3👍
✅
You haven’t broken the API endpoint, but you are using the Codex endpoint which is designed for Code completions. Only use this endpoint to generate code.
For general purpose Natural Language Processing you need to use the OpenAI completions endpoint:
https://api.openai.com/v1/completions
The other change you will need to make is in the body where you need to add the model
property:
model: 'text-davinci-003'
I rewrote your code:
const response = await fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
},
body: JSON.stringify({
prompt: `Hey, how are you?`,
model: 'text-davinci-003',
max_tokens: 2048,
n: 1,
temperature: 0.7
})
});
console.log(response)
const data = await response.json();
console.log(data)
const generatedText = data.choices[0].text.trim();
console.log(generatedText)
I recieved the following response from GPT3:
I'm doing well, thank you. How about you?
Source:stackexchange.com