9
9
10
10
import openai
11
11
12
+
12
13
class BaseModelHandler (ABC ):
13
14
@abstractmethod
14
15
def handle_request (
15
16
self , query : str , context : str
16
17
) -> tuple [str , dict [str , int ], dict [str , float ], float ]:
17
18
pass
18
19
20
+
19
21
# LLM Pricing Calculator: https://www.llm-prices.com/
20
22
# TODO: Add support for more models and their pricing
21
23
22
24
# Anthropic Model Pricing: https://docs.anthropic.com/en/docs/about-claude/pricing#model-pricing
23
25
26
+
24
27
class GPT4OMiniHandler (BaseModelHandler ):
25
28
MODEL = "gpt-4o-mini"
26
29
# TODO: Get the latest model pricing from OpenAI's API or documentation
@@ -44,10 +47,7 @@ def handle_request(
44
47
start_time = time .time ()
45
48
# TODO: Add error handling for API requests and invalid responses
46
49
response = self .client .responses .create (
47
- model = self .MODEL ,
48
- instructions = query ,
49
- input = context ,
50
- temperature = 0.0
50
+ model = self .MODEL , instructions = query , input = context , temperature = 0.0
51
51
)
52
52
duration = time .time () - start_time
53
53
@@ -67,7 +67,7 @@ class GPT41NanoHandler(BaseModelHandler):
67
67
68
68
# GPT 4.1 Prompting Guide: https://cookbook.openai.com/examples/gpt4-1_prompting_guide
69
69
70
- # Long context performance can degrade as more items are required to be retrieved,
70
+ # Long context performance can degrade as more items are required to be retrieved,
71
71
# or perform complex reasoning that requires knowledge of the state of the entire context
72
72
73
73
#
@@ -82,7 +82,7 @@ class GPT41NanoHandler(BaseModelHandler):
82
82
83
83
# Instructions
84
84
85
- - Identify decision points for bipolar medications #TODO: "pharmacological and procedurl interventions"
85
+ - Identify decision points for bipolar medications
86
86
87
87
- For each decision point you find, return a JSON object using the following format:
88
88
@@ -92,15 +92,11 @@ class GPT41NanoHandler(BaseModelHandler):
92
92
"medications": ["<medication 1>", "<medication 2>", ...],
93
93
"reason": "<short explanation for why this criterion applies>",
94
94
"sources": ["<ID-X>"]
95
- "hierarchy": Primary: Contraindictions for allergies
96
- "override" Exclude for allergy
97
95
}
98
96
99
97
100
98
- Only extract bipolar medication decision points that are explicitly stated or strongly implied in the context and never rely on your own knowledge
101
99
102
- - TODO: Test against medication indication file
103
-
104
100
# Output Format
105
101
106
102
- Return the extracted bipolar medication decision points as a JSON array and if no decision points are found in the context return an empty array
@@ -145,15 +141,11 @@ def handle_request(
145
141
if not query :
146
142
query = self .INSTRUCTIONS
147
143
148
-
149
144
start_time = time .time ()
150
145
# TODO: Add error handling for API requests and invalid responses
151
146
152
147
response = self .client .responses .create (
153
- model = self .MODEL ,
154
- instructions = query ,
155
- input = context ,
156
- temperature = 0.0
148
+ model = self .MODEL , instructions = query , input = context , temperature = 0.0
157
149
)
158
150
duration = time .time () - start_time
159
151
@@ -166,10 +158,8 @@ def handle_request(
166
158
167
159
168
160
class ModelFactory :
169
-
170
- #TODO: Define structured fields to extract from unstructured input data
171
- #https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses&example=structured-data#examples
172
-
161
+ # TODO: Define structured fields to extract from unstructured input data
162
+ # https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses&example=structured-data#examples
173
163
174
164
HANDLERS = {
175
165
"GPT_4O_MINI" : GPT4OMiniHandler ,
0 commit comments