Skip to content

Commit d0b3010

Browse files
committed
Fix some assignments
1 parent 97b4c54 commit d0b3010

13 files changed

Lines changed: 1468 additions & 265 deletions

File tree

07-building-chat-applications/python/aoai-assigment-simple.ipynb

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 20,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -16,42 +16,48 @@
1616
" azure_endpoint=os.getenv(\"OPENAI_API_BASE\", \"\").strip()\n",
1717
")\n",
1818
"\n",
19-
"API_KEY = os.getenv(\"AZURE_OPENAI_API_KEY\",\"\").strip()\n",
20-
"assert API_KEY, \"ERROR: Azure OpenAI Key is missing\"\n",
21-
"openai.api_key = API_KEY\n",
22-
"\n",
23-
"RESOURCE_ENDPOINT = os.getenv(\"OPENAI_API_BASE\",\"\").strip()\n",
24-
"assert RESOURCE_ENDPOINT, \"ERROR: Azure OpenAI Endpoint is missing\"\n",
25-
"assert \"openai.azure.com\" in RESOURCE_ENDPOINT.lower(), \"ERROR: Azure OpenAI Endpoint should be in the form: \\n\\n\\t<your unique endpoint identifier>.openai.azure.com\"\n",
26-
"openai.api_base = RESOURCE_ENDPOINT\n",
27-
"deployment = \"gpt-35-turbo\" # replace with your deployment name"
19+
"# Đảm bảo endpoint đúng định dạng\n",
20+
"assert \"openai.azure.com\" in RESOURCE_ENDPOINT.lower(), \\\n",
21+
" \"Azure endpoint phải chứa openai.azure.com\""
2822
]
2923
},
3024
{
3125
"cell_type": "code",
32-
"execution_count": 13,
26+
"execution_count": 21,
3327
"metadata": {},
34-
"outputs": [],
28+
"outputs": [
29+
{
30+
"data": {
31+
"text/plain": [
32+
"\"There are many potential causes of foot pain, ranging from minor issues like blisters or calluses to more serious conditions like fractures, tendonitis, or nerve damage. Some common causes of foot pain include plantar fasciitis, Achilles tendonitis, stress fractures, and arthritis.\\n\\nIf your foot pain is persistent, severe, or affecting your daily activities, it's important to see a doctor for a proper diagnosis and treatment. As a specialist in surgery, I can perform a thorough evaluation, order any necessary imaging tests, and recommend a treatment plan tailored to your specific condition. Treatment options may include rest, physical therapy, medication, orthotics, or in some cases, surgery.\\n\\nIt's important not to ignore foot pain, as delaying treatment can lead to further complications. I recommend making an appointment with a healthcare provider to determine the underlying cause of your foot pain and to discuss the best course of action for your specific situation.\""
33+
]
34+
},
35+
"execution_count": 21,
36+
"metadata": {},
37+
"output_type": "execute_result"
38+
}
39+
],
3540
"source": [
3641
"deployment = 'gpt-3.5-turbo'\n",
3742
"# Create your first prompt\n",
38-
"text_prompt = \" My stomach hurts, what can be wrong?\"\n",
39-
"from openai import AzureOpenAI\n",
43+
"text_prompt = \" My foot hurts, what can be wrong?\"\n",
4044
"\n",
41-
"response = openai.ChatCompletion.create(\n",
42-
" engine=deployment,\n",
43-
" messages = [\n",
44-
" {\"role\":\"system\", \"content\":\"I'm a doctor, specialist on surgery\"},\n",
45-
" {\"role\":\"user\",\"content\":text_prompt},])\n",
45+
"response = client.chat.completions.create(\n",
46+
" model=deployment,\n",
47+
" messages=[\n",
48+
" {\"role\": \"system\", \"content\": \"I'm a doctor, specialist on surgery\"},\n",
49+
" {\"role\": \"user\", \"content\": text_prompt},\n",
50+
" ]\n",
51+
")\n",
4652
"\n",
4753
"\n",
48-
"response['choices'][0]['message']['content']"
54+
"response.choices[0].message.content"
4955
]
5056
}
5157
],
5258
"metadata": {
5359
"kernelspec": {
54-
"display_name": "Python 3",
60+
"display_name": "ai",
5561
"language": "python",
5662
"name": "python3"
5763
},
@@ -65,7 +71,7 @@
6571
"name": "python",
6672
"nbconvert_exporter": "python",
6773
"pygments_lexer": "ipython3",
68-
"version": "3.10.13"
74+
"version": "3.11.13"
6975
},
7076
"orig_nbformat": 4
7177
},

