v3 to v4 Migration Guide · openai/openai-node · Discussion #217

👆 It’s written for the first release of v4. It may be outdated for the later subversions of v4. For example, when I write this note, I’m using v4.19.0 and there are incomparabilities in the guide. This guide isn’t good for typescript problems too.

<aside> ☝ This note doesn’t re-write the ones already given in the official guide.


👉 Create completion (Legacy) vs new version.


The big impact is that they remove data before every response in the old version.

// old

// new


<aside> ☝ For types, you should dive into the node_modules/openai and search for it!


// v3
import { ChatCompletionResponseMessage } from 'openai';
let message: ChatCompletionResponseMessage;

// v4
import OpenAI from 'openai';
let message: OpenAI.ChatCompletionMessage;

Function calling

<aside> 🚨 An important note for ones who are going to use function calling. They changes the return format!


If you want to use Parallel Function Calling (multiple functions detected are integrated in the repsonse, for the old versions, there is only first one function will be integrated), you have to update openai to v4.

You have to use model gpt-3.5-turbo-0613 (or later) or gpt-4-1106-preview (or later) to use the parallel function calling!

<aside> ⚠️ With the same request, you may obtain different responses for the parallel function calling! Sometimes there is only 1 function, sometimes there are more than 1. So, don’t be supprise!