openai / openai-node

Official JavaScript / TypeScript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.93k stars 863 forks source link

404 when making createCompletion #136

Closed f1nality closed 1 year ago

f1nality commented 1 year ago

Describe the bug

Some days ago createCompletion request started to return 404

Error: Request failed with status code 404
  request: {
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'User-Agent': 'OpenAI/NodeJS/3.1.0',
      Authorization: 'Bearer ******',
      'Content-Length': 247
    },
    method: 'post',
    data: '{"model":"code-davinci-002","prompt":"### PostgresSQL tables, with their properties:\\n#\\n# string(string)\\n#\\n###string\\nprettify SELECT","temperature":0,"max_tokens":256,"top_p":1,"n":1,"frequency_penalty":0,"presence_penalty":0,"stop":["#",";"]}',
    url: 'https://api.openai.com/v1/completions'
  },
  response: {
    status: 404,
    statusText: 'Not Found',
    headers: {
      date: 'Thu, 06 Apr 2023 17:06:35 GMT',
      'content-type': 'application/json; charset=utf-8',
      'content-length': '190',
      connection: 'close',
      vary: 'Origin',
      'x-request-id': '622966fb6783fe3d61c1906253b71879',
      'strict-transport-security': 'max-age=15724800; includeSubDomains',
      'cf-cache-status': 'DYNAMIC',
      server: 'cloudflare',
      'cf-ray': '7b3b9f4c4ed730e8-FRA',
      'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'
    },
  },
}

To Reproduce

  1. Run createCompletion

Code snippets

const response = await new OpenAIApi(
        new Configuration({
          apiKey: this.configService.get('OPENAI_API_KEY'),
        }),
      ).createCompletion({
        model: 'code-davinci-002',
        prompt: this.openAiAPIService.convertDTOToPrompt(body),
        temperature: 0,
        max_tokens: this.configService.get('OPENAI_MAX_TOKENS'),
        top_p: 1.0,
        n: 1,
        frequency_penalty: 0.0,
        presence_penalty: 0.0,
        stop: ['#', ';'],
      });


### OS

macOs

### Node version

Node v14.17.4

### Library version

openai v3.1.0
bianbiandashen commented 1 year ago

你这边解决了吗?

f1nality commented 1 year ago

@bianbiandashen, not, haven't found any solutions yet

petervanderh commented 1 year ago

Hi,

The response is saying that model 'code-davinci-002' does not exist anymore. Tried 'code-davinci-003', same issue.

{
    message: 'The model `code-davinci-002` does not exist',
    type: 'invalid_request_error',
}

According to https://platform.openai.com/docs/guides/code it's also deprecated.

f1nality commented 1 year ago

Moving to gpt-3.5-turbo and using createChatCompletion instead of createCompletion solved the issue. It requres to use different input and output format.

ralyodio commented 1 year ago

Moving to gpt-3.5-turbo and using createChatCompletion instead of createCompletion solved the issue. It requres to use different input and output format.

is this documented anywhere??

f1nality commented 1 year ago

This worked for me

      const response = await this.apiApi.createChatCompletion({
        model: 'gpt-3.5-turbo',
        messages: [
          { role: 'user', content: queryToAi },
        ],
        temperature: 0,
        top_p: 1.0,
        n: 1,
        frequency_penalty: 0.0,
        presence_penalty: 0.0,
        stop: ['#', ';'],
      });

      if (response.data.choices.length > 0 && response.data.choices[0].message !== undefined) {
        return response.data.choices[0].message.content);
      }
ralyodio commented 1 year ago

Thanks, this should be documented. the davinci thing in the example is 100x more expensive...and not as good.

Skaiir commented 1 year ago

@ralyodio It is documented. https://platform.openai.com/docs/api-reference/chat