Streaming for MultiRetrievalQAChain on langchain JS #3280
Replies: 1 comment 2 replies
-
🤖 Based on the context provided, it seems like you want to stream only the final response from the Here's how you can modify your code: // Create a retrieval QA chain that uses a Llama 2-powered QA stuff chain with a custom prompt.
const chain = new RetrievalQAChain({
combineDocumentsChain: loadQAStuffChain(model, { prompt: QA_CHAIN_PROMPT }),
retriever,
returnSourceDocuments: true,
inputKey: "question",
});
const stream = chain.call({
question: "What are the approaches to Task Decomposition?",
});
let finalResponse;
stream.on('data', (data) => {
finalResponse = data;
});
stream.on('end', () => {
console.log({ finalResponse });
}); In this code, we're creating a stream from the call to the chain. We then listen for 'data' events on the stream, and each time we receive data, we update our This solution was suggested in a similar issue titled Stream only the final answer when using an agent in the langchainjs repository. I hope this helps! If you have any other questions, feel free to ask. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone, I'm developing a chatbot that uses the MultiRetrievalQAChain function to provide the most appropriate response. I've managed to get it to work in "normal" mode`
I now want to switch to stream mode to improve response time, the problem is that all intermediate actions are streamed, I only want to stream the last response and not all intermediate responses.
here is my working synchronous code:
here my streamcode that not work
here is the console output for the stream
Does anyone have any clues?
Many thanks to anyone who will take the time to answer my questions.
Beta Was this translation helpful? Give feedback.
All reactions