Skip to content

Commit 31e63fb

Browse files
author
Zhi Zhou
committed
Add vision config files in enhancements and RAG notebook
1 parent 7eb1736 commit 31e63fb

10 files changed

+248
-95
lines changed

Basic_Samples/GPT-4V/RAG_chatcompletions_example_restapi.ipynb

Lines changed: 31 additions & 8 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/basic_chatcompletions_example_restapi.ipynb

Lines changed: 15 additions & 17 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/enhancement_OCR_chatcompletions_example_restapi.ipynb

Lines changed: 50 additions & 4 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/enhancement_grounding_chatcompletions_example_restapi.ipynb

Lines changed: 77 additions & 43 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/mutiple_images_chatcompletions_example_restapi.ipynb

Lines changed: 44 additions & 6 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/shared_functions.ipynb

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": null,
14+
"execution_count": 1,
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
1818
"import json\n",
1919
"import os\n",
2020
"import requests\n",
21-
"import base64"
21+
"import time"
2222
]
2323
},
2424
{
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": null,
36+
"execution_count": 2,
3737
"metadata": {},
3838
"outputs": [],
3939
"source": [
@@ -63,12 +63,12 @@
6363
},
6464
{
6565
"cell_type": "code",
66-
"execution_count": null,
66+
"execution_count": 3,
6767
"metadata": {},
6868
"outputs": [],
6969
"source": [
7070
"# Define GPT-4V API call with image\n",
71-
"def call_GPT4V_image(messages, ocr=False, grounding=False, in_context=None):\n",
71+
"def call_GPT4V_image(messages, ocr=False, grounding=False, in_context=None, vision_api=None):\n",
7272
" # Construct the API request URL\n",
7373
" if ocr or grounding or in_context is not None:\n",
7474
" api_url = f\"{openai_api_base}/openai/deployments/{deployment_name}/extensions/chat/completions?api-version={openai_api_version}\"\n",
@@ -92,23 +92,37 @@
9292
"\n",
9393
" if ocr or grounding:\n",
9494
" payload[\"enhancements\"]={\n",
95-
" \"ocr\": {\n",
96-
" \"enabled\": ocr # Enable OCR enhancement\n",
97-
" },\n",
98-
" \"grounding\": {\n",
99-
" \"enabled\": grounding # Enable grounding enhancement\n",
100-
" }\n",
101-
" }\n",
95+
" \"ocr\": {\n",
96+
" \"enabled\": ocr # Enable OCR enhancement\n",
97+
" },\n",
98+
" \"grounding\": {\n",
99+
" \"enabled\": grounding # Enable grounding enhancement\n",
100+
" }\n",
101+
" }\n",
102+
"\n",
103+
" data_sources = []\n",
104+
"\n",
102105
" if in_context is not None:\n",
103-
" data_source = {\n",
106+
" data_sources.append({\n",
104107
" \"type\": \"AzureCognitiveSearch\",\n",
105108
" \"parameters\": {\n",
106109
" \"endpoint\": in_context.get(\"endpoint\"),\n",
107110
" \"key\": in_context.get(\"key\"),\n",
108111
" \"indexName\": in_context.get(\"indexName\"),\n",
109112
" }\n",
110-
" }\n",
111-
" payload[\"dataSources\"] = [data_source]\n",
113+
" })\n",
114+
"\n",
115+
" if vision_api is not None:\n",
116+
" data_sources.append({\n",
117+
" \"type\": \"AzureComputerVision\",\n",
118+
" \"parameters\": {\n",
119+
" \"endpoint\": vision_api.get(\"endpoint\"),\n",
120+
" \"key\": vision_api.get(\"key\"),\n",
121+
" }\n",
122+
" })\n",
123+
"\n",
124+
" if data_sources:\n",
125+
" payload[\"dataSources\"] = data_sources\n",
112126
"\n",
113127
" # Send the request and handle the response\n",
114128
" try:\n",
@@ -128,7 +142,7 @@
128142
},
129143
{
130144
"cell_type": "code",
131-
"execution_count": 1,
145+
"execution_count": 4,
132146
"id": "f4b3d21a",
133147
"metadata": {},
134148
"outputs": [],
@@ -187,7 +201,7 @@
187201
},
188202
{
189203
"cell_type": "code",
190-
"execution_count": null,
204+
"execution_count": 5,
191205
"metadata": {},
192206
"outputs": [],
193207
"source": [
-85.9 KB
Binary file not shown.
96.6 KB
Loading
-21.3 KB
Binary file not shown.
39.1 KB
Loading

0 commit comments

Comments
 (0)