Skip to content

Commit 97b4c54

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

File tree

4 files changed

+172
-167
lines changed

4 files changed

+172
-167
lines changed

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

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,56 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 10,
5+
"execution_count": null,
66
"metadata": {},
77
"outputs": [],
88
"source": [
99
"import os\n",
1010
"import openai\n",
11+
"from openai import AzureOpenAI\n",
1112
"\n",
12-
"openai.api_type = \"azure\"\n",
13-
"openai.api_version = os.getenv(\"AZURE_OPENAI_API_VERSION\",\"\").strip()\n",
13+
"client = AzureOpenAI(\n",
14+
" api_key=os.getenv(\"AZURE_OPENAI_API_KEY\", \"\").strip(),\n",
15+
" api_version=os.getenv(\"AZURE_OPENAI_API_VERSION\", \"\").strip(),\n",
16+
" azure_endpoint=os.getenv(\"OPENAI_API_BASE\", \"\").strip()\n",
17+
")\n",
1418
"\n",
1519
"API_KEY = os.getenv(\"AZURE_OPENAI_API_KEY\",\"\").strip()\n",
1620
"assert API_KEY, \"ERROR: Azure OpenAI Key is missing\"\n",
1721
"openai.api_key = API_KEY\n",
1822
"\n",
19-
"RESOURCE_ENDPOINT = os.getenv(\"AZURE_OPENAI_ENDPOINT\",\"\").strip()\n",
23+
"RESOURCE_ENDPOINT = os.getenv(\"OPENAI_API_BASE\",\"\").strip()\n",
2024
"assert RESOURCE_ENDPOINT, \"ERROR: Azure OpenAI Endpoint is missing\"\n",
2125
"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",
2226
"openai.api_base = RESOURCE_ENDPOINT\n",
23-
"deployment = os.getenv(\"AZURE_OPENAI_DEPLOYMENT\",\"\").strip() # replace with your deployment name"
27+
"deployment = \"gpt-35-turbo\" # replace with your deployment name"
2428
]
2529
},
2630
{
2731
"cell_type": "code",
2832
"execution_count": 13,
2933
"metadata": {},
30-
"outputs": [
31-
{
32-
"name": "stdout",
33-
"output_type": "stream",
34-
"text": [
35-
"I'm sorry to hear you're having stomach pain. As a surgeon, you know that \"stomach pain\" is a broad complaint with a wide differential diagnosis, ranging from benign to life-threatening conditions. Without a physical examination, history, or further diagnostics, it's impossible to make a definitive diagnosis, but I can help outline a general approach and possible causes:\n",
36-
"\n",
37-
"### Key Aspects to Assess:\n",
38-
"- **Location** (epigastric, periumbilical, lower quadrants, generalized?)\n",
39-
"- **Onset & Duration**\n",
40-
"- **Character** (sharp, dull, crampy, constant, intermittent?)\n",
41-
"- **Associated symptoms** (nausea, vomiting, fever, diarrhea, obstipation, weight loss, GI bleeding)\n",
42-
"- **Aggravating/relieving factors**\n",
43-
"- **Past medical/surgical history** (especially prior abdominal operations)\n",
44-
"- **Medications**, alcohol/drug use\n",
45-
"\n",
46-
"### Differential Diagnosis Highlights\n",
47-
"- **Acute abdomen** (appendicitis, cholecystitis, perforated ulcer, bowel obstruction, mesenteric ischemia, diverticulitis, pancreatitis)\n",
48-
"- **Non-surgical** causes: gastroenteritis, gastritis, peptic ulcer disease, IBS, urinary tract infection, gynecologic pathology (in females), constipation\n",
49-
"\n",
50-
"### Surgical Red Flags\n",
51-
"Immediate evaluation is needed if: \n",
52-
"- Severe, sudden-onset (\"worst ever\") pain \n",
53-
"- Signs of peritonitis (rigidity, rebound, involuntary guarding) \n",
54-
"- Hemodynamic instability (shock) \n",
55-
"- GI bleeding (hematemesis, melena, hematochezia) \n",
56-
"- Persistent vomiting, high fever \n",
57-
"\n",
58-
"### What to do?\n",
59-
"If you are the patient:\n",
60-
"- Monitor for severe symptoms/red flags as above \n",
61-
"- If pain is mild, keep NPO and observe, with symptom logging \n",
62-
"- If moderate/severe, especially with red flag signs, **seek urgent clinical evaluation** \n",
63-
"- Laboratory and imaging as appropriate (CBC, BMP, LFTs, lipase/amylase, urinalysis, pregnancy test if female, abdominal X-ray/CT/US as indicated)\n",
64-
"\n",
65-
"---\n",
66-
"\n",
67-
"**This does not replace a formal medical evaluation.** If there's any *concern for a surgical emergency,* seek immediate medical/surgical consultation.\n",
68-
"\n",
69-
"If you want to clarify your symptoms, I can help narrow the differential or discuss workup algorithms. Let me know more details if you'd like to continue!\n"
70-
]
71-
}
72-
],
34+
"outputs": [],
7335
"source": [
36+
"deployment = 'gpt-3.5-turbo'\n",
7437
"# Create your first prompt\n",
7538
"text_prompt = \" My stomach hurts, what can be wrong?\"\n",
7639
"from openai import AzureOpenAI\n",
7740
"\n",
78-
"client = AzureOpenAI(\n",
79-
" api_key=os.environ[\"AZURE_OPENAI_API_KEY\"],\n",
80-
" azure_endpoint=os.environ[\"AZURE_OPENAI_ENDPOINT\"],\n",
81-
" api_version=\"2023-05-15\"\n",
82-
")\n",
83-
"response = client.chat.completions.create(\n",
84-
" model=os.environ[\"AZURE_OPENAI_DEPLOYMENT\"],\n",
85-
" messages=[\n",
86-
" {\"role\": \"system\", \"content\": \"I'm a doctor, specialist on surgery\"},\n",
87-
" {\"role\": \"user\", \"content\": text_prompt},\n",
88-
" ]\n",
89-
")\n",
90-
"print(response.choices[0].message.content)"
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",
46+
"\n",
47+
"\n",
48+
"response['choices'][0]['message']['content']"
9149
]
9250
}
9351
],
9452
"metadata": {
9553
"kernelspec": {
96-
"display_name": ".conda",
54+
"display_name": "Python 3",
9755
"language": "python",
9856
"name": "python3"
9957
},
@@ -107,7 +65,7 @@
10765
"name": "python",
10866
"nbconvert_exporter": "python",
10967
"pygments_lexer": "ipython3",
110-
"version": "3.11.11"
68+
"version": "3.10.13"
11169
},
11270
"orig_nbformat": 4
11371
},

0 commit comments

Comments
 (0)