v3 to v4 Migration Guide #217
Replies: 22 comments 57 replies
|
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". |
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 |
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. |
|
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? |
|
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. |
// 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) |
|
@rattrayalex btw, thanks for the clear docs and rewrite, appreciate it |
Fantastic... Working here... But, I can still retrieve the data from model How am I able to try out |
|
I have two questions:
|
|
How can I convert |
|
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? |
|
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----> |
|
how to get usage from new stream completions? |
|
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) |
|
"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) |
|
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: |







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.jsonto specify v4:and run
npm installor 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 migrateThe 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 --patchafterwards. 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.createcancelFineTune->fineTunes.cancelretrieveFineTune->fineTunes.retrievelistFineTunes->fineTunes.listlistFineTuneEvents->fineTunes.listEventscreateFile->files.createdeleteFile->files.delretrieveFile->files.retrievedownloadFile->files.retrieveContentlistFiles->files.listdeleteModel->models.dellistModels->models.listretrieveModel->models.retrievecreateImage->images.generatecreateImageEdit->images.editcreateImageVariation->images.createVariationcreateChatCompletion->chat.completions.createcreateCompletion->completions.createcreateTranscription->audio.transcriptions.createcreateTranslation->audio.translations.createcreateEdit->edits.createcreateEmbedding->embeddings.createcreateModeration->moderations.createRemoved:
createAnswer()createClassification()createSearch()listEngines()retrieveEngine()All reactions