+ 1
I've got error in my code. Can you fix it.
I've create chat bot using openAi api with html and javascript. But there is an error while running the code. https://sololearn.com/compiler-playground/W0P6kVaVEv1B/?ref=app
8 Answers
+ 4
deprecated... google what it means.
đyou fix it. update to gpt
+ 3
if you tried printing the response, this is what you get:
{"error":{"message":"The model `davinci-codex` has been deprecated, learn more here: https://platform.openai.com/docs/deprecations","type":"invalid_request_error","param":null,"code":"model_not_found"}}
+ 2
I believe the error occurs here:
try {
const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-proj-6K9VBIIZdTwghyfCMp01T3BlbkFJ3WpQVoSx1YTlFgpUfXQp'
},
body: JSON.stringify({
prompt: userInput,
max_tokens: 150
})
});
const data = await response.json();
const botMessage = data.choices[0].text.trim();
displayMessage(botMessage, 'bot-message');
} catch (error) {
console.error('Error:', error);
displayMessage('Sorry, something went wrong.', 'bot-message');
}
}
+ 2
Please specify the error.
+ 2
I think the problem is that you haven't added a valid api_key. "Bearer API_GOES_HERE" is not a valid key.
+ 2
Hereâs your corrected JS Code:
try {
const response = await fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_OPENAI_API_KEY_GOES_HERE'
},
body: JSON.stringify({
model: 'gpt-3.5-turbo-0125', // Specify the GPT-3 model here
prompt: userInput,
max_tokens: 150
})
});
Now youâre using https://api.openai.com/v1/completions instead of depreciated (no longer supported) AI chat models.
By the way YOUR_OPENAI_API_KEY_GOES_HERE is not your API key. Iâm not paying for that. But if/when you get it then put it there.
Also I made your model identifier to the latest and most reasonably priced text-only model that OpenAI has to offer. The GPT-3.5 Turbo (gpt-3.5-turbo-0125) but feel free to change that. ))) Good luck
Also this code: Bearer API_GOES_HERE instead of even *trying* an API key makes the code seem either stolen or AI generated�
0
Fix it
0
Easy fix