Spaces:
Sleeping
Sleeping
Update gpt_analyzer.py
Browse files- gpt_analyzer.py +25 -11
gpt_analyzer.py
CHANGED
@@ -11,41 +11,55 @@ class GPTAnalyzer:
|
|
11 |
prompt = f"""
|
12 |
As a hospital data analyst, analyze this data request:
|
13 |
"{request_text}"
|
14 |
-
|
15 |
Consider these available data sources in hospital Web Data system:
|
16 |
{json.dumps(available_categories, indent=2, ensure_ascii=False)}
|
17 |
-
|
18 |
-
Return JSON
|
19 |
{{
|
20 |
"required_reports": [
|
21 |
{{
|
22 |
-
"category": "
|
23 |
-
"report_type": "
|
24 |
-
"fields_needed": ["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
"filters": {{
|
26 |
-
"date_range": "
|
27 |
-
"other_filters": [
|
28 |
}}
|
29 |
}}
|
30 |
],
|
31 |
"interpretation": "Brief explanation of what data is needed",
|
32 |
"confidence_score": "HIGH/MEDIUM/LOW"
|
33 |
}}
|
|
|
|
|
|
|
|
|
|
|
34 |
"""
|
35 |
-
|
36 |
try:
|
37 |
response = self.client.chat.completions.create(
|
38 |
messages=[
|
39 |
{
|
40 |
"role": "system",
|
41 |
-
"content": "You are a healthcare data analyst expert who understands hospital information systems."
|
42 |
},
|
43 |
{
|
44 |
"role": "user",
|
45 |
"content": prompt
|
46 |
}
|
47 |
],
|
48 |
-
model="gpt-
|
49 |
response_format={ "type": "json_object" }
|
50 |
)
|
51 |
return json.loads(response.choices[0].message.content)
|
|
|
11 |
prompt = f"""
|
12 |
As a hospital data analyst, analyze this data request:
|
13 |
"{request_text}"
|
14 |
+
|
15 |
Consider these available data sources in hospital Web Data system:
|
16 |
{json.dumps(available_categories, indent=2, ensure_ascii=False)}
|
17 |
+
|
18 |
+
Return JSON that precisely matches this structure. Fields must exactly match the available report fields:
|
19 |
{{
|
20 |
"required_reports": [
|
21 |
{{
|
22 |
+
"category": "OPD",
|
23 |
+
"report_type": "diagnosis",
|
24 |
+
"fields_needed": ["HN", "Patient_Name", "VisitDate", "Doctor_Name", "ICD_Code", "ICD_Name"],
|
25 |
+
"filters": {{
|
26 |
+
"date_range": "January 2024",
|
27 |
+
"other_filters": []
|
28 |
+
}}
|
29 |
+
}},
|
30 |
+
{{
|
31 |
+
"category": "OPD",
|
32 |
+
"report_type": "waiting_times",
|
33 |
+
"fields_needed": ["HN", "Wait_Time_Statistics"],
|
34 |
"filters": {{
|
35 |
+
"date_range": "January 2024",
|
36 |
+
"other_filters": []
|
37 |
}}
|
38 |
}}
|
39 |
],
|
40 |
"interpretation": "Brief explanation of what data is needed",
|
41 |
"confidence_score": "HIGH/MEDIUM/LOW"
|
42 |
}}
|
43 |
+
|
44 |
+
IMPORTANT:
|
45 |
+
- report_type must match exactly one of the available report names
|
46 |
+
- fields_needed must match exactly the field names in the reports
|
47 |
+
- The response must maintain this exact structure
|
48 |
"""
|
49 |
+
|
50 |
try:
|
51 |
response = self.client.chat.completions.create(
|
52 |
messages=[
|
53 |
{
|
54 |
"role": "system",
|
55 |
+
"content": "You are a healthcare data analyst expert who understands hospital information systems. Always return exact matching report names and field names."
|
56 |
},
|
57 |
{
|
58 |
"role": "user",
|
59 |
"content": prompt
|
60 |
}
|
61 |
],
|
62 |
+
model="gpt-4",
|
63 |
response_format={ "type": "json_object" }
|
64 |
)
|
65 |
return json.loads(response.choices[0].message.content)
|