mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-15 22:47:59 +00:00
pr review changes
This commit is contained in:
parent
6dd5ea7631
commit
c79c8367b7
6 changed files with 152 additions and 209 deletions
|
@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue