ยท hands on
Module openai has no exported member
OpenAI's Node.js API Library has updated from Version 3 to Version 4. Changes include updating imports adjusting method calls.
There has been a major upgrade in OpenAI's Node.js API Library. When switchting from Version 3 to Version 4 you have to take into account some breaking API changes. You may also run into "insufficient_quota" errors if you don't upgrade legacy User API keys to to Project API keys (read more).
API Changes
Here is a list of the most common changes and how to update them.
Module '"openai"' has no exported member 'Configuration'. Did you mean to use 'import Configuration from "openai"' instead?
Version 3
import { Configuration } from 'openai';
After
import OpenAI from 'openai';
'"openai"' has no exported member named 'OpenAIApi'. Did you mean 'OpenAI'?
Version 3
import { Configuration, OpenAIApi } from 'openai';
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
After
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
Module '"openai"' has no exported member 'ChatCompletionRequestMessage'. Did you mean to use 'import ChatCompletionRequestMessage from "openai"' instead?
Version 3
const commands: ChatCompletionRequestMessage[] = [
{
content: 'You are a summarizer.',
role: 'system',
},
];
After
import type { ChatCompletionMessageParam } from 'openai/resources/index.mjs';
const commands: ChatCompletionRequestMessage[] = [
{
content: 'You are a summarizer.',
role: 'system',
},
];
Property 'createChatCompletion' does not exist on type 'OpenAI'.
Version 3
const { data } = await openai.createChatCompletion({
max_tokens: 196,
messages: commands,
model: 'gpt-3.5-turbo',
temperature: 0,
top_p: 0.1,
});
After
const data = await openai.chat.completions.create({
max_tokens: 196,
messages: commands,
model: 'gpt-3.5-turbo',
temperature: 0,
top_p: 0.1,
});