July 30th, 2024

Support for Azure.AI.OpenAI and OpenAI v2 is coming

Mark Wallace
Principal Engineering Manager

Microsoft announced the official OpenAI library for .NET at the Build 2024 conference. This new SDK ensures that .NET developers have parity with other programming language libraries when accessing Azure OpenAI models. This means the new SDK will be able to support the latest OpenAI features and models as soon as they come out, such as GPT4o and Assistants v2, by providing a unified experience across OpenAI and Azure OpenAI.

Since the release of the official OpenAI library for .NET, the Semantic Kernel team has been working on updating our existing OpenAI connectors to use the new V2 OpenAI library and Azure.AI.OpenAI library. This is a significant update to Semantic Kernel. Once complete, it will enable developers to upgrade their projects to the v2 libraries from OpenAI and Azure OpenAI.

Update

We have published the Semantic Kernel v1.18.0-rc release candidate including these changes and it is available to down and use now. Read the full announcement Support for Azure.AI.OpenAI and OpenAI v2 is here | Semantic Kernel (microsoft.com). We have also published a OpenAI Connector Migration Guide | Microsoft Learn to guide you through the upgrade process.

What to expect when you upgrade

Since the new .NET Azure.AI.OpenAI SDK has done a major version upgrade from v1 to v2, there have been significant updates to the underlying APIs. For developers that use this SDK directly, there are several breaking changes that must be accounted for. The good news for Semantic Kernel developers though is that our abstractions isolate your code from the vast majority of these changes. There are, however, a few unavoidable breaking changes to be aware of that are a result of the upgrade, but these changes primarily impact more advanced use cases.

The one required change…

The one change that most Semantic Kernel customers will need to make is updating the name of the library you import. Because there are now two libraries that connect to OpenAI models (Azure.AI.OpenAI and the official OpenAI library), we chose to update the name of Semantic Kernel’s connectors to better reflect those differences. There are now two different connector libraries: Microsoft.SemanticKernel.Connectors.OpenAI and Microsoft.SemanticKernel.Connectors.AzureOpenAI. If you used the  Microsoft.SemanticKernel.Connectors.OpenAI library to connect to Azure OpenAI, you’ll want to update it to the Microsoft.SemanticKernel.Connectors.AzureOpenAI library. Additional details about the decisions related to naming and structure are documented here.

Changes that impact advanced scenarios

If you are using more advanced scenarios that require direct usage of the APIs in the Azure.AI.OpenAI SDK, you’ll need to be aware of the following changes that Azure introduced when they moved to v2:

  • The OpenAIClient type previously was a Azure specific namespace type but now it is an OpenAI SDK namespace type, you will need to update your code to use the new OpenAIClient type.
  • When using Azure, you will need to update your code to use the new AzureOpenAIClient type.
  • With the new AzureOpenAIClient, you can now specify your datasource thru the options and that requires a small change in your code to the new type.

Also note that the following features have been deprecated in the new v2 Azure.AI.OpenAI SDK:

  • The TextGeneration modality was deprecated in the latest version of the OpenAI Connector. You will need to update your code to use ChatCompletion modality instead. Keep in mind that the ChatCompletion services also implement the TextGeneration interface and that may not require any changes to your code if you were targetting the ITextGenerationService interface.
  • The lastest OpenAI SDK does not support multiple choices anymore. The option for multiple results was removed also from the OpenAIPromptExecutionSettings. So any implementation that was relying on multiple choices will need to be updated.
  • The OpenAIFileService was deprecated in the latest version of the OpenAI Connector. We strongly recommend to update your code to use the new OpenAIClient.GetFileClient() for file management operations.

We’ll be there every step of the way!

Uptalking a major update can be challenging, but we in the Semantic Kernel team want to make it as painless as possible. As we get closer to adopting the new v2 libraries, we will provide a detailed migration guide to help you with the process of upgrading your code. In the feature branch where we’re updating the connectors, we’ve already made the required changes to our samples (see microsoft/semantic-kernel at feature-connectors-openai).

In most cases, the updates just required adding a new using statement for the Microsoft.SemanticKernel.Connectors.AzureOpenAI library, which shows the value of having an abstraction layer like Semantic Kernel between you and the underlying SDKs.

 

 

Author

Mark Wallace
Principal Engineering Manager

Semantic Kernel, Integrate cutting-edge LLM technology quickly and easily into your apps

0 comments

Discussion are closed.