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

Adding support for llama3.2-vision #368

Open
chaos369 opened this issue Nov 8, 2024 · 2 comments
Open

Adding support for llama3.2-vision #368

chaos369 opened this issue Nov 8, 2024 · 2 comments

Comments

@chaos369
Copy link

chaos369 commented Nov 8, 2024

llama3.2-vision is good enough in many scenarios, would you please add it to magentic?

@jackmpcollins
Copy link
Owner

jackmpcollins commented Dec 3, 2024

@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
import requests
from pydantic import BaseModel, Field

from magentic import chatprompt, UserMessage, Placeholder, OpenaiChatModel
from magentic.vision import UserImageMessage


IMAGE_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"


def url_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_policy
    headers = {"User-Agent": "MagenticExampleBot (https://magentic.dev/)"}
    return requests.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/")
)
def describe_image(image_bytes: bytes) -> str: ...


image_bytes = url_to_bytes(IMAGE_URL_WOODEN_BOARDWALK)
describe_image(image_bytes)

@chaos369
Copy link
Author

Cool! I'll try it. Thank you.

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