Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -125,14 +125,74 @@ st.sidebar.caption(f"Session ID: {genuuid()}")
|
|
125 |
# Main chat interface
|
126 |
st.header("Chat with the Agents")
|
127 |
user_id = st.text_input("User ID:", key="user_id")
|
128 |
-
user_input = st.text_input("Write your message here:", key="user_input")
|
129 |
-
|
130 |
-
if 'history' not in st.session_state:
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
user_id=user_id,
|
137 |
user_input=user_input,
|
138 |
numberOfQuestions=numberOfQuestions,
|
@@ -148,17 +208,5 @@ if st.button("Send"):
|
|
148 |
temperature2=temp2
|
149 |
)
|
150 |
response = call_chat_api(data)
|
151 |
-
|
152 |
-
|
153 |
-
st.markdown(f"##### Time take: {format_elapsed_time(response['elapsed_time'])}")
|
154 |
-
st.markdown(f"##### Question Count : {response['count']} of {numberOfQuestions}")
|
155 |
-
|
156 |
-
|
157 |
-
# {"count":count, "user_id":user_id,"time_stamp":time_stamp, "elapsed_time":elapsed_time, "content":content}
|
158 |
-
|
159 |
-
st.session_state.history.append("You: " + user_input)
|
160 |
-
|
161 |
-
st.session_state.history.append("Agent: " + response['content']) # Using 'response' after it's defined
|
162 |
-
for message in st.session_state.history:
|
163 |
-
st.write(message)
|
164 |
-
|
|
|
125 |
# Main chat interface
|
126 |
st.header("Chat with the Agents")
|
127 |
user_id = st.text_input("User ID:", key="user_id")
|
128 |
+
# user_input = st.text_input("Write your message here:", key="user_input")
|
129 |
+
|
130 |
+
# if 'history' not in st.session_state:
|
131 |
+
# st.session_state.history = []
|
132 |
+
|
133 |
+
# if st.button("Send"):
|
134 |
+
# # Placeholder for processing the input and generating a response
|
135 |
+
# data = ChatRequestClient(
|
136 |
+
# user_id=user_id,
|
137 |
+
# user_input=user_input,
|
138 |
+
# numberOfQuestions=numberOfQuestions,
|
139 |
+
# welcomeMessage="",
|
140 |
+
# llm1=llm1,
|
141 |
+
# tokens1=tokens1,
|
142 |
+
# temperature1=temp1,
|
143 |
+
# persona1SystemMessage=persona1SystemMessage,
|
144 |
+
# persona2SystemMessage=persona2SystemMessage,
|
145 |
+
# userMessage2=userMessage2,
|
146 |
+
# llm2=llm2,
|
147 |
+
# tokens2=tokens2,
|
148 |
+
# temperature2=temp2
|
149 |
+
# )
|
150 |
+
# response = call_chat_api(data)
|
151 |
+
|
152 |
+
|
153 |
+
st.markdown(f"##### Time take: {format_elapsed_time(response['elapsed_time'])}")
|
154 |
+
st.markdown(f"##### Question Count : {response['count']} of {numberOfQuestions}")
|
155 |
+
|
156 |
+
|
157 |
+
# # {"count":count, "user_id":user_id,"time_stamp":time_stamp, "elapsed_time":elapsed_time, "content":content}
|
158 |
|
159 |
+
# st.session_state.history.append("You: " + user_input)
|
160 |
+
|
161 |
+
# st.session_state.history.append("Agent: " + response['content']) # Using 'response' after it's defined
|
162 |
+
# for message in st.session_state.history:
|
163 |
+
# st.write(message)
|
164 |
+
# session state
|
165 |
+
if "chat_history" not in st.session_state:
|
166 |
+
st.session_state.chat_history = [
|
167 |
+
AIMessage(content="Hello, I am the GSK Reg Intel Assistant. How can I help you?"),
|
168 |
+
]
|
169 |
+
|
170 |
+
# conversation
|
171 |
+
for message in st.session_state.chat_history:
|
172 |
+
if isinstance(message, AIMessage):
|
173 |
+
with st.chat_message("AI"):
|
174 |
+
st.write(message.content)
|
175 |
+
elif isinstance(message, HumanMessage):
|
176 |
+
with st.chat_message("Human"):
|
177 |
+
st.write(message.content)
|
178 |
+
|
179 |
+
# user input
|
180 |
+
user_query = st.chat_input("Type your message here...")
|
181 |
+
if user_query is not None and user_query != "":
|
182 |
+
st.session_state.chat_history.append(HumanMessage(content=user_query))
|
183 |
+
|
184 |
+
with st.chat_message("Human"):
|
185 |
+
st.markdown(user_query)
|
186 |
+
|
187 |
+
|
188 |
+
# Display the table in the sidebar
|
189 |
+
st.sidebar.write("### Knowledge Base Results")
|
190 |
+
st.sidebar.dataframe(df) # Adjust height as needed
|
191 |
+
else:
|
192 |
+
st.sidebar.write("No relevant knowledge base results found.")
|
193 |
+
|
194 |
+
with st.chat_message("AI"):
|
195 |
+
data = ChatRequestClient(
|
196 |
user_id=user_id,
|
197 |
user_input=user_input,
|
198 |
numberOfQuestions=numberOfQuestions,
|
|
|
208 |
temperature2=temp2
|
209 |
)
|
210 |
response = call_chat_api(data)
|
211 |
+
response = st.write_stream(call_chat_api(data))
|
212 |
+
st.session_state.chat_history.append(AIMessage(content=response))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|