I'm trying to update my app from Angular 15 and "openai": "^3.2.1" to Angular 17 and "openai": ^4.24.1".
I cannot understand what is missing. No errors occurred.
Followed links:
https://platform.openai.com/docs/guides/text-generation/completions-api
OpenAI API error: "The model `text-davinci-003` has been deprecated"
Old version:
import { Configuration, OpenAIApi } from 'openai';
readonly configuration = new Configuration({
organization: environment.openAIOrganization,
apiKey: environment.openAIToken,
});
readonly openai = new OpenAIApi(this.configuration);
//#region -- GENERATE CHATGPT MSG --
async getDataFromOpenAI(text: string): Promise<any> {
try {
const completion = await this.openai.createCompletion({
model: "text-davinci-003",
prompt: text,
temperature: 0.9,
max_tokens: 62,
},
{
headers: {
'Content-Type': 'application/json',
//'baseOptions': 'User-Agent',
'Authorization': 'Bearer ' + environment.openAIToken,
'Access-Control-Allow-Origin': '*'
}
})
return completion.data.choices[0].text
}
catch (error) {
console.error('error.message', error);
}
}
//#endregion
New version:
import OpenAI from 'openai';
async generateSms() {
try {
let completion = await this.openai.completions.create({
model: 'gpt-3.5-turbo-instruct',
prompt: 'Create a happy birthday message',
temperature: 0.5,
});
console.log(completion);
console.log(completion.choices[0].text);
} catch (e) {
console.error('generateSms => ', e);
}
}
I created a new key but is only returning [null]
Last used in API KEY is updating: last used 12/jan

The initialization is different with the OpenAI Node.js SDK
v4than withv3.If you're using the OpenAI Node.js SDK
v4, then the following is the correct initialization:You did the completion part correctly, as follows: