Skip to content

Commit ca5c18c

Browse files
author
Zhi Zhou
committed
Add enhancement_grounding_chatcompletions_example_restapi sample code
1 parent ee89ef2 commit ca5c18c

5 files changed

+259
-13
lines changed

Basic_Samples/GPT-4V/basic_chatcompletions_example_restapi.ipynb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,10 @@
6666
"metadata": {},
6767
"outputs": [],
6868
"source": [
69-
"\n",
70-
"#Image Description Assistant\n",
71-
"image_file_path = \"../../common/images/ImageDescriptionAssistant.jpg\" # Update with your image path\n",
72-
"sys_message = \"You are an AI assistant that helps people craft a clear and detailed sentence that describes the content depicted in an image.\"\n",
73-
"user_prompt = \"Describe image\"\n",
74-
"\n",
7569
"#Image Tagging Assistant\n",
76-
"\"\"\"\n",
7770
"image_file_path = \"../../common/images/ImageTaggingAssistant.jpg\" \n",
7871
"sys_message = \"Generate a list of descriptive tags for the following image. Analyze the image carefully and produce tags that accurately represent the image. Ensure the tags are relevant.\"\n",
7972
"user_prompt = \"Provide tags for this image.\"\n",
80-
"\"\"\"\n",
8173
"\n",
8274
"#Listing Assistant\n",
8375
"\"\"\"\n",

Basic_Samples/GPT-4V/enhancement_chatcompletions_example_restapi.ipynb renamed to Basic_Samples/GPT-4V/enhancement_OCR_chatcompletions_example_restapi.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "759f9ec0",
66
"metadata": {},
77
"source": [
8-
"<h1 align =\"center\"> REST API Enhanchment Samples</h1>\n",
8+
"<h1 align =\"center\"> REST API OCR Enhanchment Samples</h1>\n",
99
"<hr>\n",
1010
" \n",
1111
"# Chat Completions"
@@ -66,7 +66,7 @@
6666
"metadata": {},
6767
"outputs": [],
6868
"source": [
69-
"image_file_path = \"../../common/images/AdobeStock_221666419.jpeg\" # Update with your image path\n",
69+
"image_file_path = \"../../common/images/TravelAssistant.jpeg\" # Update with your image path\n",
7070
"sys_message = \"You are an AI assistant that helps people find information.\"\n",
7171
"user_prompt = \"Based on this flight information board, can you provide specifics for my trip to Zurich?\"\n",
7272
"\n",

Basic_Samples/GPT-4V/enhancement_grounding_chatcompletions_example_restapi.ipynb

Lines changed: 248 additions & 0 deletions
Large diffs are not rendered by default.

Basic_Samples/GPT-4V/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
jupyter
33

44
# Other packages needed to run the notebook samples
5-
requests
5+
requests
6+
pillow
7+
matplotlib

Basic_Samples/GPT-4V/video_chatcompletions_example_restapi.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"import json\n",
2222
"import os\n",
2323
"import requests\n",
24-
"import time"
24+
"import time\n",
25+
"import re"
2526
]
2627
},
2728
{
@@ -218,7 +219,10 @@
218219
" response = requests.post(api_url, headers=headers, json=payload)\n",
219220
" response.raise_for_status() # Raise an error for bad HTTP status codes\n",
220221
" response_content = response.json()\n",
221-
" print(response_content['choices'][0]['message']['content']) # Print the content of the response\n",
222+
" text = response_content['choices'][0]['message']['content']\n",
223+
" sentences = re.split(r'(?<!\\w\\.\\w.)(?<![A-Z][a-z]\\.)(?<=\\.|\\?)\\s', text)\n",
224+
" for sentence in sentences: # Print the content of the response\n",
225+
" print(sentence)\n",
222226
"except requests.RequestException as e:\n",
223227
" raise SystemExit(f\"Failed to make the request. Error: {e}\")"
224228
]

0 commit comments

Comments
 (0)