0

I have just a simple prompt asking the AI how it is doing

async generateArticles() {
      console.log('article')
      const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${this.apiKey}`
        },
        body: JSON.stringify({
          prompt: `Hey, how are you?`,
          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)
    }

But the respones I am getting seem to be parts of the code Open AI is using like:

'positive': [
    'That\'s great!',
    'Nice!',
    'Good!',
    'Alright!',
    'Cool!',
    'Yeah!',
],
'negative': [
    'That\'s too bad',
    'Too bad',
    'I\'m sorry',
],
'current_user': [
    'My name is {}',
    'My name is {}. Nice to meet you',
    'The name\'s {}',
    'The name\'s {}. Pleased to meet you',
],

or stuff like this

# def greet():
#     print("Hey, how are you?")
#     print("I hope you are fine!")
#     print("Bye!")
#
# def say_bye():
#     print("Bye!")
#
# def greet_bye():
#     greet()
#     say_bye()
#
# print("I am not in the function")
# greet_bye()

It is weird, once even something in Russian. So is it broken, or am I missing something that I am getting such weird responses.

Louskac
  • 141
  • 1
  • 1
  • 9
  • I'm not sure what makes you think that's broken. I recommend first perfecting your prompt in the playground (make sure to select the respective codex model), then when you use the API you should get consistent results. – code Feb 28 '23 at 03:09
  • What output response are you hoping for? – code Feb 28 '23 at 03:10
  • Does this answer your question? [OpenAI API error: "Cannot specify both model and engine"](https://stackoverflow.com/questions/75176667/openai-api-error-cannot-specify-both-model-and-engine) – Rok Benko Mar 01 '23 at 16:24

1 Answers1

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?

Kane Hooper
  • 1,531
  • 1
  • 9
  • 21