Skip to content

Commit c3479f6

Browse files
committed
CLOUD_PORT -> PORT, update MODEL_NAME, remove EventLogger, fix message structures
1 parent 4176778 commit c3479f6

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

docs/zero_to_hero_guide/03_Image_Chat101.ipynb

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
"import base64\n",
2424
"import mimetypes\n",
2525
"from llama_stack_client import LlamaStackClient\n",
26-
"from llama_stack_client.lib.inference.event_logger import EventLogger\n",
27-
"from llama_stack_client.types import UserMessage\n",
2826
"from termcolor import cprint"
2927
]
3028
},
@@ -45,8 +43,8 @@
4543
"outputs": [],
4644
"source": [
4745
"HOST = \"localhost\" # Replace with your host\n",
48-
"CLOUD_PORT = 8321 # Replace with your cloud distro port\n",
49-
"MODEL_NAME='Llama3.2-11B-Vision-Instruct'"
46+
"PORT = 8321 # Replace with your cloud distro port\n",
47+
"MODEL_NAME='meta-llama/Llama3.2-11B-Vision-Instruct'"
5048
]
5149
},
5250
{
@@ -65,11 +63,6 @@
6563
"metadata": {},
6664
"outputs": [],
6765
"source": [
68-
"import base64\n",
69-
"import mimetypes\n",
70-
"from termcolor import cprint\n",
71-
"from llama_stack_client.lib.inference.event_logger import EventLogger\n",
72-
"\n",
7366
"def encode_image_to_data_url(file_path: str) -> str:\n",
7467
" \"\"\"\n",
7568
" Encode an image file to a data URL.\n",
@@ -103,8 +96,8 @@
10396
" message = {\n",
10497
" \"role\": \"user\",\n",
10598
" \"content\": [\n",
106-
" {\"image\": {\"uri\": data_url}},\n",
107-
" \"Describe what is in this image.\"\n",
99+
" {\"type\": \"image\", \"image\": {\"url\": {\"uri\": data_url}}},\n",
100+
" {\"type\": \"text\", \"text\": \"Describe what is in this image.\"}\n",
108101
" ]\n",
109102
" }\n",
110103
"\n",
@@ -115,11 +108,13 @@
115108
" stream=stream,\n",
116109
" )\n",
117110
"\n",
111+
" cprint(f'Assistant> ', color='cyan', end='')\n",
118112
" if not stream:\n",
119-
" cprint(f\"> Response: {response}\", \"cyan\")\n",
113+
" cprint(response.completion_message.content, color='yellow')\n",
120114
" else:\n",
121-
" async for log in EventLogger().log(response):\n",
122-
" log.print()\n"
115+
" for chunk in response:\n",
116+
" cprint(chunk.event.delta.text, color='yellow', end='')\n",
117+
" cprint('')\n"
123118
]
124119
},
125120
{
@@ -134,23 +129,10 @@
134129
},
135130
{
136131
"cell_type": "code",
137-
"execution_count": 6,
132+
"execution_count": null,
138133
"id": "64d36476-95d7-49f9-a548-312cf8d8c49e",
139134
"metadata": {},
140-
"outputs": [
141-
{
142-
"name": "stdout",
143-
"output_type": "stream",
144-
"text": [
145-
"\u001b[32mUser> Sending image for analysis...\u001b[0m\n",
146-
"\u001b[36mAssistant> \u001b[0m\u001b[33mThe\u001b[0m\u001b[33m image\u001b[0m\u001b[33m features\u001b[0m\u001b[33m a\u001b[0m\u001b[33m simple\u001b[0m\u001b[33m,\u001b[0m\u001b[33m mon\u001b[0m\u001b[33moch\u001b[0m\u001b[33mromatic\u001b[0m\u001b[33m line\u001b[0m\u001b[33m drawing\u001b[0m\u001b[33m of\u001b[0m\u001b[33m a\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m,\u001b[0m\u001b[33m with\u001b[0m\u001b[33m the\u001b[0m\u001b[33m words\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mLL\u001b[0m\u001b[33mAMA\u001b[0m\u001b[33m STACK\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m written\u001b[0m\u001b[33m above\u001b[0m\u001b[33m it\u001b[0m\u001b[33m.\u001b[0m\u001b[33m The\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m is\u001b[0m\u001b[33m depicted\u001b[0m\u001b[33m in\u001b[0m\u001b[33m a\u001b[0m\u001b[33m cartoon\u001b[0m\u001b[33mish\u001b[0m\u001b[33m style\u001b[0m\u001b[33m,\u001b[0m\u001b[33m with\u001b[0m\u001b[33m a\u001b[0m\u001b[33m large\u001b[0m\u001b[33m body\u001b[0m\u001b[33m and\u001b[0m\u001b[33m a\u001b[0m\u001b[33m long\u001b[0m\u001b[33m neck\u001b[0m\u001b[33m.\u001b[0m\u001b[33m It\u001b[0m\u001b[33m has\u001b[0m\u001b[33m a\u001b[0m\u001b[33m distinctive\u001b[0m\u001b[33m head\u001b[0m\u001b[33m shape\u001b[0m\u001b[33m,\u001b[0m\u001b[33m with\u001b[0m\u001b[33m a\u001b[0m\u001b[33m small\u001b[0m\u001b[33m circle\u001b[0m\u001b[33m for\u001b[0m\u001b[33m the\u001b[0m\u001b[33m eye\u001b[0m\u001b[33m and\u001b[0m\u001b[33m a\u001b[0m\u001b[33m curved\u001b[0m\u001b[33m line\u001b[0m\u001b[33m for\u001b[0m\u001b[33m the\u001b[0m\u001b[33m mouth\u001b[0m\u001b[33m.\u001b[0m\u001b[33m The\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m's\u001b[0m\u001b[33m body\u001b[0m\u001b[33m is\u001b[0m\u001b[33m composed\u001b[0m\u001b[33m of\u001b[0m\u001b[33m several\u001b[0m\u001b[33m rounded\u001b[0m\u001b[33m shapes\u001b[0m\u001b[33m,\u001b[0m\u001b[33m giving\u001b[0m\u001b[33m it\u001b[0m\u001b[33m a\u001b[0m\u001b[33m soft\u001b[0m\u001b[33m and\u001b[0m\u001b[33m cudd\u001b[0m\u001b[33mly\u001b[0m\u001b[33m appearance\u001b[0m\u001b[33m.\n",
147-
"\n",
148-
"\u001b[0m\u001b[33mThe\u001b[0m\u001b[33m words\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mLL\u001b[0m\u001b[33mAMA\u001b[0m\u001b[33m STACK\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m are\u001b[0m\u001b[33m written\u001b[0m\u001b[33m in\u001b[0m\u001b[33m a\u001b[0m\u001b[33m playful\u001b[0m\u001b[33m,\u001b[0m\u001b[33m handwritten\u001b[0m\u001b[33m font\u001b[0m\u001b[33m above\u001b[0m\u001b[33m the\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m's\u001b[0m\u001b[33m head\u001b[0m\u001b[33m.\u001b[0m\u001b[33m The\u001b[0m\u001b[33m text\u001b[0m\u001b[33m is\u001b[0m\u001b[33m also\u001b[0m\u001b[33m in\u001b[0m\u001b[33m a\u001b[0m\u001b[33m mon\u001b[0m\u001b[33moch\u001b[0m\u001b[33mromatic\u001b[0m\u001b[33m color\u001b[0m\u001b[33m scheme\u001b[0m\u001b[33m,\u001b[0m\u001b[33m matching\u001b[0m\u001b[33m the\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m's\u001b[0m\u001b[33m outline\u001b[0m\u001b[33m.\u001b[0m\u001b[33m The\u001b[0m\u001b[33m background\u001b[0m\u001b[33m of\u001b[0m\u001b[33m the\u001b[0m\u001b[33m image\u001b[0m\u001b[33m is\u001b[0m\u001b[33m a\u001b[0m\u001b[33m solid\u001b[0m\u001b[33m black\u001b[0m\u001b[33m color\u001b[0m\u001b[33m,\u001b[0m\u001b[33m which\u001b[0m\u001b[33m provides\u001b[0m\u001b[33m a\u001b[0m\u001b[33m clean\u001b[0m\u001b[33m and\u001b[0m\u001b[33m simple\u001b[0m\u001b[33m contrast\u001b[0m\u001b[33m to\u001b[0m\u001b[33m the\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m's\u001b[0m\u001b[33m design\u001b[0m\u001b[33m.\n",
149-
"\n",
150-
"\u001b[0m\u001b[33mOverall\u001b[0m\u001b[33m,\u001b[0m\u001b[33m the\u001b[0m\u001b[33m image\u001b[0m\u001b[33m appears\u001b[0m\u001b[33m to\u001b[0m\u001b[33m be\u001b[0m\u001b[33m a\u001b[0m\u001b[33m logo\u001b[0m\u001b[33m or\u001b[0m\u001b[33m icon\u001b[0m\u001b[33m for\u001b[0m\u001b[33m a\u001b[0m\u001b[33m brand\u001b[0m\u001b[33m or\u001b[0m\u001b[33m product\u001b[0m\u001b[33m called\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mL\u001b[0m\u001b[33mlama\u001b[0m\u001b[33m Stack\u001b[0m\u001b[33m.\"\u001b[0m\u001b[33m The\u001b[0m\u001b[33m use\u001b[0m\u001b[33m of\u001b[0m\u001b[33m a\u001b[0m\u001b[33m cartoon\u001b[0m\u001b[33m llama\u001b[0m\u001b[33m and\u001b[0m\u001b[33m a\u001b[0m\u001b[33m playful\u001b[0m\u001b[33m font\u001b[0m\u001b[33m suggests\u001b[0m\u001b[33m a\u001b[0m\u001b[33m l\u001b[0m\u001b[33migh\u001b[0m\u001b[33mthe\u001b[0m\u001b[33mart\u001b[0m\u001b[33med\u001b[0m\u001b[33m and\u001b[0m\u001b[33m humorous\u001b[0m\u001b[33m tone\u001b[0m\u001b[33m,\u001b[0m\u001b[33m while\u001b[0m\u001b[33m the\u001b[0m\u001b[33m mon\u001b[0m\u001b[33moch\u001b[0m\u001b[33mromatic\u001b[0m\u001b[33m color\u001b[0m\u001b[33m scheme\u001b[0m\u001b[33m gives\u001b[0m\u001b[33m the\u001b[0m\u001b[33m image\u001b[0m\u001b[33m a\u001b[0m\u001b[33m clean\u001b[0m\u001b[33m and\u001b[0m\u001b[33m modern\u001b[0m\u001b[33m feel\u001b[0m\u001b[33m.\u001b[0m\u001b[97m\u001b[0m\n"
151-
]
152-
}
153-
],
135+
"outputs": [],
154136
"source": [
155137
"# [Cell 5] - Initialize client and process image\n",
156138
"async def main():\n",
@@ -184,7 +166,7 @@
184166
"fileUid": "37bbbfda-8e42-446c-89c7-59dd49e2d339",
185167
"isAdHoc": false,
186168
"kernelspec": {
187-
"display_name": "base",
169+
"display_name": "llama-stack",
188170
"language": "python",
189171
"name": "python3"
190172
},
@@ -198,7 +180,7 @@
198180
"name": "python",
199181
"nbconvert_exporter": "python",
200182
"pygments_lexer": "ipython3",
201-
"version": "3.12.2"
183+
"version": "3.12.11"
202184
}
203185
},
204186
"nbformat": 4,

0 commit comments

Comments
 (0)