Announcing the official OpenAI library for .NET
At Microsoft Build 2024, we announced new investments that expand the AI ecosystem for .NET developers. We’re excited to share more detailed plans around Microsoft’s collaboration with OpenAI on their official .NET library.
Today, the OpenAI team released their first beta, version 2.0.0-beta.1, of the official OpenAI library for .NET. Features include:
- Support for the entire OpenAI API, including Assistants v2 and Chat Completions
- Support for GPT-4o, OpenAI’s latest flagship model
- Extensibility to enable the community to build libraries on top
- Sync and async APIs for ease of use and efficiency
- Access to streaming completions via
IAsyncEnumerable<T>
This official .NET library ensures a smooth and supported integration with OpenAI and Azure OpenAI. It also complements OpenAI’s official libraries for Python and TypeScript/JavaScript developers.
The .NET library is developed and supported on GitHub and will be kept up to date with the latest features from OpenAI. Work will continue over the next few months to gather feedback to improve the library and release a stable NuGet package.
Thank you to the .NET community
We’d like to thank and recognize the work of Roger Pincombe on his library that was published under the OpenAI v1.x NuGet package name. Roger initially published the library in June 2020, making it the first known OpenAI package for .NET. He volunteered countless hours of personal time ever since to maintain the project on GitHub. Roger has worked closely with OpenAI and Microsoft on our plans for the official .NET package for OpenAI. Roger is also helping with a migration guide from his package to the new official one.
Of course, developers may choose to continue using their favorite community libraries, like:
OpenAI and the .NET team also thank these project maintainers for their extraordinary efforts in filling a void within the community. Even with the release of the official package from OpenAI, there are opportunities for community libraries to add significant value on top. We look forward to collaborating with the community in this space.
Next steps
Here’s how you can get involved:
- Try the library: Install the OpenAI .NET library and start experimenting with its features.
- Join the community: Engage with us and other developers on GitHub. Share your experiences, report issues, and contribute to discussions.
- Attend the live stream: Join us live at 10:00 AM PDT on June 19 for the .NET AI Community Standup. Ask questions, learn more about the library, and see demos of its capabilities.
16 comments
What does this mean for the
Azure.AI.OpenAI
package?Hello, Thomas! That’s a great question. We’ve worked closely with OpenAI for overall .NET convergence and that existing
Azure.AI.OpenAI
package is being converted into the Azure OpenAI Service “companion library” that will provide a dedicatedAzureOpenAIClient
for connecting to Azure OpenAI resources, together with extensions for Azure-specific concepts like Responsible AI content filter results and On Your Data integration. All of the common capabilities between OpenAI and Azure OpenAI will share the same scenario clients, methods, and request/response types, so interoperating between Azure and non-Azure should be easier than ever.We’re hoping to have that update published very soon (I’m waiting on a build right now!) and you can keep an eye on the Azure.AI.OpenAI readme and NuGet package.
Noting here as we’ll note in the repository: this will bring some very significant changes to the details of the usage patterns and we’re eager to hear your feedback. Discussions are open on the openai-dotnet repository and we’ll also be regularly percolating all of the 2.0.0-beta input on azure-sdk-for-net repository, too. Our goal is to stabilize the preview and produce GA-status libraries as soon as we can, and that means great input from the community is critical to ensuring this .NET support is as awesome as it deserves to be.
Here’s the updated Azure.AI.OpenAI package Travis mentioned: https://www.nuget.org/packages/Azure.AI.OpenAI/2.0.0-beta.1
Thank you for the detailed answer. So, to make sure I understand the split here. Previously, we would use an
OpenAIClient
to communicate with both ChatGPT from OpenAI and Azure OpenAI Service. With different endpoints and settings, of course. But going forward, we will useAzureOpenAIClient
from theAzure.AI.OpenAI
package to communicate with Azure OpenAI Service andOpenAIAPI
from theOpenAI
package to communicate with OpenAI?OpenAIAPI
is from the predecessorv1.
OpenAI library prior to the package name being graciously transferred; please be sure you’re usingv2.0.0-
for the official library!The OpenAI library has
OpenAIClient
; theAzure.AI.OpenAI
package addsAzureOpenAIClient
, which derives fromOpenAIClient
and specifically configures things for Azure OpenAI. With either, you then instantiate scenario clients from the factory-like top-level client, e.g.client.GetChatClient("gpt-4o")
. From there, theChatClient
(or other scenario client instance) is used the same way whether you’re targeting OpenAI’s v1 endpoint or an Azure OpenAI Service resource endpoint.Makes sense. Thanks!
A quick update on this for anyone interested in making the switch. I migrated my code to the new prerelease of the
Azure.AI.OpenAI
package. Everything is running great. As already mentioned in this thread, you useAzureOpenAIClient
when communicating with a model hosted on Azure andOpenAIClient
when communicating with a model on OpenAI. One thing you should be aware of is that the new clients now throwClientResultException
instead ofRequestFailedException
. So, if you catch an exception to detect an invalid API key or similar, you need to change the catch block.Does this include support for the latest GPT-4o features? audio stream in & out as well as image & video recognition?
Hey Jose Luis!
Yes they do! the main repo have great samples (https://github.com/openai/openai-dotnet), and we talked about that also today in the .NET + AI LATAM streaming.
Best
Interesting
How does this affect those using the ML.NET package from Microsoft? Are the two packages related, or does is this package a “next version” of ML.NET?
Hi Jeff,
This has no effect on ML.NET set of packages. The OpenAI library announced in this post and ML.NET are unrelated. However, if there’s any integrations folks would like to see between ML.NET and OpenAI models, feedback is always welcome.
https://github.com/dotnet/machinelearning/issues
Official .NET libraries requiring API keys for third-party services to use?
That’s a new one.
Maybe in 2030 we’ll require the user having a Microsoft account to run a program that has using System; :p
Its OpenAI’s official api, they require a key like a million other services do. Or do you expect them to provide everything unlimited completely free?
It is required in whatever programming platform or language you are using. Lol. You are consuming their pretrained models or services through their endpoints, so you need the OPENAI keys. When consuming AI services on Azure or AWS, you would need their keys also.
But if you want to consume a SLM or MLM locally or on edge (on device), you can use Semantic Kernel library to do that. SK library supports C#, Python and Java – at least for now.
While ML.NET is amazing and you will use it to train small or large datasets to produce models and you can export it to Onnx format to be consumed by others.
For those following along, we discussed and demonstrated the official library on today’s .NET AI Community Standup. View the recording at https://www.youtube.com/watch?v=GUV2p_9QUo8. Special guest Roger Pincombe joined us!