OpenAiNextGeneration is a simple .NET library to use with various OpenAI compatible providers, such
as OpenAI, Azure OpenAI,
and KoboldCpp (
v1.45.2+). Supports features such as function calling in conjunction with streaming, caches its own HttpClient
s.
Supported features compared to OpenAI-API-dotnet:
- Assistants, threads, and messages support.
- Includes new models.
- Parallel function calling.
- Improved memory usage, and function calling in conjunction with streaming.
- Manages its pool of HttpClients.
- Improved credentials passing.
- Supports OpenAI-compatible API providers, such as KoboldCpp.
- Improved Azure OpenAI integration.
- Nullability annotations.
- Calls are guaranteed not to throw, full response is included in the call result. (Fully supported in 3.0+)
- Actively maintained, backed by a company I work for.
Features scheduled for open-sourcing:
- High-level plugin API.
- Approximate token counting for streaming & function calling.
Install the library via NuGet:
Install-Package OpenAiNg
var api = new OpenAiNg.OpenAiApi("YOUR_API_KEY");
var result = await api.Completions.GetCompletion("One Two Three One Two");
Console.WriteLine(result);
// should print something starting with "Three"
Unlike the original library, OpenAiNg supports only .NET Core >= 6.0, if you need .NET Standard 2.0 /.NET Framework support, please use OpenAI-API-DotNet.
Install package OpenAiNg
from Nuget. Here's how via the command line:
Install-Package OpenAiNg
Pass keys directly to ApiAuthentication(string key)
constructor.
You use the APIAuthentication
when you initialize the API as shown:
// for example
var api = new OpenAiApi("YOUR_API_KEY"); // shorthand
// or
var api = new OpenAiApi(new APIAuthentication("YOUR_API_KEY")); // create object manually
You may optionally include an OpenAi Organization if multiple Organizations are under one account.
// for example
var api = new OpenAiApi(new ApiAuthentication("YOUR_API_KEY", "org-yourOrgHere"));
Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to open an issue here if you have any questions.
This library is licensed under MIT license.