My code was working properly untill I changed my API key to use openai through Azure, this was my old code:
const {Configuration, OpenAIApi } = require('openai');
const apiKey = process.env.OPENAI_API_KEY;
const configuration = new Configuration({
apiKey: apiKey,
});
const openai = new OpenAIApi(configuration);
async function chatGPT(prompt,question,model_gpt) {
try
{
const response = await openai.createChatCompletion({
model: model_gpt,
messages: [
{
role: 'system',
content: prompt
},
{
role: 'user',
content: question
}
]
});
const completion = response.data.choices[0].message.content;
return completion;
}
now using Azure I had to use some new parameters:
const {Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: process.env.placeholder_azure_APIKEY,
api_type: "azure",
api_base: "placeholder_azure_path",
api_version: "placeholder_version_azure",
});
const openai = new OpenAIApi(configuration);
async function chatGPT(prompt,question,model_gpt) {
try
{
const response = await openai.ChatCompletion.create({
engine: "placeHolder",
messages: [
{
role: 'system',
content: prompt
},
{
role: 'user',
content: question
}
],
});
console.log(response);
const completion = response.data.choices[0].message;
console.log(completion);
return completion;
}
The new code isnāt working and I get an āTypeError: Cannot read properties of undefined (reading ācreateā)ā error on the "await openai.ChatCompletion.create({ā¦})
Did I made an syntax error? Hope you guys can help me.
Iām sure my API keys and path are OK, the code works perfectly on python, but I get these errors using NodeJS.
I tried using createChatCompletion() but I get a 401 error (Authentication error) that makes no sense, since I already used the same Keys/Path on a python script and it worked. Does azure have security locks for diferent programming languages?