ConnectingApps.Refit.OpenAI 1.0.3

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

// Install ConnectingApps.Refit.OpenAI as a Cake Tool
#tool nuget:?package=ConnectingApps.Refit.OpenAI&version=1.0.3

Refit.OpenAI

ConnectingApps.Refit.OpenAI is a Refit client package for calling OpenAI (but not made by the OpenAI company). Using this package, you can call the OpenAI API while being in full control of resilience and logging. This is because Refit is used so you can be fully control the HttpClient, including the logging, returned HTTP status codes etc.

For example, assuming you want to do this HTTP call:

POST https://api.openai.com/v1/chat/completions
Content-Type: application/json
Authorization: Bearer {{key}}
{
    "model": "gpt-3.5-turbo",
    "messages": [
        {
            "role": "user",
            "content": "What is the average temperature in New York city in January?"
        }
    ],
    "temperature": 0.7
}

you can achieve that with the following C# code:

using ConnectingApps.Refit.OpenAI;
using ConnectingApps.Refit.OpenAI.Completions;
using ConnectingApps.Refit.OpenAI.Completions.Request;
using Refit;

var apiKey = Environment.GetEnvironmentVariable("OPENAI_KEY");
var completionApi = RestService.For<ICompletion>("https://api.openai.com", OpenAiRefitSettings.RefitSettings);

var response = await completionApi.CreateCompletionAsync(new ChatRequest
    {
        Model = "gpt-3.5-turbo",
        Temperature = 0.7,
        Messages = new List<Message>
        {
            new()
            {
                Role = "user",
                Content = "What is the capital of the France?",
            }
        }
    }, $"Bearer {apiKey}");

Console.WriteLine($"Returned response status code {response.StatusCode}");
Console.WriteLine(response.Content!.Choices!.First().Message!.Content);

giving the following output:

Returned response status code OK
The capital of France is Paris.

You can reuse your existing Refit experience to:

  1. Implement resilience in case of accidental failures
  2. Trace the statuscode of your REST Calls
  3. Code in C# like it is a raw request
  4. Benefit from the highly performant (de)serialization using System.Text.Json

This Software incorporates certain components that are not owned by Connecting Apps. These external components, including but not limited to software libraries, plugins, modules, or any other type of software components (collectively, “External Components”), are the property of their respective owners and are used within the Software either under license or as allowed by applicable law.

Each of these External Components is subject to its own applicable license terms and conditions, which may be found in the documentation accompanying the External Components, in the External Components’ respective official repositories, or through other appropriate channels provided by the respective owners or licensors of the External Components. Users of the Software are responsible for complying with those terms and conditions, as well as with any and all other applicable laws and regulations related to the use of the External Components.

The Company disclaims any proprietary interests in the intellectual property of the External Components. The inclusion of these External Components within the Software does not imply any endorsement, affiliation, or sponsorship between the Company and the respective owners or licensors of the External Components.

Limitation of Liability

To the maximum extent permitted by applicable law, the Company shall not be liable for any damages arising out of or in connection with the use of the External Components incorporated within the Software. Users agree to hold harmless and indemnify the Company against any claims or liabilities arising out of the use, reproduction, or distribution of the External Components.

Miscellaneous

This Legal Statement may be updated from time to time at the sole discretion of the Company. Users are encouraged to review this Statement periodically to stay informed of any changes.

For any questions regarding this Legal Statement, or to obtain more information about the External Components incorporated within the Software, please contact [Your Company’s Contact Information].

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 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 was computed.  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.
  • .NETStandard 2.0

    • Refit (>= 6.0.1 && <= 8.2.0)

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.9.0 4,188 10/25/2023
1.8.0 172 10/24/2023
1.7.0 216 10/17/2023
1.6.0 127 10/16/2023
1.5.0 153 10/15/2023
1.4.0 188 10/14/2023
1.3.0 209 10/13/2023
1.2.1 227 10/12/2023
1.2.0-preview 81 10/12/2023
1.1.2 246 10/12/2023
1.1.1 127 10/11/2023
1.1.0-preview 84 10/11/2023
1.0.4 133 10/11/2023
1.0.3 108 10/10/2023
1.0.2-preview 99 10/10/2023
1.0.1-preview 76 10/10/2023

Initial version