#Switching from text-davinci-003 to gpt-3.5-turbo

31 messages · Page 1 of 1 (latest)

timber rampart
#

Hello! I'm trying to update my JS code to use the newest ChatGPT API that was released.

The previous code was the following:

async function openai_reply(message) {
    const completion = await openai.createCompletion({
        model: "text-davinci-003",
        prompt: message,
        temperature: 0.7,
        max_tokens: 256,
        top_p: 1,
        frequency_penalty: 0.0,
        presence_penalty: 0.0    
    });
  return completion.data.choices[0].text;
}

I tried then, based on this documentation page (https://platform.openai.com/docs/guides/chat), to update my code accordingly to the following:

async function openai_reply(message) {
    const completion = await openai.createCompletion({
        model: "gpt-3.5-turbo",
        messages: [
          {
            "role": "system",
            "content": "You are an assistant called Peedy"
          },
          {
            "role": "user",
            "content": message
          }
        ]
        
    });
  return completion.data.choices[0].text;
}

But i'm getting error 400 with the last function.

What i'm doing wrong?

sleek crescent
timber rampart
# sleek crescent What's the error that you're getting/ There should be an error message that's re...

When i try to invoke the openai_reply funcion..

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: Request failed with status code 400
    at createError (path\to\script\node_modules\axios\lib\core\createError.js:16:15)
    at settle (path\to\script\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (path\to\script\node_modules\axios\lib\adapters\http.js:322:11)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:394:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {

And it start to output a huge JSON that i dont know if is safe to share here...

sleek crescent
#

This is a nodejs error

#

I want to see the error that the API returns

#

the API will return an error code (400 in your case) and then also a message along with it to say what went wrong

#

Find a message field somewhere in the huge json and it should tell you what's wrong

sleek crescent
#

you're using the old function

timber rampart
#
    data: {
      error: {
        message: 'Unrecognized request argument supplied: messages',
        type: 'invalid_request_error',
        param: null,
        code: null
      }
    }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
``` this?
sleek crescent
#

I don't think you can use createCompletion for the chat completions

sleek crescent
#

this confirms that you're using an invalid method

#

You need to find the method for chat completions in that library that you're using

#

it should be named something else, not createCompletion, that's for the older models like text-davinci-003

#

the library should've updated itself with a new method

timber rampart
sleek crescent
#

yeah

timber rampart
#

just update to 3.2.0

#

oops

#

already 3.2.1

#

let me update

sleek crescent
#

yeah but you need to find the correct function

#

it's not createCompletion

timber rampart
#
const { Configuration, OpenAIApi } = require("openai");

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

const completion = await openai.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [{role: "user", content: "Hello world"}],
});
console.log(completion.data.choices[0].message);
#

seems to have been changed to createChatCompletion

#

Following the example fixed the issue

#

thanks a lot

#

can you close the topic? Dont know how to do it on discord

sleek crescent
#

No worries! We'll leave it open for others to see