tryAGI.OpenAI 2.0.9

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package tryAGI.OpenAI --version 2.0.9
NuGet\Install-Package tryAGI.OpenAI -Version 2.0.9
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="tryAGI.OpenAI" Version="2.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add tryAGI.OpenAI --version 2.0.9
#r "nuget: tryAGI.OpenAI, 2.0.9"
#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 tryAGI.OpenAI as a Cake Addin
#addin nuget:?package=tryAGI.OpenAI&version=2.0.9

// Install tryAGI.OpenAI as a Cake Tool
#tool nuget:?package=tryAGI.OpenAI&version=2.0.9

OpenAI

Nuget package dotnet License: MIT Discord

Generated C# SDK based on official OpenAI OpenAPI specification using NSwag

This package includes C# Source Generator which allows you to define functions natively through a C# interface, and also provides extensions that make it easier to call this interface later.
In addition to easy function implementation and readability, it generates Args classes, extension methods to easily pass a functions to API, and extension methods to simply call a function via json and return json.
Currently only System.Text.Json is supported.

Usage

using tryAGI.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",
        });
    }
}


var service = new WeatherService();
using var httpClient = new HttpClient();
var api = new OpenAiApi(apiKey, httpClient);
var result = await api.CreateChatCompletionAsync(new CreateChatCompletionRequest
{
    Messages = new List<ChatCompletionRequestMessage>
    {
        "You are a helpful weather assistant.".AsSystemMessage(),
        "What's the weather like today?".AsUserMessage(),
    },
    Functions = service.AsFunctions(),
    Function_call = Function_call4.Auto,
    Model = ModelIds.Gpt35Turbo_0613,
});
// ...
var resultMessage = result.GetFirstChoiceMessage();
var functionArgumentsJson = resultMessage.Function_call?.Arguments ?? string.Empty;
var json = await service.CallGetCurrentWeatherAsync(functionArgumentsJson);
// or just get arguments
var args = service.AsGetCurrentWeatherAsyncArgs(functionArgumentsJson);

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 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.

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
2.0.9 1,085 5/14/2024
2.0.8 113 4/29/2024
2.0.7 93 4/29/2024
2.0.6 7,842 4/22/2024
2.0.5 578 4/10/2024
2.0.4 302 4/4/2024
2.0.3 99 4/3/2024
2.0.2 171 4/3/2024
2.0.1 100 4/2/2024
2.0.0 269 3/22/2024
2.0.0-alpha.10 2,204 2/23/2024
2.0.0-alpha.9 7,935 1/27/2024
2.0.0-alpha.8 44 1/27/2024
2.0.0-alpha.7 90 1/20/2024
2.0.0-alpha.5 495 12/5/2023
2.0.0-alpha.4 173 11/16/2023
2.0.0-alpha.3 85 11/16/2023
2.0.0-alpha.2 51 11/16/2023
2.0.0-alpha.1 51 11/15/2023
2.0.0-alpha.0 48 11/15/2023
1.8.2 26,323 10/13/2023
1.8.1 344 10/11/2023
1.8.0 252 9/29/2023
1.7.2 1,486 8/15/2023
1.7.1 136 8/15/2023
1.7.0 305 8/15/2023
1.6.3 1,558 7/29/2023
1.6.1 130 7/29/2023
1.6.0 229 7/29/2023
1.5.0 431 7/13/2023
1.4.1 142 7/12/2023
1.4.0 145 7/12/2023
1.3.0 146 7/12/2023
1.2.0 491 7/5/2023
1.1.2 278 6/30/2023
1.1.1 134 6/30/2023
1.1.0 139 6/29/2023
1.0.0 149 6/28/2023
0.9.0 188 6/24/2023