forked from jswope00/AI-MicroApps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_soap.py
312 lines (280 loc) · 18.2 KB
/
config_soap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
APP_TITLE = "SOAP Notes Feedback"
APP_INTRO = """This app provides feedback on written SOAP (subjective, objective, assessment, and plan) notes. It provides feedback in stages for more precision over the feedback provided. .
"""
APP_HOW_IT_WORKS = """
"""
SHARED_ASSET = {
}
HTML_BUTTON = {
}
SYSTEM_PROMPT = """You grade medical students' soap notes based on a rubric.
When a user's answer is accurate, you don't need to provide verbose feedback.
When a user's answer is inaccurate, you can provide very brief 1-2 sentence supportive hint about how they might get the right answer next time.
Your primary focus is scoring based on a rubric. You should prioritize getting the score right by first using the information given to you in the rubric and other prompts, and secondarily by going to your general knowledge. """
PHASES = {
"phase1": {
"name": "Patient History",
"fields": {
"patient_history": {
"type": "text_area",
"height": 400,
"label": """Please paste the PATIENT HISTORY section of your note""",
"value": """Chief complaint: I am having darker than usual urine
HPI: MJ is a 35 y/o female who presents today complaining of a 1 week history of blood in her urine. Patient reports there is pain associated with it and rates it 6 out of 10. Pain radiates to groin, nothing makes it better or worse. Patient reports taking Ibuprofen 800 mg TID for the past week. Patient reports she feels abdominal fullness even with a little bit of food and pain in the right side of her back. Patient has not had prior episode of this. No skin discoloration. Patient states happens everyday not at the same time and the color is dark red to brown.
PMH: HTN x 7 years No surgeries
Medications: Lisinopril 20 mg 1x a day for past 7 years and Amlodipine 10 mg x7 years 1 x per day
Vaccinations: Up to date
Allergies: None
Family hx: Father is fine, Mother has hx of HTN and surgery for bleed in brain, brother is fine
Social hx: Social drinker 1-2 cups of wine per outing and 10 years of smoking 1 pack per day No illicit drug use
Occupation: Taxi driver for the past 10 years Diet chicken fish vegetables that are grilled or baked. No exercise
Sexual hx: Yes active, 1 partner, No protection yes STD testing 5 years ago and
was negative. No children and last cycle was 2 weeks ago and is regular. """
}
},
"phase_instructions": """Confirm that the user has adequately capture the patient history, especially the main symptom. Here are the relevant patient history details:
Main symptom/Cardinal Symptoms - Dark urine
The urine is dark red to brown like blood throughout the stream with no clots and no odor.
It occurred every day of the week but not with every urination.
No previous history of this symptom.
There is no urinary frequency, nocturia, polyuria, dysuria, changes in the stream, or dribbling
Associative Symptom: Flank Pain
Pain in right flank x 1 month – sudden, intermittent, dull radiating to the right groin area, 3/10 initially and 6/10 for the past week, nothing makes the pain worst and it is not relieved by ibuprofen.
Associative Symptom: Abdominal/Early fullness
Early fullness/ (Early satiety) x 3 months – eating very little and becoming full. Nothing seems to make it worse, better, or precipitates it.
Pertinent Negatives: *no associated appetite changes, fever, nausea, vomiting, diarrhea, constipation, blood in stool, no weight loss. No history of renal stones/UTIs. """,
"user_prompt": "{patient_history}",
"allow_skip": True,
"scored_phase": True,
"rubric": """
1. Organization
5 points - The history is consistently organized and contains appropriately labeled sections and sub-sections (CC, HPI, and relevant contributing history).
3.75 points - The history is somewhat organized and contains appropriate sections (CC, HPI, and relevant contributing history).
2.5 points - The history is somewhat organized but is missing sections and/or section labels.
1.25 points - The history is poorly organized.
0 points - The history is not organized.
1. History of Present Illness
15 points - History contains all the relevant attributes of the patient's presenting complaint (cardinal features, pertinent negative symptoms) AND is presented in chronological order.
11.25 points - History contains most of the relevant attributes of the patient's presenting complaint (cardinal features, pertinent negative symptoms) AND is presented in chronological order.
7.5 points - History contains some of the relevant attributes of the patient's presenting complaint (cardinal features, pertinent negative symptoms) OR has some inconsistencies in the timeline.
3.75 points - History contains some of the relevant attributes of the patient's presenting complaint (cardinal features, pertinent negative symptoms) AND has some inconsistencies in the timeline.
0 points - History does not contain relevant attributes of the patient's presenting complaint (cardinal features, pertinent negative symptoms) AND has many inconsistencies in the timeline.
4. Additional History
10 points - Additional history contains all information to support diagnostic reasoning.
7.5 points - Additional history contains most but not all information to support diagnostic reasoning.
5 points - Additional history contains some information to support diagnostic reasoning.
2.5 points - Additional history contains some information to support diagnostic reasoning, AND there are factual inaccuracies.
0 points - Additional history is insufficient to support diagnostic reasoning.
""",
"minimum_score": 5
},
"phase2": {
"name": "Physical Exam",
"fields": {
"physical_exam": {
"type": "text_area",
"height": 400,
"label": """Please paste the PHYSICAL EXAM section of your note""",
"value": """PE:
VS: T: 98.2, BP160/110 HR 90 recheck is 64, and Resp are 14 per min
G/A: Well appearing female, awake, alert, and oriented x3 in no apparent painful distress.
Abd: No scarring, no contours, no deformities, tenderness on the right flank + kidney ballotment on the right, no bruit in the right or left renal artery. No
abdominal bruit, no tenderness in the 9 front quadrants, normal bowel sounds
present in all quadrants on auscultation.
Cardio: S1,S2 present, no S3 no S4, no gallops, no murmurs.
US: + multiple cysts on bilateral kidneys + calculus in r. kidney
Urinalysis: + RBC, +3 heme, Cloudy urine, +WBC, no casts. """
}
},
"phase_instructions": """Confirm that the user has adequately capture the physical examination notes. Provide critical feedback based on this answer key:
General Appearance: The user should include some comment on general appearance.
Vital Signs: T:36.9 C(98.2 F) HR:90 RR: 14 BP: 160/110
Abodmen: The user should include some comment on inspection of abdomen.
Abodmen Palpatation: The user should include some comment on light and deep palpation of abdomen.
Liver: The user should include some comment on Liver Span and Liver Palpation (Hepatomegaly)
Splenic percussion: The user should include some comment on Splenic percussion and palpation (Splenomegaly)
Kidneys: The user should include some comment on Right & Left Kidneys (e.g. Kidneys are not palpable OR not ballotable bilaterally. )
Abodmen: The user should include some comment on generalized percussion of Abdomen. (E.g. Abdomen is tympanic throughout)
CVA Tenderness: The user should include some comment on CVA tenderness of Right and Left Kidney. (E.g. No costovertebral (CVA) tenderness OR Right CVA tenderness. )""",
"user_prompt": "{physical_exam}",
"allow_skip": True,
"scored_phase": True,
"rubric": """
1. Organization
5 points - Physical examination is organized and labeled into clear sections and presented in a systematic manner. It contains the general assessment & vital signs.
3.75 points - Physical examination is organized and labeled into sections. It contains the general assessment & vital signs.
2.5 points - Physical examination is somewhat organized and labeled into sections. It contains the general assessment & vital signs.
1.25 points - Physical examination has some accurte details and some innacurate.
0 points - Physical examination is not organized and does not contain general assessment and vital signs.
2. Physical Examination
10 points - The physical examination section contains complete, accurate, and logical documentation of the relevant system for the patient's presenting complaint.
7.5 points - The physical examination section contains mostly complete, accurate, and logical documentation of the relevant system for the patient's presenting complaint.
5 points - The physical examination section contains partially complete, accurate, and logical documentation of the relevant system for the patient's presenting complaint. OR it contains some factual errors.
2.5 points - The physical examination section contains partially complete, accurate, and logical documentation of the relevant system for the patient's presenting complaint. AND it contains some factual errors.
0 points - Physical examination was not relevant to the patient's presenting complaint.
3. Additional Examinations
10 points - Documentation of complete and accurate additional physical examination relevant to differential diagnosis with no factual errors.
7.5 points - Documentation of most additional physical examination relevant to differential diagnosis with no factual errors.
5 points - Documentation of some additional physical examination relevant to differential diagnosis OR contains a few factual errors.
2.5 points - Documentation of few additional physical examination relevant to differential diagnosis AND contains a few factual errors.
0 points - No documentation of additional physical examinations relevant to support the differential diagnosis.
""",
"minimum_score": 2
},
"phase3": {
"name": "Differential Diagnosis",
"fields": {
"ddx": {
"type": "text_area",
"height": 400,
"label": "Please paste differential diagnosis notes here",
"value": """
DDX 1: Polycystic Kidney disease - HTN -Family hx is postive for berry aneurysm in mother and HTN -R. flank pain - RBC from investigation positive - Heme 3+ positive - US of abdomen showed multiple cysts on both kidneys
DDX 2: Nephrolithiasis - US of abdomen shows L sided calculus - Flank pain Cysts on both kidneys visualized on US - Dark urine
DDX 3: Berger's disease - Blood in urine - Heme +3 - Smoker x 10 years - Age range is 30-40 - HTN
""",
}
},
"phase_instructions": "Confirm that the user has adequately provided a list of differential diagnosis options, ranked in order of likelihood, and supported by details from the patient examination and/or history. ",
"user_prompt": "{ddx}",
"allow_skip": True,
"scored_phase": True,
"rubric": """
1. List
10 points - The assessment contains three discrete diseases, with each being relevant to the patient’s presentation
7.5 points - The assessment contains at least two discrete diseases, with each being relevant to the patient’s presentation.
5 points - The assessment contains at least two discrete diseases, but one is irellevant to the patient's presentation.
2.5 points - The assessment contains only one discrete disease option.
0 points - The assessment does not contain any discrete or relevant diagnosis.
2. Ranking
15 points - All differential diagnoses are listed in order of most likely diagnosis, and each is relevant to the patient’s presentation.
11.25 points - All differential diagnoses are listed in order of most likely diagnosis, but one is not relevant to patient's presentation.
7.5 points - Leading diagnosis is not the most likely diagnosis in the differential but contains at least two discrete diseases and each is relevant to the patient presentation.
3.75 points - Leading diagnosis is not the most likely diagnosis in the differential but contains at least one discrete diseases which is relevant to the patient presentation.
0 points - Differential diagnosis not listed in order of most likely diagnosis and does not contain any discrete or relevant diagnosis.
3. Support
10 points - Differential diagnoses are consistently supported by at least three (3) relevant subjective or objective history.
7.5 points - Differential diagnoses are consistently supported by at 2-3 relevant subjective or objective history, and are factually accurate.
5 points - Differential diagnoses are somewhat supported by relevant subjective or objective history but contain some factual errors.
2.5 points - Differential diagnoses are loosely supported by relevant subjective or objective history and contain factual errors.
0 points - Differential diagnoses are not supported by relevant subjective or objective history.
""",
"minimum_score": 2
},
"phase4": {
"name": "Patient Plan",
"fields": {
"patient_plan": {
"type": "text_area",
"height": 400,
"label": """Please paste the PATIENT PLAN section of your note""",
"value": """Urinalysis, US of abdomen, and cbc with diff continue current medications - consult to nephrology and follow up in a week."""
}
},
"phase_instructions": """Confirm that the user has adequately provided a plan with investigations that are relevant to the differential diagnosis.""",
"user_prompt": "{physical_exam}",
"allow_skip": True,
"scored_phase": True,
"rubric": """
1. Relevant Patient Plan
10 points - The plan consists of investigations and/or physical examinations and are consistently relevant to the differential diagnoses corresponding to the patient’s encounter.
7.5 points - The plan consists of investigations and/or physical examinations and are mostly relevant to the differential diagnoses corresponding to the patient’s encounter.
5 points - The plan has some investigations and/or physical examinations relevant to the differential diagnoses corresponding to the patient’s encounter.
2.5 points - The plan contains some relevant and some irrelevant investigations and/or physical examinations corresponding to the patients differential diagnoses.
0 points - The plan is not relevant to the differential diagnoses corresponding to the patient’s encounter.
""",
"minimum_score": 2
}
}
def prompt_conditionals(prompt, user_input, phase_name=None):
#TO-DO: This is a hacky way to make prompts conditional that requires the user to know a lot of python and get the phase and field names exactly right. Future task to improve it.
return prompt
selected_llm = "gpt-4o-mini"
LLM_CONFIGURATIONS = {
"gpt-4o-mini": {
"model": "gpt-4o-mini",
"frequency_penalty": 0,
"max_tokens": 1000,
"presence_penalty": 0,
"temperature": 1,
"top_p": 1,
"price_input_token_1M":0.150,
"price_output_token_1M":.600
},
"gpt-4-turbo": {
"model": "gpt-4-turbo",
"frequency_penalty": 0,
"max_tokens": 1000,
"presence_penalty": 0,
"temperature": 1,
"top_p": 1,
"price_input_token_1M":10,
"price_output_token_1M":30
},
"gpt-4o": {
"model": "gpt-4o",
"frequency_penalty": 0,
"max_tokens": 250,
"presence_penalty": 0,
"temperature": 1,
"top_p": 1,
"price_input_token_1M":5,
"price_output_token_1M":15
},
"gemini-1.0-pro": {
"model": "gemini-1.0-pro",
"temperature": 1,
"top_p": 0.95,
"max_tokens": 1000,
"price_input_token_1M":.5,
"price_output_token_1M":1.5
},
"gemini-1.5-flash": {
"model": "gemini-1.5-flash",
"temperature": 1,
"top_p": 0.95,
"max_tokens": 1000,
"price_input_token_1M":.35,
"price_output_token_1M":1.05
},
"gemini-1.5-pro": {
"model": "gemini-1.5-pro",
"temperature": 1,
"top_p": 0.95,
"max_tokens": 1000,
"price_input_token_1M":3.5,
"price_output_token_1M":10.50
},
"claude-3.5-sonnet": {
"model": "claude-3-5-sonnet-20240620",
"max_tokens": 1000,
"temperature": 1,
"price_input_token_1M": 3,
"price_output_token_1M": 15
},
"claude-opus": {
"model": "claude-3-opus-20240229",
"max_tokens": 1000,
"temperature": 1,
"price_input_token_1M": 15,
"price_output_token_1M": 75
},
"claude-sonnet": {
"model": "claude-3-sonnet-20240229",
"max_tokens": 1000,
"temperature": 1,
"price_input_token_1M": 3,
"price_output_token_1M": 15
},
"claude-haiku": {
"model": "claude-3-haiku-20240307",
"max_tokens": 1000,
"temperature": 1,
"price_input_token_1M": 0.25,
"price_output_token_1M": 1.25
}
}
SCORING_DEBUG_MODE = True
DISPLAY_COST = True
COMPLETION_MESSAGE = "You've reached the end! I hope you learned something!"
COMPLETION_CELEBRATION = False