pr review changes

This commit is contained in:
Justin Lee 2024-11-08 14:50:44 -08:00
parent 6dd5ea7631
commit c79c8367b7
6 changed files with 152 additions and 209 deletions

View file

@ -72,6 +72,11 @@
"metadata": {},
"outputs": [],
"source": [
"import base64\n",
"import mimetypes\n",
"from termcolor import cprint\n",
"from llama_stack_client.lib.inference.event_logger import EventLogger\n",
"\n",
"def encode_image_to_data_url(file_path: str) -> str:\n",
" \"\"\"\n",
" Encode an image file to a data URL.\n",
@ -91,7 +96,7 @@
"\n",
" return f\"data:{mime_type};base64,{encoded_string}\"\n",
"\n",
"async def process_image(client: LlamaStackClient, image_path: str, stream: bool = True):\n",
"async def process_image(client, image_path: str, stream: bool = True):\n",
" \"\"\"\n",
" Process an image through the LlamaStack Vision API.\n",
"\n",
@ -102,15 +107,15 @@
" \"\"\"\n",
" data_url = encode_image_to_data_url(image_path)\n",
"\n",
" message = UserMessage(\n",
" role=\"user\",\n",
" content=[\n",
" message = {\n",
" \"role\": \"user\",\n",
" \"content\": [\n",
" {\"image\": {\"uri\": data_url}},\n",
" \"Describe what is in this image.\",\n",
" ],\n",
" )\n",
" \"Describe what is in this image.\"\n",
" ]\n",
" }\n",
"\n",
" cprint(f\"User> Sending image for analysis...\", \"green\")\n",
" cprint(\"User> Sending image for analysis...\", \"green\")\n",
" response = client.inference.chat_completion(\n",
" messages=[message],\n",
" model=\"Llama3.2-11B-Vision-Instruct\",\n",
@ -121,7 +126,7 @@
" cprint(f\"> Response: {response}\", \"cyan\")\n",
" else:\n",
" async for log in EventLogger().log(response):\n",
" log.print()"
" log.print()\n"
]
},
{