davidfearne commited on
Commit
ca397b9
·
verified ·
1 Parent(s): 105ea1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +143 -0
app.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from datetime import datetime
4
+ import json
5
+ import requests
6
+ import uuid
7
+ from datetime import date, datetime
8
+ import requests
9
+ from pydantic import BaseModel, Field
10
+ from typing import Optional
11
+
12
+
13
+
14
+ placeHolderPersona1 = """## Mission Statement
15
+ My mission is to utilize my expertise to aid in the medical triaging process by providing a clear, concise, and accurate assessment of potential arthritis related conditions.
16
+
17
+ # Triaging process
18
+ Ensure you stay on the topic of asking questions to triage the potential of Rheumatoid arthritis.
19
+ Ask only one question at a time.
20
+ Provide some context or clarification around the follow-up questions you ask.
21
+ Do not converse with the customer.
22
+ Be as concise as possible.
23
+ Do not give a diagnosis """
24
+
25
+ placeHolderPersona2 = """## Mission
26
+ To analyse a clinical triaging discussion between a patient and AI doctor interactions with a focus on Immunology symptoms, medical history, and test results to deduce the most probable Immunology diagnosis.
27
+ ## Diagnostic Process
28
+ Upon receipt of the clinical notes, I will follow a systematic approach to arrive at a diagnosis:
29
+ 1. Review the patient's presenting symptoms and consider their relevance to immunopathology.
30
+ 2. Cross-reference the gathered information with my knowledge base of immunology to identify patterns or indicators of specific immune disorders.
31
+ 3. Formulate a diagnosis from the potential conditions.
32
+ 4. Determine the most likely diagnosis and assign a confidence score from 1-100, with 100 being absolute certainty.
33
+ # Limitations
34
+ While I am specialized in immunology, I understand that not all cases will fall neatly within my domain. In instances where the clinical notes point to a condition outside of my expertise, I will provide the best possible diagnosis with the acknowledgment that my confidence score will reflect the limitations of my specialization in those cases"""
35
+
36
+
37
+
38
+ class ChatRequestClient(BaseModel):
39
+ user_id: str
40
+ user_input: str
41
+ numberOfQuestions: int
42
+ welcomeMessage: str
43
+ llm1: str
44
+ tokens1: int
45
+ temperature1: float
46
+ persona1SystemMessage: str
47
+ persona2SystemMessage: str
48
+ userMessage2: str
49
+ llm2: str
50
+ tokens2: int
51
+ temperature2: float
52
+
53
+ def call_chat_api(data: ChatRequestClient):
54
+ url = "https://agent-builder-api.greensea-b20be511.northeurope.azurecontainerapps.io/chat/"
55
+ # Validate and convert the data to a dictionary
56
+ validated_data = data.dict()
57
+
58
+ # Make the POST request to the FastAPI server
59
+ response = requests.post(url, json=validated_data)
60
+
61
+ if response.status_code == 200:
62
+ return response.json() # Return the JSON response if successful
63
+ else:
64
+ return "An error occured" # Return the raw response text if not successful
65
+
66
+ def genuuid ():
67
+ return uuid.uuid4()
68
+
69
+ def format_elapsed_time(time):
70
+ # Format the elapsed time to two decimal places
71
+ return "{:.2f}".format(time)
72
+
73
+
74
+ # Title of the application
75
+ # st.image('agentBuilderLogo.png')
76
+ st.title('LLM-Powered Agent Interaction')
77
+
78
+ # Sidebar for inputting personas
79
+ st.sidebar.image('agentBuilderLogo.png')
80
+ st.sidebar.header("Agent Personas Design")
81
+ # st.sidebar.subheader("Welcome Message")
82
+ # welcomeMessage = st.sidebar.text_area("Define Triaging Persona", value=welcomeMessage, height=300)
83
+ st.sidebar.subheader("Symptom Intake AI")
84
+ numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=10, step=1, value=5, key='persona1_questions')
85
+ persona1SystemMessage = st.sidebar.text_area("Define Triaging Persona", value=placeHolderPersona1, height=300)
86
+ with st.sidebar.expander("See explanation"):
87
+ st.write("This AI persona will converse with the patient to gather their symptoms. With each round of chat, the object of the AI is to ask more specific follow up questions as it narrows down to the specific diagnosis. However this AI should never give a diagnosis")
88
+ st.image("agentPersona1.png")
89
+ llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona1_size')
90
+ temp1 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.6, key='persona1_temp')
91
+ tokens1 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens')
92
+
93
+ # Persona 2
94
+ st.sidebar.subheader("Diagnosis and Next Best Action AI")
95
+ persona2SystemMessage = st.sidebar.text_area("Define Diagnosis Persona", value=placeHolderPersona2, height=300)
96
+ with st.sidebar.expander("See explanation"):
97
+ st.write("This AI persona uses the output of the symptom intake AI as its input. This AI’s job is to augment a health professional by assisting with a diagnosis and possible next best action. The teams will need to determine if this should be a tool used directly by the patient, as an assistant to the health professional or a hybrid of the two. ")
98
+ st.image("agentPersona2.png")
99
+ llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
100
+ temp2 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona2_temp')
101
+ tokens2 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona2_tokens')
102
+ userMessage2 = st.sidebar.text_area("Define User Message", value="This is the conversation todate, ", height=150)
103
+ st.sidebar.caption(f"Session ID: {genuuid()}")
104
+ # Main chat interface
105
+ st.header("Chat with the Agents")
106
+ user_id = st.text_input("User ID:", key="user_id")
107
+ user_input = st.text_input("Write your message here:", key="user_input")
108
+
109
+ if 'history' not in st.session_state:
110
+ st.session_state.history = []
111
+
112
+ if st.button("Send"):
113
+ # Placeholder for processing the input and generating a response
114
+ data = ChatRequestClient(
115
+ user_id=user_id,
116
+ user_input=user_input,
117
+ numberOfQuestions=numberOfQuestions,
118
+ welcomeMessage="",
119
+ llm1=llm1,
120
+ tokens1=tokens1,
121
+ temperature1=temp1,
122
+ persona1SystemMessage=persona1SystemMessage,
123
+ persona2SystemMessage=persona2SystemMessage,
124
+ userMessage2=userMessage2,
125
+ llm2=llm2,
126
+ tokens2=tokens2,
127
+ temperature2=temp2
128
+ )
129
+ response = call_chat_api(data)
130
+
131
+
132
+ st.markdown(f"##### Time take: {format_elapsed_time(response['elapsed_time'])}")
133
+ st.markdown(f"##### Question Count : {response['count']} of {numberOfQuestions}")
134
+
135
+
136
+ # {"count":count, "user_id":user_id,"time_stamp":time_stamp, "elapsed_time":elapsed_time, "content":content}
137
+
138
+ st.session_state.history.append("You: " + user_input)
139
+
140
+ st.session_state.history.append("Agent: " + response['content']) # Using 'response' after it's defined
141
+ for message in st.session_state.history:
142
+ st.write(message)
143
+