nc_experimental / get_answer.py
Adr740's picture
Update get_answer.py
860d4ef verified
import requests
from bs4 import BeautifulSoup
from openai import OpenAI
import base64
from config import openai_api
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
client = OpenAI(api_key=openai_api)
sys_prompt ="""
Generate the most probable diagnosis with a likelihood percentage, followed by a comprehensive medical reasoning that justifies why this diagnosis is the most plausible. Use evidence from medical literature, guidelines from sources such as NIS, NRD, or NHANES, and incorporate socio-environmental factors as well as insights from past physician experiences (this aspect is critical). Additionally, cite all references, including papers from Randomized Phase III clinical trials, and provide accessible links to the sources. Ensure that the reasoning is detailed, with clear explanations for each point, following the structure outlined in the provided image. Use the following fake patient medical record as the basis for your analysis.
Include information about but not limited to, Clinical Presentation, Risk Factors, Laboratory Findings, Physical Examination, Imaging and Diagnostics, Socio-Environmental Factors, Past Physician Experience
Additional Differential Diagnosis
Management Recommendations
Prognosis
"""
def get_ai_response(prompt_content, prompt):
global sys_prompt
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": [
{
"type": "text",
"text": sys_prompt
}
]
},
{
"role": "user",
"content": prompt_content
},
],
temperature=1,
max_tokens=1439,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
return response.choices[0].message.content
def get_answer(patient_data, prompt):
answer = get_ai_response(patient_data, prompt)
# answer = ""
return answer