createChatCompletion method returning undefined in the choices array
Problem
Describe the bug I'm using node.js with the official opean ai lib and when I tried to send a request, I got nothing, the choices array is empty. It's working fine with davinci model, just this new one `model: "gpt-3.5-turbo",` isn't working. To Reproduce Code snippets _No response_ OS windows Node version v10.19.0 Library version 3.2.1
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Update Node.js and OpenAI Library for GPT-3.5 Turbo Compatibility
The issue arises because the OpenAI library version 3.2.1 may not fully support the 'gpt-3.5-turbo' model due to compatibility issues with Node.js version 10.19.0. The 'gpt-3.5-turbo' model requires a more recent version of Node.js and possibly a newer version of the OpenAI library to function correctly.
Awaiting Verification
Be the first to verify this fix
- 1
Upgrade Node.js
Upgrade Node.js to at least version 14.x or higher, as the newer models require features and performance improvements found in later versions.
bashnvm install 14 nvm use 14 - 2
Update OpenAI Library
Update the OpenAI library to the latest version to ensure compatibility with the 'gpt-3.5-turbo' model.
bashnpm install openai@latest - 3
Check API Key and Model Configuration
Ensure that the API key is correctly set and that the model is specified correctly in your request. The model should be 'gpt-3.5-turbo'.
javascriptconst openai = require('openai'); const response = await openai.createChatCompletion({ model: 'gpt-3.5-turbo', messages: [{ role: 'user', content: 'Hello!' }] }); - 4
Test the API Call
Run your application to test if the API call to 'gpt-3.5-turbo' now returns a valid response with a populated choices array.
javascriptconsole.log(response.choices);
Validation
Confirm that the choices array in the response from the 'createChatCompletion' method is populated with valid responses from the 'gpt-3.5-turbo' model. If the array contains valid entries, the fix is successful.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep