Update app.py
Browse files
app.py
CHANGED
@@ -103,14 +103,23 @@ userMessage2 = st.sidebar.text_area("Define User Message", value="This is the co
|
|
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 |
-
|
110 |
-
|
|
|
111 |
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
data = ChatRequestClient(
|
115 |
user_id=user_id,
|
116 |
user_input=user_input,
|
@@ -126,19 +135,23 @@ if st.button("Send"):
|
|
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 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
|
|
|
103 |
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,
|
|
|
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 |
|