Chainlit / cookbook

Chainlit's cookbook repo
https://github.com/Chainlit/chainlit
747 stars 275 forks source link

How to get the "source_documents" with chainlit 0.7?? #57

Closed wangpengfei2048 closed 3 weeks ago

wangpengfei2048 commented 9 months ago
  I get the source_documents with chainlit 0.6:

code : @cl.on_message async def main(message: cl.Message): chain = cl.user_session.get("chain") # type: ConversationalRetrievalChain cb = cl.AsyncLangchainCallbackHandler()

res = await chain.acall(message.content, callbacks=[cb])
answer = res["answer"]
source_documents = res["source_documents"]  # type: List[Document]
....

  I use chainlit 0.7 now , I use this code to get the answer:

code: async for chunk in runnable.astream( message.content, config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]), ): await res.stream_token(chunk)

 the result "res" is “Message”, how to get the “source_documents”?
willydouhard commented 9 months ago

This is a Langchain question but I am not sure you can get the source documents with the astream method

wangpengfei2048 commented 9 months ago

Yes , It is a Langchain question, they are two different methods to ask. chainlit also changes it using LCEL. and I change it , but I want to use source_documents as before, can you give some suggestion?? there is an example with chainlit ,but the old method..

https://docs.chainlit.io/examples/qa

kennethleungty commented 9 months ago

Having the same question as @wangpengfei2048

willydouhard commented 9 months ago

This post on discord covers that I believe.

wangpengfei2048 commented 9 months ago

what is the link, i cant reach it.

now I use astream_log() to get the answer and the source_documents

ModEnter commented 3 weeks ago

Glad you found a way to solve your issue ! I'm marking is as resolved 😉