File size: 1,057 Bytes
f855cbe
 
2b6c76f
 
228e62f
f855cbe
2b6c76f
228e62f
f855cbe
228e62f
 
 
 
 
 
 
 
 
 
f855cbe
f22899d
228e62f
f855cbe
 
 
228e62f
f855cbe
 
2b6c76f
228e62f
2b6c76f
f855cbe
 
228e62f
2b6c76f
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
import openai
from keys import mykey
import gradio as gr

# Set your OpenAI API key
openai.api_key = mykey["mediQ"]

# Chat function
def gpt_response(message, history=[]):
    # Reformat history into proper OpenAI chat message format
    messages = [
        {"role": "system", "content": "You are a careful and experienced clinical reasoning expert."}
    ]
    for user_msg, bot_msg in history:
        messages.append({"role": "user", "content": user_msg})
        messages.append({"role": "assistant", "content": bot_msg})
    messages.append({"role": "user", "content": message})

    # Call OpenAI GPT-4
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages,
        temperature=0.3,
        max_tokens=300
    )

    reply = response["choices"][0]["message"]["content"]
    return reply

# Gradio chat interface
gr.ChatInterface(
    fn=gpt_response,
    title="🧠 MediQ GPT-4 Clinical Reasoning",
    description="Ask a clinical question. GPT-4 will simulate adaptive expert reasoning.",
).launch()