Spaces:
Paused
Paused
Update components/chat.py
Browse files- components/chat.py +20 -10
components/chat.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# components/chat.py
|
| 2 |
import streamlit as st
|
| 3 |
from langchain_core.messages import HumanMessage, AIMessage
|
|
|
|
| 4 |
|
| 5 |
def display_chat_interface():
|
| 6 |
"""Display chat interface component"""
|
|
@@ -21,17 +22,26 @@ def display_chat_interface():
|
|
| 21 |
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 22 |
try:
|
| 23 |
with st.spinner("Analyzing documents..."):
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
st.error(f"Error generating response: {e}")
|
|
|
|
| 1 |
# components/chat.py
|
| 2 |
import streamlit as st
|
| 3 |
from langchain_core.messages import HumanMessage, AIMessage
|
| 4 |
+
import asyncio
|
| 5 |
|
| 6 |
def display_chat_interface():
|
| 7 |
"""Display chat interface component"""
|
|
|
|
| 22 |
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 23 |
try:
|
| 24 |
with st.spinner("Analyzing documents..."):
|
| 25 |
+
# Use asyncio to handle the async call
|
| 26 |
+
async def get_response():
|
| 27 |
+
response = await st.session_state.qa_system.acall({
|
| 28 |
+
"input": prompt,
|
| 29 |
+
"chat_history": st.session_state.chat_history
|
| 30 |
+
})
|
| 31 |
+
return response
|
| 32 |
+
|
| 33 |
+
# Run the async function
|
| 34 |
+
response = asyncio.run(get_response())
|
| 35 |
|
| 36 |
+
if response and 'output' in response:
|
| 37 |
+
# Add messages to chat history
|
| 38 |
+
st.session_state.chat_history.append(HumanMessage(content=prompt))
|
| 39 |
+
st.session_state.chat_history.append(AIMessage(content=response['output']))
|
| 40 |
+
|
| 41 |
+
# Force refresh to show new messages
|
| 42 |
+
st.rerun()
|
| 43 |
+
else:
|
| 44 |
+
st.error("No valid response received from the agent")
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
st.error(f"Error generating response: {e}")
|