Spaces:
Sleeping
Sleeping
import chainlit as cl | |
from langchain_core.runnables import RunnableConfig | |
from rag import chain | |
async def on_chat_start(): | |
cl.user_session.set("runnable", chain) | |
async def on_message(message: cl.Message): | |
runnable = cl.user_session.get("runnable") | |
msg = cl.Message(content="") | |
async for chunk in runnable.astream( | |
message.content, | |
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]), | |
): | |
await msg.stream_token(chunk) | |
await msg.send() | |