langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.71k stars 2.19k forks source link

TypeError: t.replaceAll is not a function - While loading txt or pdf files #437

Closed rohanprasadofficial closed 1 year ago

rohanprasadofficial commented 1 year ago

Hi Team , I am getting this error when loading pdf or txt through HNSWLib.

Below is code snippet :

Attempt to load Text File

/ Initialize the LLM to use to answer the question / const model = new OpenAI({openAIApiKey:OPENAI_API_KEY}); / Load in the file we want to do question answering over /

const loader = new PDFLoader(__dirname + "/naval.txt"); const docs = await loader.load(); / Create the vectorstore / const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings({openAIApiKey:OPENAI_API_KEY})); / Create the chain / const chain = VectorDBQAChain.fromLLM(model, vectorStore); / Ask it a question / const result = await chain.call({ query: "What did the president say about Justice Breyer?", });

Attempt to load PDF File

/ Initialize the LLM to use to answer the question / const model = new OpenAI({openAIApiKey:OPENAI_API_KEY}); / Load in the file we want to do question answering over /

const loader = new TextLoader(__dirname + "/naval.pdf"); const docs = await loader.load(); / Create the vectorstore / const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings({openAIApiKey:OPENAI_API_KEY})); / Create the chain / const chain = VectorDBQAChain.fromLLM(model, vectorStore); / Ask it a question / const result = await chain.call({ query: "What did the president say about Justice Breyer?", });

Both the time it throws same error :

image

Please let me know if i am missing something.

rohanprasadofficial commented 1 year ago

upgrading to latest version of node worked.