openai / openai-node

The official Node.js / Typescript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.64k stars 819 forks source link

3.2.0 does not work with newest models #67

Closed d-e-h-i-o closed 1 year ago

d-e-h-i-o commented 1 year ago

Describe the bug

I just upgraded to 3.2.0, but the API throws an error for me when being used with the newest models.

To Reproduce

import { Configuration, OpenAIApi }  from  "openai";

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const completion = await openai.createCompletion({
  model: "gpt-3.5-turbo",
  prompt: "Hello world",
});
console.log(completion.data.choices[0].text);

Code snippets

This is (part) of the error message I receive:

data: {
      error: {
        message: 'Invalid URL (POST /v1/completions)',
        type: 'invalid_request_error',
        param: null,
        code: null
      }
    }


### OS

macOS

### Node version

Node.js v19.4.0

### Library version

openai v3.2.0
Syntoxr commented 1 year ago

You have to use createChatCompletion instead and use messages instead of prompt:

await this.openai
    .createChatCompletion({
        model: 'gpt-3.5-turbo',
        user: interaction.user.id,
        messages: [
            { role: 'system', content: 'You are a helpful assistant. Keep your answer short.' },
            { role: 'user', content: `${input}` }
        ]
    })
d-e-h-i-o commented 1 year ago

Ah, thank you. You're right!