Yes, have done that if you try “openai.” it gives a lot of available functions that you can call from the NPM Openai module but the createChatCompletion is not yet there even though it was used in the official documentation here https://platform.openai.com/docs/api-reference/chat/create?lang=node.js:
Im having the same issue - openai.createChatCompletion is not a function. I’m using Node and just have tried updating the npm openai package but doesnt sem to work, Have you got any further?
@Foskaay I have solved this by doing my own API call - first instal and require axios
npm install axios then you can configure your call to look something like this:
async function callChatGTP() { var data = JSON.stringify({
“model”: “gpt-3.5-turbo”,
“messages”: [
{ role: “system”, content: Your prompt here },
{ role: “assistant”, content: “Hi. How can I help you today?” },
{ role: “user”, content: your userinput here }],
});
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.openai.com/v1/chat/completions',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer YOUR_API_KEY`
''
},
data: data
};
let completion = await axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
));
let data = response.data;
return data
})
.catch(function (error) {
console.log(error, 'error in calling chat completion');
});
@pete1 I tried to use your code above but seems a lot of things is broken, can you send me like a repo link where you have a working sample for check or a screenshot of your expressjs application using the code implementation you sent.
Thanks