You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@chaos369 This is possible now using using Ollama via the OpenaiChatModel. The code below (adapted from https://magentic.dev/vision/) worked for me (though it did take 3 minutes to run so you might want to test with a smaller image). Let me know if this works for you!
ollama pull llama3.2-vision
importrequestsfrompydanticimportBaseModel, Fieldfrommagenticimportchatprompt, UserMessage, Placeholder, OpenaiChatModelfrommagentic.visionimportUserImageMessageIMAGE_URL_WOODEN_BOARDWALK="https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"defurl_to_bytes(url: str) ->bytes:
"""Get the content of a URL as bytes."""# A custom user-agent is necessary to comply with Wikimedia user-agent policy# https://meta.wikimedia.org/wiki/User-Agent_policyheaders= {"User-Agent": "MagenticExampleBot (https://magentic.dev/)"}
returnrequests.get(url, headers=headers, timeout=10).content@chatprompt(UserMessage("Describe the following image in one sentence."),UserImageMessage(Placeholder(bytes, "image_bytes")),model=OpenaiChatModel("llama3.2-vision", base_url="http://localhost:11434/v1/"))defdescribe_image(image_bytes: bytes) ->str: ...
image_bytes=url_to_bytes(IMAGE_URL_WOODEN_BOARDWALK)
describe_image(image_bytes)
llama3.2-vision is good enough in many scenarios, would you please add it to magentic?
The text was updated successfully, but these errors were encountered: