Open mangled-data opened 10 months ago
on_chat_start is called once per user. Every time a user sends a message, on_message is called.
I use the Askfile when on-message send, then you can check if use send file or not with the message, also check again if chain is set in session during the on-message so you can get the chain. on resume will need to check if chain field existed in thread.metadata and then you can get the vectordb from vector db store( suggest you named collection is thread id), something like this:
if message.elements or cl.user_session.get("chain") is not None:
files = message.elements
if files:
await process_file(files)# process file and set chain in session
chain = cl.user_session.get("chain") # type: ConversationalRetrievalChain
if chain is None:
await cl.Message(content="Sorry, I am unable to process your request", disable_feedback=True).send()
return
I had refactored the code in https://github.com/Chainlit/docs/blob/aa50e881dde660ee7393b0b80427e6c88524a3a5/examples/qa.mdx#L53
I am missing something on the flow. I thought on_chat_start would be invoked once per run, but it seems to be invoked periodically. Because I read embeddings from cache, it gets repeated over and over from what I could tell. It feels like a simpler sync implementation might be helpful because it is not clear who gets called when easily (and I also wonder race conditions may get to be harder to debug)