Betalgo.OpenAI.GPT3 6.6.7

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.6.7
NuGet\Install-Package Betalgo.OpenAI.GPT3 -Version 6.6.7
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.6.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Betalgo.OpenAI.GPT3 --version 6.6.7
#r "nuget: Betalgo.OpenAI.GPT3, 6.6.7"
#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.6.7

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

Dotnet SDK for OpenAI GPT-3 and DALL·E

Betalgo.OpenAI.GPT3

Install-Package Betalgo.OpenAI.GPT3

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

Features

  • ChatGPT (coming soon)
  • Image (DALL·E)
  • Models
  • Completions
  • Edit
  • Mars
  • Embeddings
  • Files
  • Fine-tunes
  • Moderation
  • Rate limit support

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

!! I would strongly suggest to use different account than your main account while you use playground. Test methods could add or delete your files and models !!

The repository includes one sample project already "OpenAI.Playground" You can check playground project to see how I was testing it while I was developing the library. Be careful while playing with it. Some test methods will delete your files or fine tunings.

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(Engines.Davinci);

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 = sdk.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 sdk.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:

I couldn't find enough time to test all the methods or improve the documentation. My main target was to make fine-tuning available. If you hit any issue please report it or pull request always appreciated.

I was building an SDK for myself then I decide to share it, I hope it will be useful for you. I haven't maintained any open source projects before. Any help would be much appreciated. I am open to suggestions If you would like to contribute somehow.

I will be using the latest libraries all the time. Also, next releasing will include breaking changes frequently (as I mentioned before I was building the SDK for myself. Unfortunately I do not have time to plan these changes and support lower version apps). So please be aware of that before starting to use the library.

As you can guess I do not accept any damage caused by use of the library. You are always free to use other libraries or OpenAI Web-API.

Changelog

6.6.7

  • Added Cancellation Token support, thanks to @robertlyson
  • Updated readme file, thanks to @qbm5, @gotmike, @SteveMCarroll

6.6.6

  • CreateCompletionAsStream is now avaliable, big thanks to @qbm5

6.6.5

  • Sad news, we have Breaking Changes.
    • SetDefaultEngineId() replaced by SetDefaultModelId()
    • RetrieveModel(modelId) will not use the default Model anymore. You have to pass modelId as a parameter.
    • I implemented Model overwrite logic.
      • If you pass a modelId as a parameter it will overwrite the Default Model Id and object modelId
      • If you pass your modelId in your object it will overwrite the Default Model Id
      • If you don't pass any modelId it will use Default Model Id
      • If you didn't set a Default Model Id, SDK will throw a null argument exception
        • Parameter Model Id > Object Model Id > Default Model Id
        • If you find this complicated please have a look at the implementation, OpenAI.SDK/Extensions/ModelExtension.cs → ProcessModelId()
  • New Method introduced: GetDefaultModelId();
  • Some name changes about the legacy engine keyword with the new model keyword
  • Started to use the latest Completion endpoint. This expecting to solve finetuning issues. Thanks to @maiemy and other reporters.

6.6.4

  • Bug-fix, ImageEditRequest.Mask now is optional. thanks to @hanialaraj (if you are using edit request without mask your image has to be RGBA, RGB is not allowed)

6.6.3

  • Bug-fix, now we are handling logprops response properly, thanks to @KosmonikOS
  • Code clean-up, thanks to @KosmonikOS

6.6.2

  • Bug-fix,added jsonignore for stop and stopAsList, thanks to @Patapum

6.6.1

  • Breaking change.

    • EmbeddingCreateRequest.Input was a string list type now it is a string type.
      I have introduced InputAsList property instead of Input. You may need to update your code according the change.
      Both Input(string) and InputAsList(string list) avaliable for use
  • Added string and string List support for some of the propertis.

    • CompletionCreateRequest --> Prompt & PromptAsList / Stop & StopAsList
    • CreateModerationRequest --> Input & InputAsList
    • EmbeddingCreateRequest --> Input & InputAsList

6.6.0

  • Added support for new models (davinciv3 & edit models)
  • Added support for Edit endpoint.
  • (Warning: edit endpoint works with only some of the models, I couldn't find documentation about it, please follow the thread for more information: https://community.openai.com/t/is-edit-endpoint-documentation-incorrect/23361 )
  • Some objects were created as class instead of record at last version. I change them to record. This will be breaking changes for some of you.
  • With this version I think we cover all of openai APIs
  • In next version I will be focusing on code cleanup and refactoring.
  • If I don't need to relase bug-fix for this version also I will be updating library with dotnet 7 in next version as I promised.

6.5.0

  • OpenAI made a surprise release yesterday and they have announced DALL·E API. I needed to do other things but I couldn't resist. Because I was rushing, some methods and class names may will change in the next release. Until that day, enjoy your creative AI.
  • This library now fully support all DALL·E features.
  • I tried to complete Edit API too bu unfortunately something was wrong with the documentation, I need to ask some questions in the community forum.

6.4.1

  • Bug-fixes
    • FineTuneCreateRequest suffix json property name changed "Suffix" to "suffix"
    • CompletionCreateRequest user json property name changed "User" to "user" (Thanks to @shaneqld), also now it is a nullable string

6.4.0

  • I have good news and bad news
  • Moderation feature implementation is done. Now we support Moderation.
  • Updated some request and response models to catch up with changes in OpenAI API
  • New version has some breaking changes. Because we are in the fall season I needed to do some cleanup. Sorry for breaking changes but most of them are just renaming. I believe they can be solved before your coffee finish.
  • I am hoping to support Edit Feature in the next version.

6.3.0

  • Thanks to @c-d and @sarilouis for their contributions to this version.
  • Now we support Embedding endpoint. Thanks to @sarilouis
  • Bug fixes and updates for Models
  • Code clean-up

6.2.0

6.1.0

  • Organization id is not a required value anymore, Thanks to @samuelnygaard
  • Removed deprecated Engine Endpoint and replaced it with Models Endpoint. Now Model response has more fields.
  • Regarding OpenAI Engine naming, I had to rename Engine Enum and static fields. They are quite similar but you have to replace them with new ones. Please use Models class instead of Engine class.
  • To support fast engine name changing I have created a new Method, Models.ModelNameBuilder() you may consider using it.
Product Compatible and additional computed target framework versions.
.NET 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. 
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 70,231 4/19/2023
6.8.3 63,129 3/28/2023
6.8.1 17,322 3/20/2023
6.8.0 23,128 3/14/2023
6.7.3 9,459 3/10/2023
6.7.2 15,996 3/5/2023
6.7.1 2,725 3/4/2023
6.7.0 4,589 3/2/2023
6.6.8 2,149 2/28/2023
6.6.7 11,525 2/8/2023
6.6.6 8,120 1/19/2023
6.6.5 1,951 1/16/2023
6.6.4 2,828 1/11/2023
6.6.3 2,318 1/5/2023
6.6.2 2,048 1/1/2023
6.6.0 3,364 12/2/2022
6.5.0 615 11/4/2022
6.4.1 442 11/1/2022
6.4.0 628 9/26/2022
6.3.0 494 9/20/2022
6.2.0 626 8/10/2022
6.1.0 630 6/9/2022
6.0.0 743 3/12/2022
0.0.3 409 1/7/2022
0.0.2 504 1/7/2022
0.0.1 431 12/28/2021