mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
How to send image to vision model #144
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @engdante on GitHub (Sep 17, 2024).
Please tell me the correct way to send an image to the vision model.
this is my function:
def generate_image_description(image_path):
prompt = f"Describe the content of this image: {image_path}."
response = client.chat(model='llava-phi3:3.8b', messages=[
{
'role': 'user',
'content': prompt,
},
])
return response['message']['content']
@karanravindra commented on GitHub (Nov 5, 2024):
Please refer to the definition of a "chat message" in the python code Message Type Dict.
The image can be passed in using the "images" key in your message dictionary. The "images" key is a sequence of "bytes" or "path-like str".
Here is an example:
@pnmartinez commented on GitHub (Mar 29, 2025):
Just my grain of salt for future searches: for gemma3, this is what worked for me using the Python
ollamalib:@myyim commented on GitHub (Apr 1, 2025):
This works for me: https://medium.com/p/bb4696663701
@ParthSareen commented on GitHub (Apr 1, 2025):
@pnmartinez @myyim does the example https://github.com/ollama/ollama-python/blob/main/examples/multimodal-chat.py not work for you guys?
@garricklw commented on GitHub (Apr 7, 2025):
Just found out in my own testing, if you want to call it against the Ollama object's chat function, you need to pass it as an "ImageDocument"
llm = Ollama(model="gemma3", request_timeout=360.0)response = llm.chat([ChatMessage("What's this? Provide a description without leading or trailing text.", additional_kwargs={"images": [ImageDocument(image_path=image_path)]})])