DEV Community

Cover image for Upgrade text-davinci-003 to gpt-3.5-turbo

Posted on

Upgrade text-davinci-003 to gpt-3.5-turbo

If you are using OpenAI's GPT-3 language model for your natural language processing tasks, you are likely familiar with the text-davinci-003 model. However, OpenAI recently released a new model called gpt-3.5-turbo, which is even more powerful and cheaper than its predecessor. In this blog post, we will guide you through the process of upgrading from text-davinci-003 to gpt-3.5-turbo in your node.js application.


Step 1: Update the OpenAI package to the latest version(3.2.0).

The first step is to Upgrade the OpenAI package in your node.js environment. You can do this by running the following command in your terminal:

yarn add openai@^3.2.0
Enter fullscreen mode Exit fullscreen mode

Step 2: Update your code

Once you have updated your API key, you need to update your code to use the gpt-3.5-turbo model instead of text-davinci-003. Here is an example of how to do this:

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

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
const openai = new OpenAIApi(configuration);
Enter fullscreen mode Exit fullscreen mode

Everything above remains the same as the openai API configuration.

// text-davinci-003
const completion = await openai.createCompletion({
  model: "text-davinci-003",
  prompt: "Hello world",

// gpt-3.5-turbo
// replace .createCompletion() with .createChatCompletion()
const completion = await openai.createChatCompletion({ 
  model: "gpt-3.5-turbo",
// replace prompt with messages and set prompt as content with a role.
  messages: [{role: "user", content: "Hello world"}], 
Enter fullscreen mode Exit fullscreen mode

In the code above, replace text-davinci-003 with gpt-3.5-turbo to use the new model.

You can also read the official documents here:


An API for accessing new AI models developed by OpenAI


Step 3: Start your application

Finally, start your node.js application to begin using the gpt-3.5-turbo model for your natural language processing tasks. If you are running your application during the process, please make sure to restart your application or it will not take effects!


Upgrading from text-davinci-003 to gpt-3.5-turbo is a simple process that can greatly improve the accuracy and effectiveness of your natural language processing tasks. By following the steps outlined in this blog post, you can easily upgrade your node.js application to use the new model. Happy coding!

Top comments (0)