Sail.NET
0.6.1
dotnet add package Sail.NET --version 0.6.1
NuGet\Install-Package Sail.NET -Version 0.6.1
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="Sail.NET" Version="0.6.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sail.NET --version 0.6.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Sail.NET, 0.6.1"
#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 Sail.NET as a Cake Addin #addin nuget:?package=Sail.NET&version=0.6.1 // Install Sail.NET as a Cake Tool #tool nuget:?package=Sail.NET&version=0.6.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Sail.NET
Sail.NET is a .NET wrapper for OpenAI's API that aims to create a streamlined and intuive way of accessing the API.
Setup
- Create an API key at: https://platform.openai.com/
- Install the Sail.NET NuGet package here: https://www.nuget.org/packages/Sail.NET
Basic Implementation
// Create the processor object
var processor = new SailProcessor();
// Create the arguments to pass in
var processorArgs = new SailProcessorArgs()
{
ApiKey = "*** API KEY GOES HERE ***",
Models = new()
{
{ SailModelTypes.GPT3Point5, new List<string>() { "name" } }
}
};
// Initialize the processor
processor.Initialize(processorArgs);
// Send a request
SailContext<SailMessage> response = await processor.SendRequestAsync(
"Hello World!",
SailModelTypes.GPT3Point5,
"name",
count: 1
);
// Check if response is successful
if (response.Success)
{
// Output response
Console.WriteLine("Response: " + response.Result.Output.Text);
}
else
{
// Output error
Console.WriteLine("Error: " + response.Exception);
}
Additional Functionality
// Create additional model arguments
var dalleArgs = new SailModelArgs()
{
Name = "DALL-E",
Address = "https://api.openai.com/v1/images/generations",
Count = 1
};
// Configure model with custom settings
processor.ConfigureModel(SailModelTypes.DALLE, "name", dalleArgs);
// Reconfigure model with updated settings
processor.ReconfigureModel(SailModelTypes.GPT3Point5, "name", temperature: 0.1);
// Clears message history for a model
processor.ClearModelHistory(SailModelTypes.GPT3Point5, "name");
// Set a system message
processor.AddSystemMessage(SailModelTypes.GPT3Point5, "name","Respond in the style of Yoda");
// Remove a system message
processor.RemoveSystemMessage(SailModelTypes.GPT3Point5, "name", "Respond in the style of Yoda");
// Retrieve messages from a specific model
var messages = processor.GetModelMessages(SailModelTypes.GPT3Point5, "name");
Function Calling
In order to use function calling, the used model must be the 'GPT3Point5Snapshot'. The functions you wish the API to recognise need to be added to the model manually. The follwoing parameters can be added to the 'SailModelArgs' object when configuring a model, or called directly using the 'ConfigureModelFunctions' method.
- 'ConfigureFunctions': Whether function calling should be used *'SailModelArgs' only
- 'FunctionsLocation': The class that all of the functions are located in
- 'Functions': A dictionary of 'SailFunction' objects that contain the data for the configured functions
public class FunctionsLocation
{
public static void ExampleFunction(string example)
{
// Functionality goes here
}
}
public class ConfigureFunctions
{
public void ConfigureExample(SailProcessor processor)
{
// Create location object
var location = new FunctionsLocation();
// Configure model functions
processor.ConfigureModelFunctions(SailModelTypes.GPT3Point5Snapshot, "name", location.GetType(), GetFunctions());
}
public Dictionary<string, SailFunction> GetFunctions()
{
var functions = new Dictionary<string, SailFunction>
{
{
"ExampleFunction",
SailFunctionProcessor.BuildFunction(
"ExampleFunction",
"An example function",
new
{
Example = new SailFunctionProperty()
{
Type = "string",
Description = "An example variable"
}
},
new List<string>()
{
"example"
}
)
}
};
return functions;
}
}
History
Version 0.6
Version 0.6.1
- Added name identifier to all models to allow for creation of multiple models with the same type
Version 0.5
Version 0.5.1
- Added return types to 'AddSystemMessage' and 'RemoveSystemMessage' functions
- Added DALLE-3 support
Version 0.4
Version 0.4.2
- Added GPT4 support
Version 0.4.1
- Added support for function calling
- Added functionality for setting system messages
- Added 'GPT3Point5Snapshot' model support
- Fixed issue where assistant messages weren't being stored
Version 0.3
Version 0.3.1
- Added new message input and output objects
- Added 'ClearModelHistory' function
- Added additional error handling
Version 0.2
Version 0.2.4
- Added missing 'Count' variable to 'SailModelArgs'
- Added '_handlers' dictionary for assigning a handler for each model
Version 0.2.3
- Added comments to each class
- Removed "GPT4" from "SailModeTypes"
Version 0.2.2
- Renamed "SailModelType" enum
Version 0.2.1
- Refactored code to allow for multiple endpoints
- Added support for DALL-E image generation
- Fixed issue where ChatGPT messages weren't being stored
- Simplified implementation process
Version 0.1
Version 0.1.1
- Created basic request and response classes
- Added support for ChatGPT messaging
Product | Versions 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.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.