The following code is giving me a 404 error. From my understanding a 404 in this case is that I am calling an incorrect endpoint except I am using the openai library so I don’t believe I am making an error in the api url aspect.
import { NextResponse } from 'next/server';
import { Configuration, OpenAIApi } from 'openai';
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
export async function POST(request) {
try {
const { description } = await request.json();
if (!description || description === '') {
return new Response('Please send your prompt', { status: 400 });
}
const aiResult = await openai.createCompletion({
model: 'gpt-3.5-turbo',
prompt: `This is my prompt say something back`,
temperature: 0,
max_tokens: 2048,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});
return NextResponse.json({text: aiResult});
} catch(error) {
console.error(error);
return new Response('An error occurred', { status: 500 });
}
}