OpenAI 1.0.0

Additional Details

OpenAI SDK package versions prior to v1.3 will not work with the current OpenAI API due to breaking changes with the OpenAI API.  Please update to at least v1.3 of the SDK to restore functionality.

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenAI --version 1.0.0
NuGet\Install-Package OpenAI -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenAI" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenAI --version 1.0.0
#r "nuget: OpenAI, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenAI as a Cake Addin
#addin nuget:?package=OpenAI&version=1.0.0

// Install OpenAI as a Cake Tool
#tool nuget:?package=OpenAI&version=1.0.0

C#/.NET SDK for accessing the OpenAI GPT-3 API

A simple C# .NET wrapper library to use with OpenAI's GPT-3 API.

Requirements

This library is based on .NET Standard 2.0, so it should work across .NET Framework >=4.7.2 and .NET Core >= 3.0. It should work across console apps, winforms, wpf, asp.net, etc (although I have not yet testing with asp.net). It should work across Windows, Liux, and Mac, although I have only tested on Windows so far.

Getting started

Install from NuGet

(Coming soon)

Authentication

There are 3 ways to provide your API keys, in order of precedence:

  1. Pass keys directly to APIAuthentication(string key) constructor
  2. Set environment vars for OPENAI_KEY and/or OPENAI_SECRET_KEY
  3. Include a config file in the local directory or in your user directory named .openai and containing one of both lines:
OPENAI_KEY=pk-aaaabbbbbccccddddd
OPENAI_SECRET_KEY=sk-aaaabbbbbccccddddd

Completions

The Completion API is accessed via OpenAIAPI.Completions:

Non-streaming

CreateCompletionAsync(CompletionRequest request)

Streaming

Using the new C# 8.0 async interators: IAsyncEnumerable<CompletionResult> StreamCompletionEnumerableAsync(CompletionRequest request)

Or if using .NET framework or C# <8.0: StreamCompletionAsync(CompletionRequest request, Action<int, CompletionResult> resultHandler)

The Search API is accessed via OpenAIAPI.Search:

You can get all results as a dictionary using GetSearchResultsAsync(SearchRequest request)

You can get only the best match using GetBestMatchAsync(...)

nd if you only want the best match but still want to know the score, use GetBestMatchWithScoreAsync(...)

Documentation

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. Better documentation may come later.

Examples

var api = new OpenAI_API.OpenAIAPI(engine: Engine.Davinci);

var result = await api.Completions.CreateCompletionAsync("One Two Three Four Five Six Seven Eight Nine One Two Three Four Five Six Seven Eight", temperature: 0.1);
Console.WriteLine(result.ToString());
// should print "Nine"
var api = new OpenAI_API.OpenAIAPI(engine: Engine.Curie);

var result = await api.Search.GetBestMatchAsync("Washington DC", "Canada", "China", "USA", "Spain");
Console.WriteLine(result);
// should print "USA"
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (23)

Showing the top 5 NuGet packages that depend on OpenAI:

Package Downloads
AuthScape.OpenAI

Package Description

AuthScape.Document.Mapping

Package Description

VL.OpenAISimple

VL/vvvv gamma nodeset wrapping the https://github.com/betalgo/openai library, enabling access to OpenAI APIs from vvvv gamma

Absurd.Umbraco.OpenAI

OpenAI Content App for Umbraco 11

VL.OpenAI

talk to the OpenAI API

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on OpenAI:

Repository Stars
VladislavAntonyuk/MauiSamples
.NET MAUI Samples
ks233/ja-learner
📖简易日语学习 / 视觉小说阅读辅助工具
lastbattle/Harepacker-resurrected
All in one .wz file/map editor for MapleStory game files
jeffdapaz/VisualChatGPTStudio
Add chatGPT functionalities directly on Visual Studio
rcarneironet/valhalla-hexagonal-architecture
Hexagonal architecture showcase
Version Downloads Last updated
1.11.0 6,004 3/13/2024
1.10.0 88,756 12/14/2023
1.9.0 5,402 12/12/2023
1.8.0 6,141 12/6/2023
1.7.2 447,602 4/2/2023
1.7.1 1,222 4/2/2023
1.7.0 974 4/2/2023
1.6.0 49,345 3/9/2023
1.5.0 20,426 2/16/2023
1.4.0 10,880 2/3/2023
1.3.0 12,494 1/12/2023
1.2.0 37,730 12/22/2020
1.1.0 1,622 7/28/2020
1.0.0 2,023 7/23/2020

Initial release of SDK.  An OpenAI API account is required (still in closed beta)