Error in prompt template #6011
Unanswered
LakshyaTambi
asked this question in
Q&A
Replies: 1 comment
-
Hey @LakshyaTambi! I'm here to help you with any bugs, questions, or contributions while you're waiting for a human maintainer. To resolve the "400 You provided an invalid 'prompt'" error, ensure that the prompt you are providing is a valid string and formatted correctly. Here is a revised version of your code:
const { OpenAI } = require('@langchain/openai');
const { config } = require('dotenv');
const { PromptTemplate } = require('@langchain/core/prompts');
const fs = require('fs');
const pdf = require('pdf-parse');
config();
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
let dataBuffer = fs.readFileSync('./test.pdf');
let finalData;
pdf(dataBuffer).then(async function(data) {
// use data
finalData = data.text;
console.log(finalData);
const model = new OpenAI({ temperature: 0.1, apiKey: OPENAI_API_KEY });
const API_URL_PROMPT_TEMPLATE1 = `You have been provided some information and a question based on this information answer the question
here is the information : {api_docs};
here is the question : {question}`;
let question1 = "Can you give me the name of the person whose resume belongs";
const API_URL_PROMPT_TEMPLATE = new PromptTemplate({
inputVariables: ["api_docs", "question"],
template: API_URL_PROMPT_TEMPLATE1,
});
const apiUrlPrompt = API_URL_PROMPT_TEMPLATE.format({
api_docs: finalData,
question: question1,
});
const apiUrlResponse = await model.generate([apiUrlPrompt]);
console.log("API URL Response:", JSON.stringify(apiUrlResponse, null, 1));
console.log("Generated API URL:", apiUrlResponse);
}).catch(function(error){
// handle exceptions
console.error(error);
});
Make sure the
Ensure that the prompt is a non-empty string and does not contain any invalid characters or formatting issues. This should resolve the error and ensure that the prompt is correctly formatted and processed by the OpenAI API. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
C:\Users\LakshyaTambi\Desktop\VidForm\node_modules\openai\error.js:45
return new BadRequestError(status, error, message, headers);
^
BadRequestError: 400 You provided an invalid 'prompt'. Your prompt was provided in list-with-dicts format, but a dict you provided was not valid.
at APIError.generate (C:\Users\LakshyaTambi\Desktop\VidForm\node_modules\openai\error.js:45:20)
at OpenAI.makeStatusError (C:\Users\LakshyaTambi\Desktop\VidForm\node_modules\openai\core.js:275:33)
at OpenAI.makeRequest (C:\Users\LakshyaTambi\Desktop\VidForm\node_modules\openai\core.js:318:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:\Users\LakshyaTambi\Desktop\VidForm\node_modules@langchain\openai\dist\llms.cjs:508:29
at async RetryOperation._fn (C:\Users\LakshyaTambi\Desktop\VidForm\node_modules\p-retry\index.js:50:12) {
status: 400,
headers: {
'access-control-allow-origin': '*',
'alt-svc': 'h3=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'cf-ray': '8a078be46ed317ab-MAA',
connection: 'keep-alive',
'content-length': '237',
'content-type': 'application/json',
date: 'Tue, 09 Jul 2024 10:14:19 GMT',
'openai-model': 'gpt-3.5-turbo-instruct',
'openai-organization': 'user-i3axtx9nmx2opwzhcrh8ixou',
'openai-processing-ms': '21',
'openai-version': '2020-10-01',
server: 'cloudflare',
'set-cookie': '__cf_bm=qjnyDACNmXh5Hk8a7jfblAcTx7LtEQi4.nLoP6uUcdY-1720520059-1.0.1.1-cdCOjiwLYx7XwMMU7BkAhxIBkGBeVQxnuReTMcWEyokotZdr.ySXVO3ZA_fY0O.jHiTiCC2nugum3iJu_PsJhw; path=/; expires=Tue, 09-Jul-24 10:44:19 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None, _cfuvid=TKTBlJOknwkowFWY8FGAnMAwpVu0XXDosKmQLnb8slA-1720520059907-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'x-ratelimit-limit-requests': '3500',
'x-ratelimit-remaining-requests': '3499',
'x-ratelimit-reset-requests': '17ms',
'x-request-id': 'req_b0a723a81a548bc26558e385ed887be3'
},
request_id: 'req_b0a723a81a548bc26558e385ed887be3',
error: {
message: "You provided an invalid 'prompt'. Your prompt was provided in list-with-dicts format, but a dict you provided was not valid.",
type: 'invalid_request_error',
param: null,
code: null
},
code: null,
param: null,
type: 'invalid_request_error',
attemptNumber: 1,
retriesLeft: 6
}
System Info
ok
Beta Was this translation helpful? Give feedback.
All reactions