tryAGI.OpenAI
3.0.3-dev.1
Prefix Reserved
See the version list below for details.
dotnet add package tryAGI.OpenAI --version 3.0.3-dev.1
NuGet\Install-Package tryAGI.OpenAI -Version 3.0.3-dev.1
<PackageReference Include="tryAGI.OpenAI" Version="3.0.3-dev.1" />
paket add tryAGI.OpenAI --version 3.0.3-dev.1
#r "nuget: tryAGI.OpenAI, 3.0.3-dev.1"
// Install tryAGI.OpenAI as a Cake Addin #addin nuget:?package=tryAGI.OpenAI&version=3.0.3-dev.1&prerelease // Install tryAGI.OpenAI as a Cake Tool #tool nuget:?package=tryAGI.OpenAI&version=3.0.3-dev.1&prerelease
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 = CreateChatCompletionRequestModel.Gpt35Turbo;
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 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 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. |
-
.NETFramework 4.6.2
- System.Text.Json (>= 8.0.4)
- Tiktoken (>= 2.0.3)
-
.NETStandard 2.0
- System.Text.Json (>= 8.0.4)
- Tiktoken (>= 2.0.3)
-
net6.0
- System.Text.Json (>= 8.0.4)
- Tiktoken (>= 2.0.3)
-
net8.0
- Tiktoken (>= 2.0.3)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on tryAGI.OpenAI:
Package | Downloads |
---|---|
LangChain.Providers.OpenAI
OpenAI API LLM and Chat model provider. |
|
Anyscale
SDK for Anyscale Endpoint that makes it easy and cheap to use LLama 2 |
|
LangChain.Providers.Azure
OpenAI API LLM and Chat model provider. |
|
LangChain.Serve.OpenAI
LangChain Serve as OpenAI sdk compatible API |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on tryAGI.OpenAI:
Repository | Stars |
---|---|
tryAGI/LangChain
C# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.
|
Version | Downloads | Last updated |
---|---|---|
3.8.1-dev.13 | 0 | 10/2/2024 |
3.8.1-dev.6 | 31 | 9/28/2024 |
3.8.1-dev.3 | 39 | 9/28/2024 |
3.8.1-dev.2 | 37 | 9/26/2024 |
3.8.0 | 293 | 9/26/2024 |
3.7.1-dev.14 | 30 | 9/24/2024 |
3.7.1-dev.12 | 44 | 9/23/2024 |
3.7.1-dev.5 | 61 | 9/16/2024 |
3.7.1-dev.3 | 1,151 | 9/15/2024 |
3.7.0 | 270 | 9/14/2024 |
3.6.4-dev.10 | 46 | 9/14/2024 |
3.6.4-dev.9 | 47 | 9/14/2024 |
3.6.4-dev.7 | 39 | 9/13/2024 |
3.6.4-dev.5 | 49 | 9/9/2024 |
3.6.3 | 388 | 9/2/2024 |
3.6.2 | 110 | 9/1/2024 |
3.6.1 | 116 | 9/1/2024 |
3.5.2-dev.24 | 57 | 8/31/2024 |
3.5.2-dev.22 | 48 | 8/31/2024 |
3.5.2-dev.21 | 51 | 8/31/2024 |
3.5.2-dev.14 | 51 | 8/29/2024 |
3.5.2-dev.10 | 71 | 8/24/2024 |
3.5.2-dev.9 | 81 | 8/21/2024 |
3.5.2-dev.7 | 74 | 8/19/2024 |
3.5.2-dev.6 | 66 | 8/19/2024 |
3.5.2-dev.5 | 71 | 8/19/2024 |
3.5.2-dev.2 | 83 | 8/18/2024 |
3.5.1 | 665 | 8/18/2024 |
3.5.1-dev.4 | 70 | 8/18/2024 |
3.5.1-dev.3 | 78 | 8/18/2024 |
3.5.0 | 128 | 8/17/2024 |
3.4.2-dev.5 | 69 | 8/17/2024 |
3.4.2-dev.1 | 71 | 8/17/2024 |
3.4.1 | 212 | 8/16/2024 |
3.4.0 | 129 | 8/16/2024 |
3.3.1-dev.17 | 82 | 8/15/2024 |
3.3.1-dev.16 | 62 | 8/15/2024 |
3.3.1-dev.14 | 65 | 8/15/2024 |
3.3.1-dev.12 | 73 | 8/13/2024 |
3.3.1-dev.11 | 69 | 8/13/2024 |
3.3.1-dev.8 | 63 | 8/12/2024 |
3.3.1-dev.7 | 58 | 8/12/2024 |
3.3.1-dev.1 | 35 | 8/6/2024 |
3.3.0 | 287 | 8/6/2024 |
3.2.2-dev.3 | 29 | 8/6/2024 |
3.2.1 | 735 | 8/6/2024 |
3.2.1-dev.2 | 46 | 8/6/2024 |
3.2.1-dev.1 | 33 | 8/5/2024 |
3.2.0 | 79 | 8/5/2024 |
3.1.1-dev.1 | 35 | 8/4/2024 |
3.1.0 | 150 | 8/1/2024 |
3.0.4-dev.11 | 42 | 8/1/2024 |
3.0.4-dev.9 | 616 | 7/24/2024 |
3.0.4-dev.8 | 106 | 7/23/2024 |
3.0.4-dev.6 | 155 | 7/20/2024 |
3.0.4-dev.5 | 52 | 7/20/2024 |
3.0.4-dev.4 | 53 | 7/20/2024 |
3.0.4-dev.3 | 53 | 7/20/2024 |
3.0.4-dev.2 | 55 | 7/19/2024 |
3.0.4-dev.1 | 51 | 7/18/2024 |
3.0.3 | 150 | 7/18/2024 |
3.0.3-dev.1 | 45 | 7/18/2024 |
3.0.1 | 111 | 7/13/2024 |
3.0.0 | 86 | 7/11/2024 |
3.0.0-alpha.3 | 48 | 7/7/2024 |
3.0.0-alpha.2 | 47 | 7/6/2024 |
2.0.9 | 22,880 | 5/14/2024 |
2.0.8 | 141 | 4/29/2024 |
2.0.7 | 120 | 4/29/2024 |
2.0.6 | 9,142 | 4/22/2024 |
2.0.5 | 612 | 4/10/2024 |
2.0.4 | 356 | 4/4/2024 |
2.0.3 | 123 | 4/3/2024 |
2.0.2 | 198 | 4/3/2024 |
2.0.1 | 126 | 4/2/2024 |
2.0.0 | 300 | 3/22/2024 |
2.0.0-alpha.10 | 2,637 | 2/23/2024 |
2.0.0-alpha.9 | 13,727 | 1/27/2024 |
2.0.0-alpha.8 | 52 | 1/27/2024 |
2.0.0-alpha.7 | 98 | 1/20/2024 |
2.0.0-alpha.5 | 505 | 12/5/2023 |
2.0.0-alpha.4 | 184 | 11/16/2023 |
2.0.0-alpha.3 | 94 | 11/16/2023 |
2.0.0-alpha.2 | 62 | 11/16/2023 |
2.0.0-alpha.1 | 60 | 11/15/2023 |
2.0.0-alpha.0 | 57 | 11/15/2023 |
1.8.2 | 59,470 | 10/13/2023 |
1.8.1 | 434 | 10/11/2023 |
1.8.0 | 281 | 9/29/2023 |
1.7.2 | 1,637 | 8/15/2023 |
1.7.1 | 160 | 8/15/2023 |
1.7.0 | 329 | 8/15/2023 |
1.6.3 | 1,885 | 7/29/2023 |
1.6.1 | 154 | 7/29/2023 |
1.6.0 | 289 | 7/29/2023 |
1.5.0 | 545 | 7/13/2023 |
1.4.1 | 169 | 7/12/2023 |
1.4.0 | 165 | 7/12/2023 |
1.3.0 | 167 | 7/12/2023 |
1.2.0 | 587 | 7/5/2023 |
1.1.2 | 320 | 6/30/2023 |
1.1.1 | 166 | 6/30/2023 |
1.1.0 | 162 | 6/29/2023 |
1.0.0 | 176 | 6/28/2023 |
0.9.0 | 216 | 6/24/2023 |
0.0.0-dev.150 | 50 | 7/18/2024 |
0.0.0-dev | 95 | 9/14/2024 |