Проблема BufferMemory с ConversationalRetrievalQAChain в JavaScript/Nodejs
Я использую Langchain в Nodejs и следую официальной документации, чтобы сохранить контекст разговора, используяConversationalRetrievalQAChain
иBufferMemory
и не может передать объект памяти вConversationalRetrievalQAChain.fromLLM
согласно документации здесь: https://js.langchain.com/docs/modules/chains/popular/chat_vector_db/.
const encoder = new TextEncoder();
const stream = new TransformStream();
const writer = stream.writable.getWriter();
console.log("Querying Pinecone vector store...");
const index = client.Index(indexName);
const queryEmbedding = await new OpenAIEmbeddings().embedQuery(question);
let queryResponse = await index.query({
queryRequest: {
topK: 10,
vector: queryEmbedding,
includeMetadata: true,
includeValues: true,
},
});
if (queryResponse.matches.length) {
const model = new OpenAI({
modelName: "gpt-3.5-turbo",
streaming: true,
temperature: 0,
openAIApiKey: process.env.OPENAI_API_KEY || "",
callbacks: [
{
async handleLLMNewToken(token) {
await writer.ready;
await writer.write(encoder.encode(`${token}`));
},
async handleLLMEnd() {
await writer.ready;
await writer.close();
},
},
],
});
const concatenatedPageContent = queryResponse.matches
.map((match) => match.metadata.pageContent)
.join(" ");
const vectorStore = await PineconeStore.fromDocuments(
[new Document({ pageContent: concatenatedPageContent })],
new OpenAIEmbeddings(),
{
pineconeIndex: index,
}
);
const chain = ConversationalRetrievalQAChain.fromLLM(
model,
vectorStore.asRetriever(),
{
memory: new BufferMemory({
memoryKey: "chat_history", // Must be set to "chat_history"
}),
}
);
/* Ask it a question */
const question = "What did the president say about Justice Breyer?";
const res = await chain.call({ question });
console.log(res);
/* Ask it a follow up question */
const followUpRes = await chain.call({
question: "Was that nice?",
});
console.log(followUpRes);
Ошибка:Argument of type '{ memory: BufferMemory; }' is not assignable to parameter of type '{ outputKey?: string | undefined; returnSourceDocuments?: boolean | undefined; questionGeneratorTemplate?: string | undefined; qaTemplate?: string | undefined; } & Omit<ConversationalRetrievalQAChainInput, "retriever" | ... 1 more ... | "questionGeneratorChain">'. Object literal may only specify known properties, and 'memory' does not exist in type '{ outputKey?: string | undefined; returnSourceDocuments?: boolean | undefined; questionGeneratorTemplate?: string | undefined; qaTemplate?: string | undefined; } & Omit<ConversationalRetrievalQAChainInput, "retriever" | ... 1 more ... | "questionGeneratorChain">'.ts(2345)
Цель: Моя цель — сохранить контекст разговора в документе PDF.
Я открыт для других предложений по моему варианту использования. Поддержка Langchain с Nodejs очень меньшая.
1 ответ
я имел"langchain": "^0.0.84",
и я получал ту же ошибку
обновить пакет до последней версии, на данный момент"langchain": "^0.0.127"
и это работает