File size: 2,015 Bytes
8f0fd77
 
 
 
 
 
 
 
 
 
 
 
 
13cfff6
 
860d4ef
 
 
 
 
 
 
 
 
aa273ac
13cfff6
11546a5
13cfff6
8f0fd77
 
 
 
 
 
 
 
13cfff6
8f0fd77
 
 
 
 
 
 
 
 
 
 
 
 
 
11546a5
8f0fd77
 
11546a5
 
8f0fd77
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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