|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 10, |
| 5 | + "execution_count": null, |
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
9 | 9 | "import os\n", |
10 | 10 | "import openai\n", |
| 11 | + "from openai import AzureOpenAI\n", |
11 | 12 | "\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", |
14 | 18 | "\n", |
15 | 19 | "API_KEY = os.getenv(\"AZURE_OPENAI_API_KEY\",\"\").strip()\n", |
16 | 20 | "assert API_KEY, \"ERROR: Azure OpenAI Key is missing\"\n", |
17 | 21 | "openai.api_key = API_KEY\n", |
18 | 22 | "\n", |
19 | | - "RESOURCE_ENDPOINT = os.getenv(\"AZURE_OPENAI_ENDPOINT\",\"\").strip()\n", |
| 23 | + "RESOURCE_ENDPOINT = os.getenv(\"OPENAI_API_BASE\",\"\").strip()\n", |
20 | 24 | "assert RESOURCE_ENDPOINT, \"ERROR: Azure OpenAI Endpoint is missing\"\n", |
21 | 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", |
22 | 26 | "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" |
24 | 28 | ] |
25 | 29 | }, |
26 | 30 | { |
27 | 31 | "cell_type": "code", |
28 | 32 | "execution_count": 13, |
29 | 33 | "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": [], |
73 | 35 | "source": [ |
| 36 | + "deployment = 'gpt-3.5-turbo'\n", |
74 | 37 | "# Create your first prompt\n", |
75 | 38 | "text_prompt = \" My stomach hurts, what can be wrong?\"\n", |
76 | 39 | "from openai import AzureOpenAI\n", |
77 | 40 | "\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']" |
91 | 49 | ] |
92 | 50 | } |
93 | 51 | ], |
94 | 52 | "metadata": { |
95 | 53 | "kernelspec": { |
96 | | - "display_name": ".conda", |
| 54 | + "display_name": "Python 3", |
97 | 55 | "language": "python", |
98 | 56 | "name": "python3" |
99 | 57 | }, |
|
107 | 65 | "name": "python", |
108 | 66 | "nbconvert_exporter": "python", |
109 | 67 | "pygments_lexer": "ipython3", |
110 | | - "version": "3.11.11" |
| 68 | + "version": "3.10.13" |
111 | 69 | }, |
112 | 70 | "orig_nbformat": 4 |
113 | 71 | }, |
|
0 commit comments