Prompt Issue #5699
Replies: 1 comment
-
The issue you're encountering where the OpenAI API always returns the same answer is likely due to the To introduce variability in the responses, you should increase the /*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 {
bufferData = await fs.readFile(pdf.path);
console.log(bufferData.toString());
bufferData = bufferData.toString();
} catch (err) {
console.log(err);
return;
}
const model = new OpenAI({ temperature: 0.7, apiKey: OPENAI_API_KEY });
const API_URL_PROMPT_TEMPLATE1 = `You have given the information ${bufferData} give me any data contained in file in response:
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: bufferData,
query: query,
});
const apiUrlResponse = await model.generate([apiUrlPrompt]);
console.log("OPEN API RESPONSE:", JSON.stringify(apiUrlResponse, null, 2));
return apiUrlResponse;
} By setting the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
When I pass the data and query to openAI it will always give me same ans cant provide answer why it is happening
System Info
all good
Beta Was this translation helpful? Give feedback.
All reactions