Location>code7788 >text

Official OpenAI Library for .NET Stable

Popularity:937 ℃/2024-10-20 12:35:37

preamble

Today I'd like to share with you an official OpenAI project designed to provide .NET developers with a convenient interface to OpenAI's REST API, which is distributed as a NuGet package that makes it easy for .NET applications to integrate and utilize OpenAI's various AI models and features, such as text generation, image generation, audio transcription, and more.

Main features of the library

  • namespace organization: The library is organized into namespaces according to the functional areas of the OpenAI REST API, and each namespace contains the corresponding client classes.
  • asynchronous support: All client-side methods provide both synchronous and asynchronous calls, making it easy for developers to choose as needed.
  • Environment variables and configuration files: It is recommended that API keys be managed via environment variables or configuration files for increased security.
  • streaming: Streaming of chat completion results is supported, allowing processing to begin while results are being generated, reducing wait times.
  • Tool Call: Allows integration of external tool calls in chat completion requests, enhancing the functionality and accuracy of the model.
  • Structured Output: Support the use of JSON Schema to constrain the content of the chat completion, making the output more structured and controllable.
  • Support for the latest models: OpenAI's latest flagship models, including GPT-4o, GPT-4o mini, o1-preview, and o1-mini, are fully supported, ensuring developers have access to the most cutting-edge AI capabilities.

namespace organization

 

Install the NuGet package to experience its features

mountingOpenAI The NuGet package allows you to experience both OpenAI's various AI models and features, such as text generation, image generation, audio transcription, and more.

dotnet add package OpenAI

The following is a brief overview of using the OpenAI library in .NET applications. The following code snippet demonstrates how to create an OpenAI client and use it for chat interactions:

using ;

ChatClient client = new(model: "gpt-4o", apiKey: ("OPENAI_API_KEY"));

ChatCompletion completion = ("Say 'this is a test.'");

($"[ASSISTANT]: {[0].Text}");


Project source code address

More useful features and characteristics of the project welcome to the project open source address to view 👀, do not forget to give the project a Star support 💖.

  • Open source address:/openai/openai-dotnet

A selection of great projects and frameworks

This project has been included in the C#/.NET/.NET Core Excellent Projects and Frameworks Selection, focusing on the excellent projects and frameworks selection can let you keep abreast of the latest developments and best practices in the field of C#, .NET and .NET Core, and improve the efficiency and quality of development work. The pit has been dug, you are welcome to submit PR recommendations or self-recommendation (so that excellent projects and frameworks are not buried 🤞).

  • GitHub open source address:/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/
  • Gitee open source address:/ysgdaydayup/DotNetGuide/blob/main/docs/DotNet/