+ 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

19th Jun 2024, 2:37 AM
Gautam Kumar Sharma
Gautam Kumar Sharma - avatar
8 odpowiedzi
+ 4
deprecated... google what it means. 🙄you fix it. update to gpt
19th Jun 2024, 10:30 AM
Bob_Li
Bob_Li - avatar
+ 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"}}
19th Jun 2024, 10:21 AM
Bob_Li
Bob_Li - avatar
+ 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'); } }
19th Jun 2024, 6:45 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Please specify the error.
19th Jun 2024, 9:09 AM
Gautam Kumar Sharma
Gautam Kumar Sharma - avatar
+ 2
I think the problem is that you haven't added a valid api_key. "Bearer API_GOES_HERE" is not a valid key.
19th Jun 2024, 3:03 PM
Jan
Jan - avatar
+ 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…?
19th Jun 2024, 5:11 PM
X—X
X—X - avatar
0
Fix it
19th Jun 2024, 10:28 AM
Gautam Kumar Sharma
Gautam Kumar Sharma - avatar
0
Easy fix
20th Jun 2024, 4:26 PM
Torren “Bruddashizz” Nick
Torren “Bruddashizz” Nick - avatar