Skip to content

Commit 51c22a8

Browse files
author
Zhi Zhou
committed
Update API interface
1 parent 8a86f22 commit 51c22a8

7 files changed

+257
-175
lines changed

Basic_Samples/GPT-4V/basic_chatcompletions_example_restapi.ipynb

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": null,
16+
"execution_count": 1,
1717
"id": "f4b3d21a",
1818
"metadata": {},
1919
"outputs": [],
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"cell_type": "code",
40-
"execution_count": null,
40+
"execution_count": 2,
4141
"id": "fd85fb30",
4242
"metadata": {},
4343
"outputs": [],
@@ -61,10 +61,37 @@
6161
},
6262
{
6363
"cell_type": "code",
64-
"execution_count": null,
64+
"execution_count": 3,
6565
"id": "aef62557",
6666
"metadata": {},
67-
"outputs": [],
67+
"outputs": [
68+
{
69+
"name": "stdout",
70+
"output_type": "stream",
71+
"text": [
72+
"1. Fresh produce\n",
73+
"2. Fruits and vegetables\n",
74+
"3. Colorful food\n",
75+
"4. Healthy eating\n",
76+
"5. Organic groceries\n",
77+
"6. Variety of produce\n",
78+
"7. Vegetarian ingredients\n",
79+
"8. Assorted vegetables\n",
80+
"9. Tropical fruits\n",
81+
"10. Farm fresh\n",
82+
"11. Nutrient-rich foods\n",
83+
"12. Vegan options\n",
84+
"13. Whole foods\n",
85+
"14. Raw vegetables\n",
86+
"15. Fruit assortment\n",
87+
"16. Market produce\n",
88+
"17. Dietary fiber sources\n",
89+
"18. Natural foods\n",
90+
"19. Agriculture harvest\n",
91+
"20. Culinary ingredients\n"
92+
]
93+
}
94+
],
6895
"source": [
6996
"#Image Tagging Assistant\n",
7097
"image_file_path = \"../../common/images/ImageTaggingAssistant.jpg\" \n",
@@ -80,7 +107,7 @@
80107
"\n",
81108
"# Encode the image in base64\n",
82109
"with open(image_file_path, 'rb') as image_file:\n",
83-
" encoded_image = base64.b64encode(image_file.read()).decode('ascii')\n",
110+
" encoded_image = base64.b64encode(image_file.read()).decode('utf-8')\n",
84111
"\n",
85112
"# Construct the API request URL\n",
86113
"api_url = f\"{openai_api_base}/openai/deployments/{deployment_name}/chat/completions?api-version={openai_api_version}\"\n",
@@ -93,20 +120,30 @@
93120
"\n",
94121
"# Payload for the request\n",
95122
"payload = {\n",
123+
" \"model\": \"gpt-4-vision-preview\",\n",
96124
" \"messages\": [\n",
97125
" {\n",
98126
" \"role\": \"system\",\n",
99127
" \"content\": [\n",
100-
" sys_message\n",
128+
" {\n",
129+
" \"type\": \"text\", \n",
130+
" \"text\": sys_message\n",
131+
" }\n",
101132
" ]\n",
102133
" },\n",
103134
" {\n",
104135
" \"role\": \"user\",\n",
105136
" \"content\": [\n",
106-
" user_prompt, # Pass the prompt\n",
107-
" {\n",
108-
" \"image\": encoded_image #Pass the encoded image\n",
109-
" }\n",
137+
" {\n",
138+
" \"type\": \"text\",\n",
139+
" \"text\": user_prompt\n",
140+
" },\n",
141+
" {\n",
142+
" \"type\": \"image_url\",\n",
143+
" \"image_url\": {\n",
144+
" \"url\": f\"data:image/jpeg;base64,{encoded_image}\"\n",
145+
" }\n",
146+
" }\n",
110147
" ]\n",
111148
" }\n",
112149
" ],\n",
@@ -124,14 +161,6 @@
124161
"except requests.RequestException as e:\n",
125162
" raise SystemExit(f\"Failed to make the request. Error: {e}\")"
126163
]
127-
},
128-
{
129-
"cell_type": "code",
130-
"execution_count": null,
131-
"id": "b6165c63",
132-
"metadata": {},
133-
"outputs": [],
134-
"source": []
135164
}
136165
],
137166
"metadata": {

Basic_Samples/GPT-4V/config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
"VISION_API_ENDPOINT": "https://<Your Azure Vision Resource Name>.cognitiveservices.azure.com",
77

88
"AZURE_SEARCH_SERVICE_ENDPOINT": "https://<Your Azure Search Resource Name>.search.windows.net",
9-
"AZURE_SEARCH_INDEX_NAME": "<Your Azure Search Index Name>"
9+
"AZURE_SEARCH_INDEX_NAME": "<Your Azure Search Index Name>",
10+
11+
"VIDEO_SAS_URL": "<Your Azure Blob Storage SAS URL>",
12+
"VIDEO_INDEX_NAME": "<Your Azure Video Index Name>",
13+
"VIDEO_INDEX_ID": "<Your Azure Video Index ID>"
1014
}

