Spaces:
Sleeping
Sleeping
File size: 9,866 Bytes
ca397b9 50123fb ca397b9 2d3472b ca397b9 50123fb ca397b9 50123fb ca397b9 |
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
import os
import streamlit as st
from datetime import datetime
import json
import requests
import uuid
from datetime import date, datetime
import requests
from pydantic import BaseModel, Field
from typing import Optional
placeHolderPersona1 = """##Diagnostic Agent (DA):
##Objective: Gather comprehensive details about the user's illness.
##Conversation Flow:
#Symptom Collection:
Primary Symptoms: Ask about the main symptoms the user is experiencing.
Duration and Severity: Gather details on how long the symptoms have been present and their severity.
Medical History: Collect information on any relevant medical history or existing conditions.
Current Medications: Inquire about any current medications the user
is taking.
Allergies: Identify any known allergies to medications.
Lifestyle Factors: Consider any lifestyle factors that may affect the choice of medication.
##Example Interaction:
DA: "Can you describe the primary symptoms you are experiencing?"
User: "I have a persistent cough and fever."
DA: "How long have you been experiencing these symptoms?"
"""
placeHolderPersona2 = """## You are an advisor for a doctor, augmenting their professional opinion on prescribed drug options
## Objective: Analyse the structured data to identify suitable medicinal products for the list given in the user message from the given conversation between an AI doctor and a human patient
## Processing Steps:
Symptom Analysis: Evaluate the symptoms and other collected information.
Product Matching: Match the symptoms and patient profile to suitable medicinal products.
IDMP Compliance: Ensure the identified products are compliant with IDMP standards.
Recommendation Generation: Generate a list of recommended medicinal products.
Feedback Loop: If needed, request additional information from the DA or user.
# Example Interaction:
RA: "Based on the symptoms of a persistent cough and fever, along with your medical history, we recommend considering ProductX and ProductY. Please consult with your healthcare provider before use."""
placeHolderUser2 = """This is the list of available drugs on offer to prescribe please use your understanding of the Generic version of each drug and give the Trademark Name
Trademark Name,Generic,Product area
Amoxil,amoxiicillin,General medicines
Anoro Ellipta,umeclidinium and vilanterol,General medicines
Arnuity Ellipta,Fluticasone,General medicines
Augmentin,amoxicillin/clavulanate potassium,General medicines
Avamys / Veramyst,fluticasone furoate,General medicines
Avodart/Avolve / Duodart,dutasteride,General medicines
Bactroban,mupirocin,General medicines
Beconase,beclomethasone,General medicines
Becotide/Becloforte,beclomethasone dipropionate,General medicines
Betnovate,betamethasone valerate,General medicines
Cutivate,fluticasone propionate,General medicines
Dermovate,clobetasol propionate,General medicines
Duac,clindamycin phosphate and benzoyl peroxide,General medicines
Eltroxin,Levothyroxin sodium,General medicines
Eumovate,clobetasone butyrate,General medicines
Flixonase/Flonase,fluticasone propionate,General medicines
Flixotide / Flovent - Diskus / MDI,fluticasone propionate,General medicines
Flolan,epoprostenol,General medicines
Fortum,ceftazidime,General medicines
Hepsera,Adefovir,General medicines
Imigran/ImITrex FDT,sumatriptan succinate,General medicines
Imuran,Azathioprine,General medicines
Incruse,umeclidinium,General medicines
Keppra,Levetiracetam,General medicines
Lacipil,Lacidipine,General medicines
Lacticare - Family,Lactic Acid,General medicines
Lamictal,lamotrigine,General medicines
Lanoxin,Digoxin,General medicines
Levoxacin,Levofloxacin,General medicines
Lovaza,omega-3 acid ethyl esters,General medicines
Malarone,atovaquone and proguanil hydrochloride,General medicines
Mepron,atovaquone,General medicines
Naramig/Amerge,naratriptan hydrochloride,General medicines
Paxil / Seroxat,paroxetine hydrochloride,General medicines
Relenza,zanamivir,General medicines
Relvar/Breo,Fluticasone furoate/vilanterol,General medicines
Requip,ropinirole hydrochloride,General medicines
Rythmol,propafenone hydrochloride,General medicines
Septrin,Cotrimoxazole,General medicines
Seretide / Advair - Diskus / MDI,"salmeterol xinofoate, fluticasone propionate",General medicines
Serevent - Diskus / MDI,salmeterol xinafoate,General medicines
Toctino,Alitretinoin,General medicines
Trelegy - Ellipta,"fluticasone furoate, umeclidinium, and vilanterol inhalation powder",General medicines
Valtrex,valaciclovir hydrochloride,General medicines
Ventolin - Diskus / MDI,Salbutamol,General medicines
Volibris (Ambrisentan),ambrisentan,General medicines
Wellbutrin,bupropion hydrochloride,General medicines
Xyzal,Levocetirizine,General medicines
Zagallo,Dutasteride,General medicines
Zeffix,lamivudine,General medicines
Zentel,Albendazole,General medicines
Zinacef,cefuroxime,General medicines
Zovirax,aciclovir,General medicines
Zyban,bupropion hydrochloride,General medicines
Zyloric,Allopurinol,General medicines
Zyrtec,cetirizine,General medicines
This is the conversation to date,
"""
class ChatRequestClient(BaseModel):
user_id: str
user_input: str
numberOfQuestions: int
welcomeMessage: str
llm1: str
tokens1: int
temperature1: float
persona1SystemMessage: str
persona2SystemMessage: str
userMessage2: str
llm2: str
tokens2: int
temperature2: float
def call_chat_api(data: ChatRequestClient):
url = "https://agent-builder-api.greensea-b20be511.northeurope.azurecontainerapps.io/chat/"
# Validate and convert the data to a dictionary
validated_data = data.dict()
# Make the POST request to the FastAPI server
response = requests.post(url, json=validated_data)
if response.status_code == 200:
return response.json() # Return the JSON response if successful
else:
return "An error occured" # Return the raw response text if not successful
def genuuid ():
return uuid.uuid4()
def format_elapsed_time(time):
# Format the elapsed time to two decimal places
return "{:.2f}".format(time)
# Title of the application
# st.image('agentBuilderLogo.png')
st.title('LLM-Powered Agent Interaction')
# Sidebar for inputting personas
st.sidebar.image('agentBuilderLogo.png')
st.sidebar.header("Agent Personas Design")
# st.sidebar.subheader("Welcome Message")
# welcomeMessage = st.sidebar.text_area("Define Triaging Persona", value=welcomeMessage, height=300)
st.sidebar.subheader("Finance Intake AI")
numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=10, step=1, value=5, key='persona1_questions')
persona1SystemMessage = st.sidebar.text_area("Define Triaging Persona", value=placeHolderPersona1, height=300)
with st.sidebar.expander("See explanation"):
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")
st.image("agentPersona1.png")
llm1 = st.sidebar.selectbox("Model Selection", ['GPT3.5','GPT-4'], key='persona1_size')
temp1 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona1_temp')
tokens1 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens')
# Persona 2
st.sidebar.subheader("Diagnosis and Next Best Action AI")
persona2SystemMessage = st.sidebar.text_area("Define Diagnosis Persona", value=placeHolderPersona2, height=300)
with st.sidebar.expander("See explanation"):
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. ")
st.image("agentPersona2.png")
llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
temp2 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.3, key='persona2_temp')
tokens2 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=2000, key='persona2_tokens')
userMessage2 = st.sidebar.text_area("Define User Message", value=placeHolderUser2, height=150)
st.sidebar.caption(f"Session ID: {genuuid()}")
# Main chat interface
st.header("Chat with the Agents")
user_id = st.text_input("User ID:", key="user_id")
user_input = st.text_input("Write your message here:", key="user_input")
if 'history' not in st.session_state:
st.session_state.history = []
if st.button("Send"):
# Placeholder for processing the input and generating a response
data = ChatRequestClient(
user_id=user_id,
user_input=user_input,
numberOfQuestions=numberOfQuestions,
welcomeMessage="",
llm1=llm1,
tokens1=tokens1,
temperature1=temp1,
persona1SystemMessage=persona1SystemMessage,
persona2SystemMessage=persona2SystemMessage,
userMessage2=userMessage2,
llm2=llm2,
tokens2=tokens2,
temperature2=temp2
)
response = call_chat_api(data)
st.markdown(f"##### Time take: {format_elapsed_time(response['elapsed_time'])}")
st.markdown(f"##### Question Count : {response['count']} of {numberOfQuestions}")
# {"count":count, "user_id":user_id,"time_stamp":time_stamp, "elapsed_time":elapsed_time, "content":content}
st.session_state.history.append("You: " + user_input)
st.session_state.history.append("Agent: " + response['content']) # Using 'response' after it's defined
for message in st.session_state.history:
st.write(message)
|