Spaces:
Sleeping
Sleeping
import chainlit as cl | |
from qdrant_client import QdrantClient | |
from rag_graph import RagGraph | |
def get_qdrant_client(): | |
"""Create a QdrantClient instance and cache it for restarts during development.""" | |
from qdrant_client import QdrantClient | |
return QdrantClient(path='data/vectors') | |
async def on_chat_start(): | |
"""Create the RAG graph and store it in the user session.""" | |
qdrant_client = get_qdrant_client() | |
rag_graph = RagGraph(qdrant_client) | |
cl.user_session.set("rag_graph", rag_graph) | |
async def on_message(question: cl.Message): | |
"""Stream the response to the user.""" | |
msg = cl.Message(content="") | |
# Send a message to the user to indicate that the response is being generated | |
await msg.send() | |
rag_graph = cl.user_session.get("rag_graph") | |
# Update the message when streaming is complete | |
await rag_graph.stream(question.content, msg) | |