8000 Update Multimodal notebook · jithinraj/llama-cpp-python@598780f · GitHub
[go: up one dir, main page]

Skip to content

Commit 598780f

Browse files
committed
Update Multimodal notebook
1 parent b30b9c3 commit 598780f

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

examples/notebooks/Multimodal.ipynb

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<div>\n",
8+
" <img src=\"https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png\" width=\"500\"/>\n",
9+
"</div>"
10+
]
11+
},
312
{
413
"cell_type": "code",
514
"execution_count": 1,
@@ -9,19 +18,13 @@
918
"name": "stdout",
1019
"output_type": "stream",
1120
"text": [
12-
"ChatCompletion(id='chatcmpl-65a710ba-41d1-4d0a-a124-a44b2b4a0189', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content=' The image reads \"LlamaC++.\"', role='assistant', function_call=None, tool_calls=None))], created=1699413274, model='gpt-4-vision-preview', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=10, prompt_tokens=624, total_tokens=634))\n"
21+
"{'text': 'Llama C++'}\n"
1322
]
1423
}
1524
],
1625
"source": [
1726
"from openai import OpenAI\n",
1827
"\n",
19-
"import urllib.request\n",
20-
"import base64\n",
21-
"\n",
22-
"def get_data_url(url):\n",
23-
" return \"data:image/png;base64,\" + base64.b64encode(urllib.request.urlopen(url).read()).decode(\"utf-8\")\n",
24-
"\n",
2528
"client = OpenAI(base_url=\"http://100.64.159.73:8000/v1\", api_key=\"sk-1234\")\n",
2629
"response = client.chat.completions.create(\n",
2730
" model=\"gpt-4-vision-preview\",\n",
@@ -32,23 +35,17 @@
3235
" {\n",
3336
" \"type\": \"image_url\",\n",
3437
" \"image_url\": {\n",
35-
" \"url\": get_data_url(\"https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png\"),\n",
36-
" # \"url\": \"https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png\",\n",
38+
" \"url\": \"https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png\",\n",
3739
" },\n",
3840
" },\n",
39-
" {\"type\": \"text\", \"text\": \"What does the image say\"},\n",
41+
" {\"type\": \"text\", \"text\": \"What does the image say. Format your response as a json object with a single 'text' key.\"},\n",
4042
" ],\n",
4143
" }\n",
4244
" ],\n",
45+
" response_format={ \"type\": \"json_object\" }\n",
4346
")\n",
44-
"print(response)"
45-
]
46-
},
47-
{
48-
"cell_type": "markdown",
49-
"metadata": {},
50-
"s 595E ource": [
51-
"![](https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png)"
47+
"import json\n",
48+
"print(json.loads(response.choices[0].message.content))"
5249
]
5350
},
5451
{

0 commit comments

Comments
 (0)
0