llama.cpp/examples/notebooks/Multimodal.ipynb

82 lines
2.1 KiB
Text
Raw Normal View History

{
"cells": [
2023-11-08 05:48:25 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div>\n",
" <img src=\"https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png\" width=\"500\"/>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2023-11-08 05:48:25 +00:00
"{'text': 'Llama C++'}\n"
]
}
],
"source": [
"from openai import OpenAI\n",
"\n",
"client = OpenAI(base_url=\"http://100.64.159.73:8000/v1\", api_key=\"sk-1234\")\n",
"response = client.chat.completions.create(\n",
" model=\"gpt-4-vision-preview\",\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": [\n",
" {\n",
" \"type\": \"image_url\",\n",
" \"image_url\": {\n",
2023-11-08 05:48:25 +00:00
" \"url\": \"https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png\",\n",
" },\n",
" },\n",
2023-11-08 05:48:25 +00:00
" {\"type\": \"text\", \"text\": \"What does the image say. Format your response as a json object with a single 'text' key.\"},\n",
" ],\n",
" }\n",
" ],\n",
2023-11-08 05:48:25 +00:00
" response_format={ \"type\": \"json_object\" }\n",
")\n",
2023-11-08 05:48:25 +00:00
"import json\n",
"print(json.loads(response.choices[0].message.content))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5+"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}