davidfearne commited on
Commit
ee19843
·
verified ·
1 Parent(s): 6ee4ae8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -48
app.py CHANGED
@@ -104,54 +104,61 @@ st.sidebar.caption(f"Session ID: {genuuid()}")
104
  # Main chat interface
105
  st.header("Chat with the Agents")
106
 
107
- # Initialize chat history in session state
108
- if "messages" not in st.session_state:
109
- st.session_state.messages = []
110
-
111
- # Display chat messages from history on app rerun
112
- for message in st.session_state.messages:
113
- with st.chat_message(message["role"]):
114
- st.markdown(message["content"])
115
-
116
- # Collect user input
117
- if user_input := st.chat_input("Write your message here:"):
118
- # Add user message to the chat history
119
- st.session_state.messages.append({"role": "user", "content": user_input})
120
- st.chat_message("user").markdown(user_input)
121
-
122
- # Prepare data for API call
123
- data = ChatRequestClient(
124
- user_id=user_id,
125
- user_input=user_input,
126
- numberOfQuestions=numberOfQuestions,
127
- welcomeMessage="",
128
- llm1=llm1,
129
- tokens1=tokens1,
130
- temperature1=temp1,
131
- persona1SystemMessage=persona1SystemMessage,
132
- persona2SystemMessage=persona2SystemMessage,
133
- userMessage2=userMessage2,
134
- llm2=llm2,
135
- tokens2=tokens2,
136
- temperature2=temp2
137
- )
138
-
139
- # Call the API
140
- response = call_chat_api(data)
141
-
142
- # Process the API response
143
- agent_message = response.get("content", "No response received from the agent.")
144
- elapsed_time = response.get("elapsed_time", 0)
145
- count = response.get("count", 0)
146
-
147
- # Add agent response to the chat history
148
- st.session_state.messages.append({"role": "assistant", "content": agent_message})
149
- with st.chat_message("assistant"):
150
- st.markdown(agent_message)
151
-
152
- # Display additional metadata
153
- st.markdown(f"##### Time taken: {format_elapsed_time(elapsed_time)} seconds")
154
- st.markdown(f"##### Question Count: {count} of {numberOfQuestions}")
 
 
 
 
 
 
 
155
 
156
 
157
 
 
104
  # Main chat interface
105
  st.header("Chat with the Agents")
106
 
107
+ # User ID Input
108
+ user_id = st.text_input("User ID:", key="user_id")
109
+
110
+ # Ensure user_id is defined or fallback to a default value
111
+ if not user_id:
112
+ st.warning("Please provide a User ID to start the chat.")
113
+ else:
114
+ # Initialize chat history in session state
115
+ if "messages" not in st.session_state:
116
+ st.session_state.messages = []
117
+
118
+ # Display chat messages from history on app rerun
119
+ for message in st.session_state.messages:
120
+ with st.chat_message(message["role"]):
121
+ st.markdown(message["content"])
122
+
123
+ # Collect user input
124
+ if user_input := st.chat_input("Write your message here:"):
125
+ # Add user message to the chat history
126
+ st.session_state.messages.append({"role": "user", "content": user_input})
127
+ st.chat_message("user").markdown(user_input)
128
+
129
+ # Prepare data for API call
130
+ data = ChatRequestClient(
131
+ user_id=user_id, # Ensure user_id is passed correctly
132
+ user_input=user_input,
133
+ numberOfQuestions=numberOfQuestions,
134
+ welcomeMessage="",
135
+ llm1=llm1,
136
+ tokens1=tokens1,
137
+ temperature1=temp1,
138
+ persona1SystemMessage=persona1SystemMessage,
139
+ persona2SystemMessage=persona2SystemMessage,
140
+ userMessage2=userMessage2,
141
+ llm2=llm2,
142
+ tokens2=tokens2,
143
+ temperature2=temp2
144
+ )
145
+
146
+ # Call the API
147
+ response = call_chat_api(data)
148
+
149
+ # Process the API response
150
+ agent_message = response.get("content", "No response received from the agent.")
151
+ elapsed_time = response.get("elapsed_time", 0)
152
+ count = response.get("count", 0)
153
+
154
+ # Add agent response to the chat history
155
+ st.session_state.messages.append({"role": "assistant", "content": agent_message})
156
+ with st.chat_message("assistant"):
157
+ st.markdown(agent_message)
158
+
159
+ # Display additional metadata
160
+ st.markdown(f"##### Time taken: {format_elapsed_time(elapsed_time)} seconds")
161
+ st.markdown(f"##### Question Count: {count} of {numberOfQuestions}")
162
 
163
 
164