Whetstone.ChatGPT 1.0.0

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

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

CodeQL

Whetstone.ChatGPT

A simple light-weight library that wraps ChatGPT API completions.

This library includes quality of life improvements:

  • including support for CancellationTokens
  • documentation comments
  • conversions of Unix Epoch time to DateTime, etc.
  • IChatGPTClient interface for use with dependency injection
  • Streaming completion responses and fine tune events

Supported features include:

  • Completions
  • Edits
  • Files
  • Fine Tunes
  • Images
  • Embeddings
  • Moderations

Completion

ChatGPT Completions use models to answer a wide variety of tasks, including but not limited to classification, sentiment analysis, answering questions, etc.

Completion Quickstart

This shows a direct useage of the text-davinci-003 model without any prompts.

using Whetstone.ChatGPT;
using Whetstone.ChatGPT.Models;

. . .

IChatGPTClient client = new ChatGPTClient("YOURAPIKEY");

var gptRequest = new ChatGPTCompletionRequest
{
    Model = ChatGPTCompletionModels.Davinci,
    Prompt = "How is the weather?"
};

var response = await client.CreateCompletionAsync(gptRequest);

Console.WriteLine(response.GetCompletionText());

ChatGPT is not deterministic. One of the test runs of the sample above returned:

The weather can vary greatly depending on location. In general, you can expect temperatures to be moderate and climate to be comfortable, but it is always best to check the forecast for your specific area.

Completion Code Sample

A C# console application that uses completions is available at:

Whetstone.ChatGPT.CommandLineBot (chatgpt-marv)

This sample includes:

  • Authentication
  • Created a completion request using a prompt
  • Processing completion responses

Editing Quickstart

To use submit an edit completion request:

using Whetstone.ChatGPT;
using Whetstone.ChatGPT.Models;

. . .

IChatGPTClient client = new ChatGPTClient("YOURAPIKEY");

var gptEditRequest = new ChatGPTCreateEditRequest
{             
    Input = "What day of the wek is it?",
    Instruction = "Fix spelling mistakes"
};

var response = await client.CreateEditAsync(gptEditRequest);

Console.WriteLine(response.GetEditedText());

One of the test runs returned:

What day of the week is it?

File Quickstart

How to create a upload a new fine tuning file.


List<ChatGPTFineTuneLine> tuningInput = new()
{
    new ChatGPTFineTuneLine("<PROMPT>", "<COMPLETION>"),
    new ChatGPTFineTuneLine("<PROMPT>", "<COMPLETION>"),
    . . .
};

byte[] tuningText = tuningInput.ToJsonLBinary();

string fileName = "finetuningsample.jsonl";

ChatGPTUploadFileRequest? uploadRequest = new ChatGPTUploadFileRequest
{
    File = new ChatGPTFileContent
    {
        FileName = fileName,
        Content = tuningText
    }
};

ChatGPTFileInfo? uploadedFileInfo;
using (IChatGPTClient client = new ChatGPTClient("YOURAPIKEY"))
{
    uploadedFileInfo = await client.UploadFileAsync(uploadRequest);
}

Fine Tuning Quickstart

Once the file has been created, get the fileId, and reference it when creating a new fine tuning.

using (IChatGPTClient client = new ChatGPTClient("YOURAPIKEY"))
{
  var fileList = await client.ListFilesAsync();
  var foundFile =  fileList.Data.First(x => x.Filename.Equals("finetuningsample.jsonl"));

  ChatGPTCreateFineTuneRequest tuningRequest = new ChatGPTCreateFineTuneRequest
  {
     TrainingFileId = foundFile.Id
  };

  ChatGPTFineTuneJob? tuneResponse = await client.CreateFineTuneAsync(tuningRequest);

  string fineTuneId = tuneResponse.Id;

}

Processing the fine tuning request will take some time. Once it finishes, the Status will report "succeeded" and it's ready to be used in a completion request.

using (IChatGPTClient client = new ChatGPTClient("YOURAPIKEY"))
{
  ChatGPTFineTuneJob? tuneResponse = await client.RetrieveFineTuneAsync("FINETUNEID");

  if(tuneResponse.Status.Equals("succeeded"))
  {
    var gptRequest = new ChatGPTCompletionRequest
    {
      Model = ChatGPTCompletionModels.Davinci,
      Prompt = "How is the weather?"
    };

    var response = await client.CreateCompletionAsync(gptRequest);

    Console.WriteLine(response.GetCompletionText());
  }
}

Image Quickstart

Here's an example that generates a 1024x1024 image.

ChatGPTCreateImageRequest imageRequest = new()
{
    Prompt = "A sail boat",
    Size = CreatedImageSize.Size1024,
    ResponseFormat = CreatedImageFormat.Base64
};

using (IChatGPTClient client = new ChatGPTClient("YOURAPIKEY"))
{
    ChatGPTImageResponse? imageResponse = await client.CreateImageAsync(imageRequest);

    Assert.NotNull(imageResponse);

    Assert.NotNull(imageResponse.Data);

    Assert.Single(imageResponse.Data);

    Assert.NotNull(imageResponse.Data[0].Base64);

    string? imageData = imageResponse.Data[0].Base64;

    if (imageData != null)
    {
        byte[] imageBytes = Convert.FromBase64String(imageData);
        Assert.True(imageBytes.Length > 0);
        File.WriteAllBytes("sailboat.png", imageBytes);
    }
}
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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.1 1,298 2/17/2024
1.8.0 137 1/21/2024
1.7.1 153 1/8/2024
1.7.0 465 12/17/2023
1.6.2 559 10/8/2023
1.6.1 1,137 7/8/2023
1.6.0 1,895 3/18/2023
1.5.0 273 3/12/2023
1.4.0 4,044 2/11/2023
1.3.0 608 1/21/2023
1.2.0 403 1/8/2023
1.1.0 296 1/7/2023
1.0.0 320 1/4/2023