07-building-chat-applications/python/aoai-assignment.ipynb

Lines changed: 1224 additions & 58 deletions
Large diffs are not rendered by default.

08-building-search-applications/python/aoai-assignment.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,9 @@
10651065
"output_type": "stream",
10661066
"text": [
10671067
"1.0\n",
1068-
"0.915739416418029\n",
1069-
"0.8329017718558467\n",
1070-
"0.7818148774886836\n"
1068+
"0.9157394164180291\n",
1069+
"0.8329017718558461\n",
1070+
"0.7818148774886838\n"
10711071
]
10721072
}
10731073
],
@@ -1088,7 +1088,7 @@
10881088
],
10891089
"metadata": {
10901090
"kernelspec": {
1091-
"display_name": ".conda",
1091+
"display_name": "ai",
10921092
"language": "python",
10931093
"name": "python3"
10941094
},
@@ -1102,7 +1102,7 @@
11021102
"name": "python",
11031103
"nbconvert_exporter": "python",
11041104
"pygments_lexer": "ipython3",
1105-
"version": "3.11.11"
1105+
"version": "3.11.13"
11061106
},
11071107
"orig_nbformat": 4
11081108
},

09-building-image-applications/python/aoai-app.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212

1313
# Assign the API version (DALL-E is currently supported for the 2023-06-01-preview API version only)
1414
client = AzureOpenAI(
15-
api_key=os.environ['AZURE_OPENAI_API_DALLE_KEY'], # this is also the default, it can be omitted
16-
api_version = os.environ['AZURE_OPENAI_API_DALLE_VERSION'], # e.g. "2023-06-01-preview"
17-
azure_endpoint= os.environ['AZURE_OPENAI_DALLE_ENDPOINT']
15+
api_key=os.environ['AZURE_DALLE_API_KEY'], # this is also the default, it can be omitted
16+
api_version = os.environ['AZURE_DALLE_API_VERSION'], # e.g. "2023-06-01-preview"
17+
azure_endpoint= os.environ['AZURE_DALLE_ENDPOINT']
1818
)
1919

20-
model = "dall-e-3"
21-
20+
model = os.environ['AZURE_DALLE_DEPLOYMENT'] # e.g. "dall-e-2" or "dall-e-3"
2221

2322
try:
2423
# Create an image by using the image generation API

09-building-image-applications/python/aoai-solution.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
# Assign the API version (DALL-E is currently supported for the 2023-06-01-preview API version only)
1414
client = AzureOpenAI(
15-
api_key=os.environ['AZURE_OPENAI_API_DALLE_KEY'], # this is also the default, it can be omitted
16-
api_version = os.environ['AZURE_OPENAI_API_DALLE_VERSION'], # e.g. "2023-06-01-preview"
17-
azure_endpoint=os.environ['AZURE_OPENAI_DALLE_ENDPOINT']
15+
api_key=os.environ['AZURE_DALLE_API_KEY'], # this is also the default, it can be omitted
16+
api_version = os.environ['AZURE_DALLE_API_VERSION'], # e.g. "2023-06-01-preview"
17+
azure_endpoint=os.environ['AZURE_DALLE_ENDPOINT']
1818
)
1919

20-
model = os.environ['AZURE_OPENAI_DEPLOYMENT']
20+
model = os.environ['AZURE_DALLE_DEPLOYMENT']
2121

2222
disallow_list = "swords, violence, blood, gore, nudity, sexual content, adult content, adult themes, adult language, adult humor, adult jokes, adult situations, adult"
2323

09-building-image-applications/python/tempCodeRunnerFile.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)