Skip to content

Instantly share code, notes, and snippets.

@Realiserad
Created October 7, 2024 07:34
Show Gist options
  • Select an option

  • Save Realiserad/d2fb9fe7c0d7d4a97af83e74ab8ca90b to your computer and use it in GitHub Desktop.

Select an option

Save Realiserad/d2fb9fe7c0d7d4a97af83e74ab8ca90b to your computer and use it in GitHub Desktop.
Classification of mushrooms using Llama 3 Vision provided GitHub Models
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import SystemMessage
from azure.ai.inference.models import UserMessage
from azure.core.credentials import AzureKeyCredential
from azure.ai.inference.models import TextContentItem
from azure.ai.inference.models import ImageContentItem
from azure.ai.inference.models import ImageDetailLevel
from azure.ai.inference.models import ImageUrl
import sys
from textwrap import dedent
import os
client = ChatCompletionsClient(
endpoint="https://models.inference.ai.azure.com",
credential=AzureKeyCredential(os.environ["GITHUB_PAT"]),
)
response = client.complete(
messages=[
SystemMessage(content=dedent('''\
You are a classifier of mushrooms.
Respond only with the latin name of the mushroom
without a dot at the end.''')),
UserMessage(
content=[
TextContentItem(text=dedent('''\
Classify the mushroom in this picture.''')),
ImageContentItem(
image_url=ImageUrl.load(
image_file=sys.argv[1],
image_format="jpg",
detail=ImageDetailLevel.HIGH
),
),
],
)
],
model="Llama-3.2-90B-Vision-Instruct",
temperature=0.2,
max_tokens=128,
top_p=0.1
)
print(response.choices[0].message.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment