I created the pipeline using langchain inside the JavaScript, when I am using chain.invoke() method its working precisely but when I am trying to call the chain by chain.stream() method I am getting issues as nothing prints on the console. Is there anyone facing the same issues?
const prompt = ChatPromptTemplate.fromMessages([
["system", systemPrompt],
new MessagesPlaceholder("chat_history"),
["user", "{input}"],
["user", userPrompt],
]);
// console.log("Prompt is : ");
// console.log(prompt);
// Chain creation using prompt and model
const chain = await createStuffDocumentsChain({
llm: modelInstance,
prompt,
});
// Initialize retriever with the vector store
const startTimeInner = Date.now();
const retriever = vectorStore.asRetriever({
search_type: "mmr",
search_kwargs: { k: 3 },
});
// console.log(vectorStore);
const endTimeInner = Date.now();
console.log(
"Total time taken by retriever to fetch data from db: ",
(endTimeInner - startTimeInner) / 1000
);
// Create a retrieval chain with the retriever and document chain
const retrievalChain = await createRetrievalChain({
retriever,
combineDocsChain: chain,
});
calling a streaming response
const response = await chain.stream({
chat_history: chatHistory,
input: question,
});
let firstResponse = false;
for await (const chunk of response) {
console.log(chunk);
yield chunk.answer;
}