| from openai import OpenAI |
| import os |
| from dotenv import load_dotenv |
|
|
| load_dotenv() |
|
|
| |
| client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) |
|
|
| def get_diagnosis(clean_symptoms, clean_history): |
| system_prompt = ( |
| "You are a Clinical Decision Support AI. " |
| "The following data has been de-identified for privacy. " |
| "Analyze the case and provide: " |
| "1. Differential Diagnosis (ranked by likelihood). " |
| "2. Clinical 'Red Flags' to watch for. " |
| "3. Recommended diagnostic tests (e.g., CBC, MRI). " |
| "Keep the tone professional and clinical." |
| ) |
|
|
| try: |
| response = client.chat.completions.create( |
| model="gpt-4o", |
| messages=[ |
| {"role": "system", "content": system_prompt}, |
| {"role": "user", "content": f"Symptoms: {clean_symptoms}\nHistory: {clean_history}"} |
| ], |
| temperature=0.1 |
| ) |
| return response.choices[0].message.content |
| except Exception as e: |
| return f"Error connecting to AI: {str(e)}" |