Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -41,23 +41,23 @@ def initialize_chainlit():
|
|
41 |
)
|
42 |
)
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
|
62 |
@app.route('/')
|
63 |
def home():
|
|
|
41 |
)
|
42 |
)
|
43 |
|
44 |
+
# Setup chainlit callbacks
|
45 |
+
@cl.on_chat_start
|
46 |
+
async def on_chat_start():
|
47 |
+
prompt = ChatPromptTemplate.from_messages([("human", "{question}")])
|
48 |
+
runnable = prompt | llm | StrOutputParser()
|
49 |
+
cl.user_session.set("runnable", runnable)
|
50 |
|
51 |
+
@cl.on_message
|
52 |
+
async def on_message(message: cl.Message):
|
53 |
+
runnable = cl.user_session.get("runnable") # type: Runnable
|
54 |
+
msg = cl.Message(content="")
|
55 |
+
async for chunk in runnable.astream(
|
56 |
+
{"question": message.content},
|
57 |
+
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
58 |
+
):
|
59 |
+
await msg.stream_token(chunk)
|
60 |
+
await msg.send()
|
61 |
|
62 |
@app.route('/')
|
63 |
def home():
|