Skip to content

Commit d3d6087

Browse files
author
Thodoris Petropoulos
committed
sending images to client.evaluate_prompt example
1 parent 226c74a commit d3d6087

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/language/0.calling_large_language_models.ipynb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,43 @@
6969
"learning_objectives = json.loads(r.content)\n",
7070
"learning_objectives"
7171
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"#### Sending image to `client.evaluate_prompt`\n",
78+
"\n",
79+
"You can also send images so a model!"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"fo = open('test.png', 'rb')\n",
89+
"import base64\n",
90+
"encoded_data = base64.b64encode(fo.read()).decode('utf-8')\n",
91+
"\n",
92+
"response = client.evaluate_prompt(\n",
93+
" prompt='What can you see in the image?',\n",
94+
" messages=[\n",
95+
" {\n",
96+
" \"role\": \"user\",\n",
97+
" \"content\": [\n",
98+
" {\n",
99+
" \"type\": \"image_url\",\n",
100+
" \"image_url\": {\n",
101+
" \"url\": f\"data:image/png;base64,{encoded_data}\",\n",
102+
" },\n",
103+
" },\n",
104+
" ],\n",
105+
" },\n",
106+
" ],\n",
107+
")"
108+
]
72109
}
73110
],
74111
"metadata": {

0 commit comments

Comments
 (0)