v3 to v4 Migration Guide #217
Replies: 22 comments 57 replies
-
It would be great if you could also update it in the playground. |
Beta Was this translation helpful? Give feedback.
-
It would be great if an example could be added for Image generation. Though there is a guide at the bottom that lists the new functions. Some interfaces aren't listed, such as: "CreateImageRequestSizeEnum". |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
Thanks for this. A banner with a note on the release of v4.0.0 out of beta at the top of https://platform.openai.com/docs/api-reference would go a long way |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
https://chat.openai.com/share/b175130a-0d77-465e-8187-59b92590df8b I put the main migration text body in a ChatGPT-4 chat for querying, handy to run issues past for a quick check. |
Beta Was this translation helpful? Give feedback.
-
Any information on using this SDK with the Azure OpenAI service? How do we set api_type, api_base, and api_version in the 4.0 SDK? |
Beta Was this translation helpful? Give feedback.
-
Hey -- really awesome to see this migration, we have to update a few things on our side but the streaming functionality is welcome. Please provide a migration guide for functions. |
Beta Was this translation helpful? Give feedback.
-
// New
const chatCompletion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{"role": "user", "content": "Hello!"}],
});
console.log(chatCompletion.choices[0].message); This new snippet brought me the following error messages: Property 'choices' does not exist on type 'Stream<ChatCompletionChunk> | ChatCompletion'.
Property 'choices' does not exist on type 'Stream<ChatCompletionChunk>'.ts(2339) |
Beta Was this translation helpful? Give feedback.
-
@rattrayalex btw, thanks for the clear docs and rewrite, appreciate it |
Beta Was this translation helpful? Give feedback.
-
Fantastic... Working here... But, I can still retrieve the data from model How am I able to try out |
Beta Was this translation helpful? Give feedback.
-
I have two questions:
|
Beta Was this translation helpful? Give feedback.
-
How can I convert
|
Beta Was this translation helpful? Give feedback.
-
I have been trying to create an Express API endpoint that returns a response from the Open AI package in streaming format to be consumed by React on the front end. But all the resources are deprecated. Any help on how do I create such an endpoint? |
Beta Was this translation helpful? Give feedback.
-
Hey, I was doing the manual migration same as the above code snippet, I am in the version "^4.2.0" now and am getting this error----> |
Beta Was this translation helpful? Give feedback.
-
Can anyone please help me out to how to remove this errors |
Beta Was this translation helpful? Give feedback.
-
how to get usage from new stream completions? |
Beta Was this translation helpful? Give feedback.
-
import OpenAI from "openai"; // Updated import for OpenAI const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); // Initialize OpenAI API export async function POST(req: Request) {
} catch (error) { Cannot find name 'configuration'.ts(2304) |
Beta Was this translation helpful? Give feedback.
-
"use client"; import axios from "axios"; import {Heading} from "@/components/heading"; import { formSchema } from "./constants"; import { Input } from "@/components/ui/input"; const ConversationPage = () => {
export default ConversationPage; Cannot find name 'ChatCompletionRequestMessage'.ts(2304) |
Beta Was this translation helpful? Give feedback.
-
dalleRoutes.js (to fetch images from openapi) import express from 'express'; import Post from '../mongodb/models/post.js'; dotenv.config(); const router = express.Router(); const openai = new OpenAI({ router.route('/').get((req, res) => { router.route('/').post(async (req, res) => {
}) export default router; postRoutes.js (to post on homepage) import express from 'express'; import Post from '../mongodb/models/post.js'; dotenv.config(); const router = express.Router(); cloudinary.config({ //GET ALL POSTS
}); //CREATE A POST
}); export default router; I'm getting this error: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
v4 is a complete rewrite of the SDK. To see what's new, see the release notes.
Installation
First, update your
package.json
to specify v4:and run
npm install
or equivalent to download the new version.Automatic migration
You can automatically migrate your codebase using grit, either online or with the following CLI command:
npm exec openai migrate
The grit binary executes entirely locally with AST-based transforms.
Be sure to audit its changes: we suggest ensuring you have a clean working tree beforehand, and running
git add --patch
afterwards. Note that grit.io also offers opt-in automatic fixes powered by AI.Manual migration
There are changes in the initialization logic, method names, error handling. The API parameter names should be unchanged.
Initialization
Creating a chat completion
Creating a streaming chat completion (new)
Creating a completion
Creating a transcription (whisper)
Creating a streaming completion (new)
Error handling
Headers
All method name changes
To migrate these automatically, see Automatic migration, above
createFineTune
->fineTunes.create
cancelFineTune
->fineTunes.cancel
retrieveFineTune
->fineTunes.retrieve
listFineTunes
->fineTunes.list
listFineTuneEvents
->fineTunes.listEvents
createFile
->files.create
deleteFile
->files.del
retrieveFile
->files.retrieve
downloadFile
->files.retrieveContent
listFiles
->files.list
deleteModel
->models.del
listModels
->models.list
retrieveModel
->models.retrieve
createImage
->images.generate
createImageEdit
->images.edit
createImageVariation
->images.createVariation
createChatCompletion
->chat.completions.create
createCompletion
->completions.create
createTranscription
->audio.transcriptions.create
createTranslation
->audio.translations.create
createEdit
->edits.create
createEmbedding
->embeddings.create
createModeration
->moderations.create
Removed:
createAnswer()
createClassification()
createSearch()
listEngines()
retrieveEngine()
Beta Was this translation helpful? Give feedback.
All reactions