davidfearne commited on
Commit
b177ad3
·
verified ·
1 Parent(s): 5c2bc53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -25
app.py CHANGED
@@ -9,26 +9,31 @@ import requests
9
  from pydantic import BaseModel, Field
10
  from typing import Optional
11
 
12
- welcomeMessage = "Welcome to the Ford Car Selection AI Agent I am here to talk about your motoring needs, please start by giving me your key requirement"
13
 
14
 
15
- placeHolderPersona1 = """# MISSION
16
- You are a car sales chatbot focusing on gaining enough information to make a selection. Your mission is to ask questions to help a customer fully articulate their needs in a clear manner.
17
- When they ask you a question or give you a need ask a suitable follow up question
18
-
19
- # RULES
20
  Ask only one question at a time.
21
  Provide some context or clarification around the follow-up questions you ask.
22
  Do not converse with the customer.
23
- Be as concise as possible"""
 
24
 
25
- placeHolderPersona2 = """# MISSION
26
- You are a car selection expert you will be given a dialoge between a customer and a sales executive. Your job is to select the perfect car for the customer based on their conversation
27
- # RULES
28
- You will need to select 1 primary choice car and one secondary choice car
29
- You will need to give some justification as to why you have chosen these cars
30
- Do not converse with the customer.
31
- Be as concise as possible"""
 
 
 
 
 
32
 
33
 
34
 
@@ -48,7 +53,7 @@ class ChatRequestClient(BaseModel):
48
  temperature2: float
49
 
50
  def call_chat_api(data: ChatRequestClient):
51
- url = "https://agent-builder-api.greensea-b20be511.northeurope.azurecontainerapps.io/chat/"
52
  # Validate and convert the data to a dictionary
53
  validated_data = data.dict()
54
 
@@ -62,7 +67,23 @@ def call_chat_api(data: ChatRequestClient):
62
 
63
  def genuuid ():
64
  return uuid.uuid4()
 
 
 
 
 
 
 
 
 
65
 
 
 
 
 
 
 
 
66
  # Title of the application
67
  # st.image('agentBuilderLogo.png')
68
  st.title('LLM-Powered Agent Interaction')
@@ -70,18 +91,24 @@ st.title('LLM-Powered Agent Interaction')
70
  # Sidebar for inputting personas
71
  st.sidebar.image('agentBuilderLogo.png')
72
  st.sidebar.header("Agent Personas Design")
73
- st.sidebar.subheader("Welcome Message")
74
- welcomeMessage = st.sidebar.text_area("Define Persona 1", value=welcomeMessage, height=150)
75
  st.sidebar.subheader("Personas 1 Settings")
76
- numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=2, step=1, value=5, key='persona1_questions')
77
- persona1SystemMessage = st.sidebar.text_area("Define Persona 1", value=placeHolderPersona1, height=150)
 
 
 
78
  llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona1_size')
79
  temp1 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.6, key='persona1_temp')
80
  tokens1 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens')
81
 
82
  # Persona 2
83
  st.sidebar.subheader("Personas 2 Settings")
84
- persona2SystemMessage = st.sidebar.text_area("Define Persona 2", value=placeHolderPersona2, height=150)
 
 
 
85
  llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
86
  temp2 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona2_temp')
87
  tokens2 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona2_tokens')
@@ -101,7 +128,7 @@ if st.button("Send"):
101
  user_id=user_id,
102
  user_input=user_input,
103
  numberOfQuestions=numberOfQuestions,
104
- welcomeMessage=welcomeMessage,
105
  llm1=llm1,
106
  tokens1=tokens1,
107
  temperature1=temp1,
@@ -113,9 +140,18 @@ if st.button("Send"):
113
  temperature2=temp2
114
  )
115
  response = call_chat_api(data)
 
 
 
 
 
 
 
 
116
  st.session_state.history.append("You: " + user_input)
117
- st.session_state.history.append("Agent: " + response) # Using 'response' after it's defined
 
 
 
 
118
 
