Replies: 1 comment
-
🤖 Hello, The issue you're experiencing is likely due to the fact that you're using the To fix this, you can wrap your code in an async function. Here's how you can do it: import { ChatOpenAI } from "langchain/chat_models/openai";
import { ConversationalRetrievalQAChain } from "langchain/chains";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { BufferMemory } from "langchain/memory";
import { TextLoader } from "langchain/document_loaders/fs/text";
import { CharacterTextSplitter } from "langchain/text_splitter";
import { FaissStore } from "langchain/vectorstores/faiss";
async function main() {
const loader = new TextLoader("./restaurant.txt");
const docs = await loader.load();
const splitter = new CharacterTextSplitter({
chunkSize: 200,
chunkOverlap: 50,
});
const documents = await splitter.splitDocuments(docs);
const embeddings1 = new OpenAIEmbeddings();
const vectorStore = await FaissStore.fromDocuments(documents, embeddings1);
await vectorStore.save("./");
const model = new ChatOpenAI({
openAIApiKey: process.env.OPENAI_API_KEY,
});
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);
}
main(); Also, make sure to compile your TypeScript code to JavaScript before running it with Node.js. You can do this by running I hope this helps! Let me know if you have any other questions. 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.
-
I run:
node 010_cchain.js
from 010_cchain.js:
Beta Was this translation helpful? Give feedback.
All reactions