0
jqueryLearner posted
Error - cant read property of 'create' undefined in openai library
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: 'api key here',
});
const openai = new OpenAIApi(configuration);
async function a(){
try {
const prompt = "Please write a brief summary openai.";
const completion = await openai.Completion.create({
engine: 'text-davinci-003',
prompt: prompt,
max_tokens: 60,
n: 1
});
const summary = completion.choices[0].text.trim();
console.log(summary);
} catch (error) {
if (error.response) {
console.log(error.response.status);
console.log(error.response.data);
} else {
console.log(error.message);
}
}
}
a();