-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] Ollama requests fail when including an Image #8067
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
Comments
Try |
Hi @okhat , I tried that. That's the second error output that I added above. I actually thought they were different errors, but upon running it again, they appear to be the same. I'll edit my post to reflect that. |
hey @kmeehl , do you get this error for all your datapoints, or does it only happen on some? I believe most multimodal LLMs are not well adapted for structured JSON outputting (from our newly-updated JsonAdapter) all the time, so that's what's triggering the error. (I've been noticing this on You can bypass this to ensure runs aren't halted by setting lmk if this helps! |
Hey @kmeehl import dspy
class Describe(dspy.Signature):
"""Describe the image in detail. Respond only in English."""
image: dspy.Image = dspy.InputField(desc="A photo")
description: str = dspy.OutputField(desc="Detailed description of the image.")
image_path="image.png"
minicpm = dspy.LM('openai/gemma3:12b-it-qat', base_url='http://localhost:11454/v1', api_key='ollama', cache=False)
p = dspy.Predict(Describe)
p.set_lm(minicpm)
result = p(image=dspy.Image.from_url(image_path))
print(result.description) Hope this works—don’t forget to swap in your own image path, model name, and port! |
Thanks for the responses! Hey @okhat , 'ollama_chat/...' results in the following error: Hey @carvalho28, I haven't tried a ton of different LLMs, but I have yet to see it work on any of the ones that I have tried. Hey @carvalho28, I gave your solution a try, but it results in the same error: I have been able to get dspy talking to my LLM via ollama by bypassing the "standard" dspy way of doing it: minicpm = dspy.LM('ollama_chat/minicpm-v:latest', api_base='http://localhost:11434', api_key='')
img = Util.image_base64_uri(image_base_path)
image_detail_prompt = "Describe the image in detail. Respond only in English."
messages = [{"role": "user", "content": [{"type": "text", "text": image_detail_prompt}, {"type": "image_url", "image_url": {"url": img}} ]}]
detail = minicpm(messages=messages)
print(detail) I believe this works because |
Uh oh!
There was an error while loading. Please reload this page.
What happened?
Hi! Very interesting project.
I'm trying to use dspy to do image classification. As a first step, I'd like to just generate a description of an image, using
minicpm-v
model on ollama.The following example results in an error:
Output:
I've also tried the same code, replacing the model provider with
ollama_chat
:minicpm = dspy.LM('ollama_chat/minicpm-v:latest', api_base='http://localhost:11434', api_key='')
This results in the same error.
Questions
Additional Info
ollama version: 0.6.5
dspy version: 2.6.17
Steps to reproduce
Copy and run the example code above, changing
image_path
to point to a real image on your hard drive.DSPy version
2.6.17
The text was updated successfully, but these errors were encountered: