Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send image to vision model #283

Open
engdante opened this issue Sep 17, 2024 · 1 comment
Open

How to send image to vision model #283

engdante opened this issue Sep 17, 2024 · 1 comment

Comments

@engdante
Copy link

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
Copy link

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:

import ollama

response = ollama.chat(
    model="moondream",
    messages=[
        {"role": "user", "content": "Describe the image", "images": ["./cat.jpeg"]}
    ],
)

print(response["message"]['role'])
print(response["message"]['content'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants