OpenAI.Constants
3.0.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
Suggested Alternatives
dotnet add package OpenAI.Constants --version 3.0.0
NuGet\Install-Package OpenAI.Constants -Version 3.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.Constants" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenAI.Constants --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenAI.Constants, 3.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.Constants as a Cake Addin #addin nuget:?package=OpenAI.Constants&version=3.0.0 // Install OpenAI.Constants as a Cake Tool #tool nuget:?package=OpenAI.Constants&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenAI
Features 🔥
- Fully generated C# SDK based on official OpenAI OpenAPI specification using OpenApiGenerator
- Same day update to support new features
- Updated and supported automatically if there are no breaking changes
- Contains a supported list of constants such as current prices, models, and other
- Source generator to define functions natively through C# interfaces
Usage
using OpenAI;
public enum Unit
{
Celsius,
Fahrenheit,
}
public class Weather
{
public string Location { get; set; } = string.Empty;
public double Temperature { get; set; }
public Unit Unit { get; set; }
public string Description { get; set; } = string.Empty;
}
[OpenAiFunctions]
public interface IWeatherFunctions
{
[Description("Get the current weather in a given location")]
public Task<Weather> GetCurrentWeatherAsync(
[Description("The city and state, e.g. San Francisco, CA")] string location,
Unit unit = Unit.Celsius,
CancellationToken cancellationToken = default);
}
public class WeatherService : IWeatherFunctions
{
public Task<Weather> GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)
{
return Task.FromResult(new Weather
{
Location = location,
Temperature = 22.0,
Unit = unit,
Description = "Sunny",
});
}
}
using var api = new OpenAiApi();
api.AuthorizeUsingBearer(apiKey);
var service = new WeatherService();
var tools = service.AsTools();
var messages = new List<ChatCompletionRequestMessage>
{
"You are a helpful weather assistant.".AsSystemMessage(),
"What is the current temperature in Dubai, UAE in Celsius?".AsUserMessage(),
};
var model = ChatModels.Gpt35Turbo.Id;
var result = await api.Chat.CreateChatCompletionAsync(
messages,
model: model,
tools: tools);
var resultMessage = result.Choices.First().Message;
messages.Add(resultMessage.AsRequestMessage());
foreach (var call in resultMessage.ToolCalls)
{
var json = await service.CallAsync(
functionName: call.Function.Name,
argumentsAsJson: call.Function.Arguments);
messages.Add(json.AsToolMessage(call.Id));
}
var result = await api.Chat.CreateChatCompletionAsync(
messages,
model: model,
tools: tools);
var resultMessage = result.Choices.First().Message;
messages.Add(resultMessage.AsRequestMessage());
> System:
You are a helpful weather assistant.
> User:
What is the current temperature in Dubai, UAE in Celsius?
> Assistant:
call_3sptsiHzKnaxF8bs8BWxPo0B:
GetCurrentWeather({"location":"Dubai, UAE","unit":"celsius"})
> Tool(call_3sptsiHzKnaxF8bs8BWxPo0B):
{"location":"Dubai, UAE","temperature":22,"unit":"celsius","description":"Sunny"}
> Assistant:
The current temperature in Dubai, UAE is 22°C with sunny weather.
Constants
This repository contains the library with constants for all OpenAI constants(models/prices/context length and other).
using OpenAI.Constants;
string id = EmbeddingModels.Version3Small; // implicit conversion to string
double price = EmbeddingModels.Version3Small.GetPriceInUsd(tokens: 500); // 0.00001
EmbeddingModels.Version3Small.MaxInputTokens // 8191
EmbeddingModels.Version3Small.PricePerTokenInUsd // 0.00000002
Support
Priority place for bugs: https://github.com/tryAGI/OpenAI/issues
Priority place for ideas and general questions: https://github.com/tryAGI/OpenAI/discussions
Discord: https://discord.gg/Ca2xhfBf3v
Product | Versions 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 is compatible. 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 is compatible. 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 is compatible. 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.
-
.NETFramework 4.6.2
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.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.
Version | Downloads | Last updated | |
---|---|---|---|
3.0.0 | 765 | 7/11/2024 | |
3.0.0-alpha.3 | 63 | 7/7/2024 | |
3.0.0-alpha.2 | 63 | 7/6/2024 | |
2.0.9 | 32,186 | 5/14/2024 | |
2.0.8 | 184 | 4/29/2024 | |
2.0.7 | 152 | 4/29/2024 | |
2.0.6 | 9,334 | 4/22/2024 | |
2.0.5 | 658 | 4/10/2024 | |
2.0.4 | 398 | 4/4/2024 | |
2.0.3 | 149 | 4/3/2024 | |
2.0.2 | 244 | 4/3/2024 | |
2.0.1 | 164 | 4/2/2024 | |
2.0.0 | 326 | 3/22/2024 | |
2.0.0-alpha.10 | 2,844 | 2/23/2024 | |
2.0.0-alpha.9 | 18,874 | 1/27/2024 | |
2.0.0-alpha.8 | 65 | 1/27/2024 | |
2.0.0-alpha.7 | 120 | 1/20/2024 | |
2.0.0-alpha.5 | 507 | 12/5/2023 | |
2.0.0-alpha.4 | 192 | 11/16/2023 | |
2.0.0-alpha.3 | 110 | 11/16/2023 | |
2.0.0-alpha.2 | 78 | 11/16/2023 |