OpenAI Library For .NET Exits Beta
Written by Nikos Vaggalis   
Tuesday, 19 November 2024

A few months ago the OpenAI .NET library was released as a beta. It has now reached version 2.0.0 and the time has come to leave beta and, with a few amendments enter production readiness.

OpenAI2 banner 

As a refresher, the library provides convenient access to the OpenAI REST API from .NET applications so that developers can build AI driven applications. That access breaks down to :

  • 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>
  • .NET Standard 2.0 compatibility: written in C#, supports all .NET variants that implement .NET Standard 2.0, ensuring compatibility with the latest .NET platforms.

You can very easily add it to your project through NuGet:

dotnet add package OpenAI 

With that in place and after obtaining an API key, you can enrich you application with the following functionalities:

  • chat completions with streaming
  • chat completions with tools and function calling
  • chat completions with structured outputs
  • generate text embeddings
  • generate images
  • transcribe audio
  • use assistants with retrieval augmented generation (RAG)
  • use assistants with streaming and vision

To put it into practice, here's a sample that summons various clients; embedding, image and audio.

The new version 2.0.0 implements a few breaking changes:

  • Renamed `OpenAIClientOptions`'s `ApplicationId` to `UserAgentApplicationId` (commit_hash)
  • Replaced the deprecated `ChatFunctionChoice(ChatFunction)` constructor with `CreateNamedChoice(string functionName)`
  • Renamed `FileClient` to `OpenAIFileClient` and the corresponding `GetFileClient()` method in `OpenAIClient` to `GetOpenAIFileClient()`
  • Renamed `ModelClient` to `OpenAIModelClient` and the corresponding `GetModelClient()` method in `OpenAIClient` to `GetOpenAIModelClient()`

So if you've been using the beta and want to upgrade, take those into consideration.

opena1new

 

There's also another Microsoft AI SDK, that of Semantic Kernel which serves a similar purpose in accessing LLMs from your code. The main difference is that with Semantic you get access to multiple models, and not just OpenAI’s, plus you can choose between the C#, Java, Python and Javascript versions. Explore both options to see which fits your needs.

More Information

OpenAI .NET

Related Articles

Microsoft Introduces Unified .NET API For AI

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Edera Releases Open Source Container Benchmark And Scanner
07/11/2024

Edera has released Am I Isolated, an open source container security benchmark that probes users runtime environments and tests for container isolation.



Flutter Forked As Flock
05/11/2024

One of developers who worked on the Flutter team at Google has created an open-source form of the framework. Matt Carroll says Flock will be "Flutter+", will remain constantly up to date with Flutter, [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Tuesday, 19 November 2024 )