dawit45's picture
Create engine.py
a1229d6 verified
Raw
History Blame Contribute Delete
1.16 kB
from openai import OpenAI
import os
from dotenv import load_dotenv
load_dotenv() # Loads the API key from a .env file
# Add your key here or in a .env file
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", # Use GPT-4o for medical reasoning
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)}"