119
- # Display the chat history
120
- for message in st.session_state.history:
121
- st.text(message)
 
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
+
28
+ ## Diagnostic Process
29
+ Upon receipt of the clinical notes, I will follow a systematic approach to arrive at a diagnosis:
30
+ 1. Review the patient's presenting symptoms and consider their relevance to immunopathology.
31
+ 2. Cross-reference the gathered information with my knowledge base of immunology to identify patterns or indicators of specific immune disorders.
32
+ 3. Formulate a diagnosis from the potential conditions.
33
+ 4. Determine the most likely diagnosis and assign a confidence score from 1-100, with 100 being absolute certainty.
34
+
35
+ # Limitations
36
+ 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"""
37
 
38
 
39
 
 
53
  temperature2: float
54
 
55
  def call_chat_api(data: ChatRequestClient):
56
+ url = "http://127.0.0.1:8000/chat/"
57
  # Validate and convert the data to a dictionary
58
  validated_data = data.dict()
59
 
 
67
 
68
  def genuuid ():
69
  return uuid.uuid4()
70
+
71
+ def format_elapsed_time(time):
72
+ # Format the elapsed time to two decimal places
73
+ return "{:.2f}".format(time)
74
+
75
+ def update_history(response):
76
+ # Initialize the history list if it doesn't exist
77
+ if 'history' not in st.session_state:
78
+ st.session_state.history = []
79
 
80
+ # Append the agent's response to the history
81
+ st.session_state.history.append("Agent: " + response['content'])
82
+ def display_history():
83
+ # Display each item in the history
84
+ for item in st.session_state.history:
85
+ st.text_area(label="", value=item, height=75)
86
+
87
  # Title of the application
88
  # st.image('agentBuilderLogo.png')
89
  st.title('LLM-Powered Agent Interaction')
 
91
  # Sidebar for inputting personas
92
  st.sidebar.image('agentBuilderLogo.png')
93
  st.sidebar.header("Agent Personas Design")
94
+ # st.sidebar.subheader("Welcome Message")
95
+ # welcomeMessage = st.sidebar.text_area("Define Triaging Persona", value=welcomeMessage, height=150)
96
  st.sidebar.subheader("Personas 1 Settings")
97
+ numberOfQuestions = st.sidebar.slider("Number of Questions", min_value=0, max_value=10, step=1, value=5, key='persona1_questions')
98
+ persona1SystemMessage = st.sidebar.text_area("Define Triaging Persona", value=placeHolderPersona1, height=150)
99
+ with st.sidebar.expander("See explanation"):
100
+ st.write("Personas: the individual members of the business function / agent equivalent to employee’s. They have job or personality specific design and are crafted to think, and reason based on this job or personality specific design. They have free reign to feedback to the task however they see most appropriate ")
101
+ st.image("agentPersona1.png")
102
  llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona1_size')
103
  temp1 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.6, key='persona1_temp')
104
  tokens1 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens')
105
 
106
  # Persona 2
107
  st.sidebar.subheader("Personas 2 Settings")
108
+ persona2SystemMessage = st.sidebar.text_area("Define Selection Persona", value=placeHolderPersona2, height=150)
109
+ with st.sidebar.expander("See explanation"):
110
+ st.write("Personas: the individual members of the business function / agent equivalent to employee’s. They have job or personality specific design and are crafted to think, and reason based on this job or personality specific design. They have free reign to feedback to the task however they see most appropriate ")
111
+ st.image("agentPersona2.png")
112
  llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
113
  temp2 = st.sidebar.slider("Tempreature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona2_temp')
114
  tokens2 = st.sidebar.slider("Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona2_tokens')
 
128
  user_id=user_id,
129
  user_input=user_input,
130
  numberOfQuestions=numberOfQuestions,
131
+ welcomeMessage="",
132
  llm1=llm1,
133
  tokens1=tokens1,
134
  temperature1=temp1,
 
140
  temperature2=temp2
141
  )
142
  response = call_chat_api(data)
143
+
144
+
145
+ st.markdown(f"##### Time take: {format_elapsed_time(response['elapsed_time'])}")
146
+ st.markdown(f"##### Question Count : {response['count']} of {numberOfQuestions}")
147
+
148
+
149
+ # {"count":count, "user_id":user_id,"time_stamp":time_stamp, "elapsed_time":elapsed_time, "content":content}
150
+
151
  st.session_state.history.append("You: " + user_input)
152
+
153
+ st.session_state.history.append("Agent: " + response['content']) # Using 'response' after it's defined
154
+ for message in st.session_state.history:
155
+ st.write(message)
156
+
157