Spaces:
Runtime error
Runtime error
Commit
·
ce15480
1
Parent(s):
fe85ba7
fix async error
Browse files
app.py
CHANGED
|
@@ -213,17 +213,18 @@ async def main(message: cl.Message):
|
|
| 213 |
try:
|
| 214 |
lcel_rag_chain = cl.user_session.get("lcel_rag_chain")
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
chunks = await cl.make_async(lcel_rag_chain.stream)(
|
| 219 |
{"query": message.content},
|
| 220 |
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
| 221 |
)
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
await msg.send()
|
| 227 |
except Exception as e:
|
| 228 |
error_message = str(e)
|
| 229 |
if "Connection reset by peer" in error_message or "Connection aborted" in error_message:
|
|
|
|
| 213 |
try:
|
| 214 |
lcel_rag_chain = cl.user_session.get("lcel_rag_chain")
|
| 215 |
|
| 216 |
+
# Get the response as a single string
|
| 217 |
+
response = await cl.make_async(lcel_rag_chain.invoke)(
|
|
|
|
| 218 |
{"query": message.content},
|
| 219 |
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
| 220 |
)
|
| 221 |
|
| 222 |
+
# Create and send the message with the response
|
| 223 |
+
await cl.Message(
|
| 224 |
+
content=response,
|
| 225 |
+
author="Paul Graham Essay Bot"
|
| 226 |
+
).send()
|
| 227 |
|
|
|
|
| 228 |
except Exception as e:
|
| 229 |
error_message = str(e)
|
| 230 |
if "Connection reset by peer" in error_message or "Connection aborted" in error_message:
|