-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data going undefined #5684
Comments
The issue with To fix this, you should use the promise-based version of /*eslint-disable*/
import fs from 'fs/promises';
import { OpenAI } from "@langchain/openai";
import { PromptTemplate } from "@langchain/core/prompts";
const OPENAI_API_KEY = "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";
export async function handlePdfUpload(pdf, query) {
console.log("This is pdf", pdf.path);
console.log("This is query", query);
let bufferData;
try {
const data = await fs.readFile(pdf.path);
bufferData = "My name is Lakshya and I am of 23 age";
console.log(bufferData.toString());
} catch (err) {
console.log(err);
return;
}
const model = new OpenAI({ temperature: 0, apiKey: OPENAI_API_KEY });
const API_URL_PROMPT_TEMPLATE1 = `Given the following information, please answer the question:
Information:
${bufferData}
Question:
${query}
`;
const API_URL_PROMPT_TEMPLATE = new PromptTemplate({
inputVariables: ["bufferData", "query"],
template: API_URL_PROMPT_TEMPLATE1,
});
const apiUrlPrompt = await API_URL_PROMPT_TEMPLATE.format({
bufferData: "My name is lakshya and age is 23",
query: query,
});
const apiUrlResponse = await model.generate([apiUrlPrompt]);
console.log("OPEN API RESPONSE:", JSON.stringify(apiUrlResponse, null, 2));
return apiUrlResponse;
} By using |
Be careful, your |
Currently, langchainjs/examples/src/prompts/quickstart/hard_coded_fstring.ts Lines 14 to 17 in a4448fe
|
Checked other resources
Example Code
/eslint-disable/
import fs from 'fs';
import { OpenAI } from "@langchain/openai";
import { PromptTemplate } from "@langchain/core/prompts";
const OPENAI_API_KEY = "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"
export async function handlePdfUpload(pdf,query)
{
let bufferData;
console.log("This is pdf",pdf.path)
console.log("This is query",query)
fs.readFile(pdf.path,(err,data)=>{
if(err)
{
console.log(err)
}
else
{
bufferData="My name is Lakshya and I am of 23 age";
console.log(bufferData.toString())
})
const model = new OpenAI({ temperature: 0, apiKey: OPENAI_API_KEY });
const API_URL_PROMPT_TEMPLATE1 = `Given the following information, please answer the question:
Information:
${bufferData}
Question:
${query}
`;
const API_URL_PROMPT_TEMPLATE = /* #PURE */ new PromptTemplate({
inputVariables: ["bufferData", "query"],
template: API_URL_PROMPT_TEMPLATE1,
});
const apiUrlPrompt = await API_URL_PROMPT_TEMPLATE.format({
bufferData: "My name is lakshya and age is 23",
query:query,
});
const apiUrlResponse = await model.generate([apiUrlPrompt]);
console.log("OPEN API RESPONSE:", JSON.stringify(apiUrlResponse, null, 2));
return apiUrlResponse
}
Error Message and Stack Trace (if applicable)
Description
I mught think buffer Data is undefined so I purt explicitally data but still information going undefined
System Info
all good
The text was updated successfully, but these errors were encountered: