Betalgo.OpenAI.GPT3 6.8.0

Suggested Alternatives

Betalgo.OpenAI

Additional Details

PackageId is updated to Betalgo.OpenAI, Please use the new packageId(Betalgo.OpenAI) to get the latest updates.

There is a newer version of this package available.
See the version list below for details.
dotnet add package Betalgo.OpenAI.GPT3 --version 6.8.0
NuGet\Install-Package Betalgo.OpenAI.GPT3 -Version 6.8.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="Betalgo.OpenAI.GPT3" Version="6.8.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Betalgo.OpenAI.GPT3 --version 6.8.0
#r "nuget: Betalgo.OpenAI.GPT3, 6.8.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 Betalgo.OpenAI.GPT3 as a Cake Addin
#addin nuget:?package=Betalgo.OpenAI.GPT3&version=6.8.0

// Install Betalgo.OpenAI.GPT3 as a Cake Tool
#tool nuget:?package=Betalgo.OpenAI.GPT3&version=6.8.0

Dotnet SDK for OpenAI ChatGPT, Whisper, GPT-3 and DALL·E

Betalgo.OpenAI.GPT3

Install-Package Betalgo.OpenAI.GPT3

Dotnet SDK for OpenAI Chat GPT, Whisper, GPT-3 and DALL·E
Unofficial.
GPT-3 doesn't have any official .Net SDK.

Checkout the wiki page:

https://github.com/betalgo/openai/wiki

Features

For changelogs please go to end of the document.

Visit https://openai.com/ to get your API key. Also documentation with more detail is avaliable there.

Sample Usages

The repository contains a sample project named OpenAI.Playground that you can refer to for a better understanding of how the library works. However, please exercise caution while experimenting with it, as some of the test methods may result in unintended consequences such as file deletion or fine tuning.

Your API Key comes from here --> https://platform.openai.com/account/api-keys

Your Organization ID comes from here --> https://platform.openai.com/account/org-settings

Without using dependency injection:

var openAiService = new OpenAIService(new OpenAiOptions()
{
    ApiKey =  Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY")
});

Using dependency injection:

secrets.json:
 "OpenAIServiceOptions": {
    //"ApiKey":"Your api key goes here"
    //,"Organization": "Your Organization Id goes here (optional)"
  },

(How to use user secret ?
Right click your project name in "solution explorer" then click "Manage User Secret", it is a good way to keep your api keys)

Program.cs
serviceCollection.AddOpenAIService();

OR
Use it like below but do NOT put your API key directly to your source code.

Program.cs
serviceCollection.AddOpenAIService(settings => { settings.ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY"); });

After injecting your service you will be able to get it from service provider

var openAiService = serviceProvider.GetRequiredService<IOpenAIService>();

You can set default model(optional):

openAiService.SetDefaultModelId(Models.Davinci);

Chat Gpt Sample

var completionResult = await openAiService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
{
    Messages = new List<ChatMessage>
    {
        ChatMessage.FromSystem("You are a helpful assistant."),
        ChatMessage.FromUser("Who won the world series in 2020?"),
        ChatMessage.FromAssistant("The Los Angeles Dodgers won the World Series in 2020."),
        ChatMessage.FromUser("Where was it played?")
    },
    Model = Models.ChatGpt3_5Turbo,
    MaxTokens = 50//optional
});
if (completionResult.Successful)
{
   Console.WriteLine(completionResult.Choices.First().Message.Content);
}

Completions Sample

var completionResult = await openAiService.Completions.CreateCompletion(new CompletionCreateRequest()
{
    Prompt = "Once upon a time",
    Model = Models.TextDavinciV3
});

if (completionResult.Successful)
{
    Console.WriteLine(completionResult.Choices.FirstOrDefault());
}
else
{
    if (completionResult.Error == null)
    {
        throw new Exception("Unknown Error");
    }
    Console.WriteLine($"{completionResult.Error.Code}: {completionResult.Error.Message}");
}

Completions Stream Sample

var completionResult = openAiService.Completions.CreateCompletionAsStream(new CompletionCreateRequest()
   {
      Prompt = "Once upon a time",
      MaxTokens = 50
   }, Models.Davinci);

   await foreach (var completion in completionResult)
   {
      if (completion.Successful)
      {
         Console.Write(completion.Choices.FirstOrDefault()?.Text);
      }
      else
      {
         if (completion.Error == null)
         {
            throw new Exception("Unknown Error");
         }

         Console.WriteLine($"{completion.Error.Code}: {completion.Error.Message}");
      }
   }
   Console.WriteLine("Complete");

DALL·E Sample

var imageResult = await openAiService.Image.CreateImage(new ImageCreateRequest
{
    Prompt = "Laser cat eyes",
    N = 2,
    Size = StaticValues.ImageStatics.Size.Size256,
    ResponseFormat = StaticValues.ImageStatics.ResponseFormat.Url,
    User = "TestUser"
});


if (imageResult.Successful)
{
    Console.WriteLine(string.Join("\n", imageResult.Results.Select(r => r.Url)));
}

Notes:

Please note that due to time constraints, I was unable to thoroughly test all of the methods or fully document the library. If you encounter any issues, please do not hesitate to report them or submit a pull request - your contributions are always appreciated.

I initially developed this SDK for my personal use and later decided to share it with the community. As I have not maintained any open-source projects before, any assistance or feedback would be greatly appreciated. If you would like to contribute in any way, please feel free to reach out to me with your suggestions.

I will always be using the latest libraries, and future releases will frequently include breaking changes. Please take this into consideration before deciding to use the library. I want to make it clear that I cannot accept any responsibility for any damage caused by using the library. If you feel that this is not suitable for your purposes, you are free to explore alternative libraries or the OpenAI Web-API.

I am incredibly busy. If I forgot your name, please accept my apologies and let me know so I can add it to the list.

Changelog

6.8.0

  • Added .Net Standart Support, Massive thanks to @pdcruze and @ricaun

6.7.3

  • Breaking change: ChatMessage.FromAssistance is now ChatMessage.FromAssistant. Thanks to @Swimburger
  • The Tokenizer method has been extended with cleanUpCREOL. You can use this option to clean up Windows-style line endings. Thanks to @gspentzas1991

6.7.2

  • Removed Microsoft.AspNet.WebApi.Client dependecy
  • The action build device has been updated to ubuntu due to suspicions that the EOL of the vocab.bpe file had been altered in the last few Windows builds.
  • Added support for TextEmbeddingAdaV2 Model.

6.7.1

  • Introduced support for Whisper.
  • Grateful thanks to @shanepowell for contributing RetrieveFileContent.
  • Resolved an issue that was causing problems with the tokenizer. A clean build should hopefully address this.
  • Added support for skip options validation

6.7.0

  • We all beeen waiting for this moment. Please enjoy Chat GPT API
  • Added support for Chat GPT API
  • Fixed Tokenizer Bug, it was not working properly.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 (6)

Showing the top 5 NuGet packages that depend on Betalgo.OpenAI.GPT3:

Package Downloads
BootstrapBlazor.OpenAI.GPT3

Bootstrap UI OpenAI GPT3 components experience

Witrics.AI.Activities

UiPath AI activities for working with ChatGPT

Senparc.Xncf.OpenAI The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

OpenAI 和 ChatGPT 接口

Luga

A Generative AI Agent Management framework for .NET.

YKT.ChatGPT.AI

访问OpenAI ChatGPT模型api的库,OpenAI, ChatGPT

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Betalgo.OpenAI.GPT3:

Repository Stars
weibaohui/blazork8s
manage k8s using c# blazor enhance by chatgpt ,try something new !使用blazor技术开发的内置OpenAI GPT的k8s 管理界面
Version Downloads Last updated
6.8.4 73,249 4/19/2023
6.8.3 64,106 3/28/2023
6.8.1 17,771 3/20/2023
6.8.0 23,575 3/14/2023
6.7.3 9,701 3/10/2023
6.7.2 16,373 3/5/2023
6.7.1 2,745 3/4/2023
6.7.0 4,605 3/2/2023
6.6.8 2,161 2/28/2023
6.6.7 11,698 2/8/2023
6.6.6 8,147 1/19/2023
6.6.5 1,954 1/16/2023
6.6.4 2,861 1/11/2023
6.6.3 2,324 1/5/2023
6.6.2 2,083 1/1/2023
6.6.0 3,400 12/2/2022
6.5.0 618 11/4/2022
6.4.1 445 11/1/2022
6.4.0 635 9/26/2022
6.3.0 499 9/20/2022
6.2.0 631 8/10/2022
6.1.0 633 6/9/2022
6.0.0 746 3/12/2022
0.0.3 412 1/7/2022
0.0.2 507 1/7/2022
0.0.1 436 12/28/2021