Open darinkishore opened 9 months ago
git clone
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Modify your requirements.txt or Pipfile to specify the new version: openai>=1.0
pip install -U -r requirements.txt
openai migrate
python -m unittest discover tests
Prepare a rollback plan in case any critical issues are discovered after deploying the updated code with openai v1.0. Should be done smoothly :)
We need to migrate from openai v 0.28 to >=1.0.
This is a pretty big upgrade. To ensure it goes smoothly, we must test all usages of the openai library, without using the actual syntax used currently, if that makes sense. Tests should pass on v 0.28 AND v1.0, so we know we have a successful upgrade.
V1.0 Change Documentation:
pip install --upgrade openai
openai migrate
Then, you can close WSL and go back to using Windows.
Automatic migration with grit in Jupyter Notebooks
If your Jupyter notebooks are not in source control, they will be more difficult to migrate. You may want to copy each cell into grit's web interface, and paste the output back in.
If you need to migrate in a way that preserves use of the module-level client instead of instantiated clients, you can use the openai_global grit migration instead.
Initialization
Responses
Response objects are now pydantic models and no longer conform to the dictionary shape. However you can easily convert them to a dictionary with
model.model_dump()
.Async client
We do not support calling asynchronous methods in the module-level client, instead you will have to instantiate an async client.
The rest of the API is exactly the same as the synchronous client.
Module client
Important
We highly recommend instantiating client instances instead of relying on the global client. We also expose a global client instance that is accessible in a similar fashion to versions prior to v1.
The API is the exact same as the standard client instance based API.
This is intended to be used within REPLs or notebooks for faster iteration, not in application code.
We recommend that you always instantiate a client (e.g., with
client = OpenAI()
) in application code because:Pagination
All
list()
methods that support pagination in the API now support automatic iteration, for example:Previously you would have to explicitly call a
.auto_paging_iter()
method instead. See the README for more details.Azure OpenAI
To use this library with Azure OpenAI, use the
AzureOpenAI
class instead of theOpenAI
class.
A more comprehensive Azure-specific migration guide is available on the Microsoft website.
Important
The Azure API shape differs from the core API shape which means that the static types for responses / params won't always be correct.
In addition to the options provided in the base
OpenAI
client, the following options are provided:azure_endpoint
azure_deployment
api_version
azure_ad_token
azure_ad_token_provider
An example of using the client with Azure Active Directory can be found here.
All name changes
Note: all
a*
methods have been removed; the async client must be used instead.openai.api_base
->openai.base_url
openai.proxy
->openai.proxies
(docs)openai.InvalidRequestError
->openai.BadRequestError
openai.Audio.transcribe()
->client.audio.transcriptions.create()
openai.Audio.translate()
->client.audio.translations.create()
openai.ChatCompletion.create()
->client.chat.completions.create()
openai.Completion.create()
->client.completions.create()
openai.Edit.create()
->client.edits.create()
openai.Embedding.create()
->client.embeddings.create()
openai.File.create()
->client.files.create()
openai.File.list()
->client.files.list()
openai.File.retrieve()
->client.files.retrieve()
openai.File.download()
->client.files.retrieve_content()
openai.FineTune.cancel()
->client.fine_tunes.cancel()
openai.FineTune.list()
->client.fine_tunes.list()
openai.FineTune.list_events()
->client.fine_tunes.list_events()
openai.FineTune.stream_events()
->client.fine_tunes.list_events(stream=True)
openai.FineTune.retrieve()
->client.fine_tunes.retrieve()
openai.FineTune.delete()
->client.fine_tunes.delete()
openai.FineTune.create()
->client.fine_tunes.create()
openai.FineTuningJob.create()
->client.fine_tuning.jobs.create()
openai.FineTuningJob.cancel()
->client.fine_tuning.jobs.cancel()
openai.FineTuningJob.delete()
->client.fine_tuning.jobs.create()
openai.FineTuningJob.retrieve()
->client.fine_tuning.jobs.retrieve()
openai.FineTuningJob.list()
->client.fine_tuning.jobs.list()
openai.FineTuningJob.list_events()
->client.fine_tuning.jobs.list_events()
openai.Image.create()
->client.images.generate()
openai.Image.create_variation()
->client.images.create_variation()
openai.Image.create_edit()
->client.images.edit()
openai.Model.list()
->client.models.list()
openai.Model.delete()
->client.models.delete()
openai.Model.retrieve()
->client.models.retrieve()
openai.Moderation.create()
->client.moderations.create()
openai.api_resources
->openai.resources
Removed
openai.api_key_path
openai.app_info
openai.debug
openai.log
openai.OpenAIError
openai.Audio.transcribe_raw()
openai.Audio.translate_raw()
openai.ErrorObject
openai.Customer
openai.api_version
openai.verify_ssl_certs
openai.api_type
openai.enable_telemetry
openai.ca_bundle_path
openai.requestssession
(we now use httpx)openai.aiosession
(we now use httpx)openai.Deployment
(only used for Azure)openai.Engine
openai.File.find_matching_files()
openai.embeddings_utils
(now in the cookbook)Please plan out the tests. Be careful, meticulous, and thorough.