Update app.py
Browse files
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 |
-
#
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
#
|
| 119 |
-
st.session_state.messages
|
| 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 |
|
|
|
|
| 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 |
|