Spaces:
Runtime error
Runtime error
Commit ·
57bf226
1
Parent(s): ce15480
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 |
# 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 |
-
#
|
| 223 |
-
await
|
| 224 |
-
content=response,
|
| 225 |
-
author="Paul Graham Essay Bot"
|
| 226 |
-
).send()
|
| 227 |
|
| 228 |
except Exception as e:
|
| 229 |
error_message = str(e)
|
|
|
|
| 213 |
try:
|
| 214 |
lcel_rag_chain = cl.user_session.get("lcel_rag_chain")
|
| 215 |
|
| 216 |
+
# Create a message to stream to
|
| 217 |
+
msg = cl.Message(content="")
|
| 218 |
+
await msg.send()
|
| 219 |
+
|
| 220 |
# Get the response as a single string
|
| 221 |
response = await cl.make_async(lcel_rag_chain.invoke)(
|
| 222 |
{"query": message.content},
|
| 223 |
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
| 224 |
)
|
| 225 |
|
| 226 |
+
# Update the message with the complete response
|
| 227 |
+
await msg.update(response)
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
except Exception as e:
|
| 230 |
error_message = str(e)
|