Basic_Samples/GPT-4V/enhancement_OCR_chatcompletions_example_restapi.ipynb

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": null,
16+
"execution_count": 1,
1717
"id": "f4b3d21a",
1818
"metadata": {},
1919
"outputs": [],
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"cell_type": "code",
40-
"execution_count": null,
40+
"execution_count": 2,
4141
"id": "fd85fb30",
4242
"metadata": {},
4343
"outputs": [],
@@ -61,10 +61,18 @@
6161
},
6262
{
6363
"cell_type": "code",
64-
"execution_count": null,
64+
"execution_count": 3,
6565
"id": "aef62557",
6666
"metadata": {},
67-
"outputs": [],
67+
"outputs": [
68+
{
69+
"name": "stdout",
70+
"output_type": "stream",
71+
"text": [
72+
"Your flight to Zurich is LX 1101. It is scheduled to depart at 09:20. You should proceed to check-in for your flight. The departure is from Terminal 2. Please make sure to verify this information upon your arrival at the airport as schedules can change.\n"
73+
]
74+
}
75+
],
6876
"source": [
6977
"image_file_path = \"../../common/images/TravelAssistant.jpeg\" # Update with your image path\n",
7078
"sys_message = \"You are an AI assistant that helps people find information.\"\n",
@@ -85,6 +93,7 @@
8593
"\n",
8694
"# Payload for the request\n",
8795
"payload = {\n",
96+
" \"model\": \"gpt-4-vision-preview\", \n",
8897
" \"enhancements\": {\n",
8998
" \"ocr\": {\n",
9099
" \"enabled\": True # Enable OCR enhancement\n",
@@ -94,16 +103,25 @@
94103
" {\n",
95104
" \"role\": \"system\",\n",
96105
" \"content\": [\n",
97-
" sys_message\n",
106+
" {\n",
107+
" \"type\": \"text\", \n",
108+
" \"text\": sys_message\n",
109+
" }\n",
98110
" ]\n",
99111
" },\n",
100112
" {\n",
101113
" \"role\": \"user\",\n",
102114
" \"content\": [\n",
103-
" user_prompt, # Pass the prompt\n",
104-
" {\n",
105-
" \"image\": encoded_image #Pass the encoded image\n",
106-
" }\n",
115+
" {\n",
116+
" \"type\": \"text\",\n",
117+
" \"text\": user_prompt # Prompt for the user\n",
118+
" },\n",
119+
" {\n",
120+
" \"type\": \"image_url\",\n",
121+
" \"image_url\": {\n",
122+
" \"url\": f\"data:image/jpeg;base64,{encoded_image}\" # Image to be processed\n",
123+
" }\n",
124+
" }\n",
107125
" ]\n",
108126
" }\n",
109127
" ],\n",
@@ -121,14 +139,6 @@
121139
"except requests.RequestException as e:\n",
122140
" raise SystemExit(f\"Failed to make the request. Error: {e}\")"
123141
]
124-
},
125-
{
126-
"cell_type": "code",
127-
"execution_count": null,
128-
"id": "b6165c63",
129-
"metadata": {},
130-
"outputs": [],
131-
"source": []
132142
}
133143
],
134144
"metadata": {

Basic_Samples/GPT-4V/enhancement_grounding_chatcompletions_example_restapi.ipynb

Lines changed: 20 additions & 19 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/in_context_chatcompletions_example_restapi.ipynb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"cell_type": "code",
40-
"execution_count": 3,
40+
"execution_count": 2,
4141
"id": "fd85fb30",
4242
"metadata": {},
4343
"outputs": [],
@@ -70,15 +70,15 @@
7070
},
7171
{
7272
"cell_type": "code",
73-
"execution_count": 4,
73+
"execution_count": 3,
7474
"id": "b6165c63",
7575
"metadata": {},
7676
"outputs": [
7777
{
7878
"name": "stdout",
7979
"output_type": "stream",
8080
"text": [
81-
"It's a Gala apple.\n"
81+
"The apple in the image appears to be a Gala apple.\n"
8282
]
8383
}
8484
],
@@ -106,6 +106,7 @@
106106
"\n",
107107
"# Payload for the request\n",
108108
"payload = {\n",
109+
" \"model\": \"gpt-4-vision-preview\", \n",
109110
" \"dataSources\": [\n",
110111
" {\n",
111112
" \"type\": \"AzureCognitiveSearch\",\n",
@@ -120,16 +121,25 @@
120121
" {\n",
121122
" \"role\": \"system\",\n",
122123
" \"content\": [\n",
123-
" sys_message\n",
124+
" {\n",
125+
" \"type\": \"text\", \n",
126+
" \"text\": sys_message\n",
127+
" }\n",
124128
" ]\n",
125129
" },\n",
126130
" {\n",
127131
" \"role\": \"user\",\n",
128132
" \"content\": [\n",
129-
" user_prompt, # Pass the prompt\n",
130-
" {\n",
131-
" \"image\": encoded_image #Pass the encoded image\n",
132-
" }\n",
133+
" {\n",
134+
" \"type\": \"text\",\n",
135+
" \"text\": user_prompt # Prompt for the user\n",
136+
" },\n",
137+
" {\n",
138+
" \"type\": \"image_url\",\n",
139+
" \"image_url\": {\n",
140+
" \"url\": f\"data:image/jpeg;base64,{encoded_image}\" # Image to be processed\n",
141+
" }\n",
142+
" }\n",
133143
" ]\n",
134144
" }\n",
135145
" ],\n",
@@ -147,13 +157,6 @@
147157
"except requests.RequestException as e:\n",
148158
" raise SystemExit(f\"Failed to make the request. Error: {e}\")"
149159
]
150-
},
151-
{
152-
"cell_type": "code",
153-
"execution_count": null,
154-
"metadata": {},
155-
"outputs": [],
156-
"source": []
157160
}
158161
],
159162
"metadata": {

0 commit comments

Comments
 (0)