ManagedCode.OpenAI.Azure 0.0.11-alpha

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

// Install ManagedCode.OpenAI.Azure as a Cake Tool
#tool nuget:?package=ManagedCode.OpenAI.Azure&version=0.0.11-alpha&prerelease

OpenAI

This is an unofficial C# library for the OpenAI API. As there are no official libraries available, we have created our own to help C# developers interact with the API easily.

.NET Coverage Status nuget CodeQL NuGet Package

Installation

To install the ManagedCode.OpenAI library from NuGet, you can use the following methods:

Package Manager

Open the Package Manager Console in Visual Studio and run the following command:

Install-Package ManagedCode.OpenAI

.NET CLI

You can also use the .NET CLI to install the package. Open a terminal/command prompt and run the following command:

dotnet add package ManagedCode.OpenAI

Usage

Initializing the client You can initialize the client in two ways:

var client1 = GptClient.Builder("#API_KEY#")
    .WithOrganization("#ORGANIZATION#")
    .Build();
var client2 = GptClient.Builder("#API_KEY#")
    .WithOrganization("#ORGANIZATION#")
    .Configure(x => x.SetDefaultModel(GptModel.Ada))
    .Build();

or using DI

builder.Services.AddOpenAI("#API_KEY#");

public class MyClass
{
    public MyClass(IGptClient client)
    {
        var chat = client.OpenChat();
    }
}

Ask chat gpt

var client = GptClient.Builder("#API_KEY#")
    .WithOrganization("#ORGANIZATION#")
    .Build();
var chat = client.OpenChat();
var answer = await chat.AskAsync("2+2?");
Console.WriteLine($"Answer: {answer.Data.Content}");

Generating an image URL

var client = new GptClient("#API_KEY#");
var img = await client.ImageClient
    .GenerateImage("Big man")
    .AsUrl().ExecuteAsync();

var url = img.Content;
Console.WriteLine(url);

Generating an image URL with editing

var client = new GptClient("#API_KEY#");
var imgBytes = new byte[] { };
var maskBase64 = "#CONTENT#";

var img = await client.ImageClient
    .EditImage("Change color to red", x => x.FromBytes(imgBytes))
    .SetImageMask(x => x.FromBase64(maskBase64))
    .AsUrl().ExecuteAsync();

// Edited img URL
Console.WriteLine(img.Content);

Editing an image using a mask

var client = new GptClient("#API_KEY#");
var imgBytes = new byte[] { };
var imgCollection = await client.ImageClient
    .VariationImage(x => x.FromBytes(imgBytes))
    .AsBase64String()
    .ExecuteMultipleAsync(5);

foreach (var imageBase64 in imgCollection.Content)
    Console.WriteLine(imageBase64);

Generating multiple image variations as base64 strings

Create multiple variations of an image in base64 string format with 5 results:

var client = new GptClient("#API_KEY#");
var imgBytes = new byte[] { };
var imgCollection = await client.ImageClient
    .VariationImage(x => x.FromBytes(imgBytes))
    .AsBase64String()
    .ExecuteMultipleAsync(5);

foreach (var imageBase64 in imgCollection.Content)
    Console.WriteLine(imageBase64);

Contributing

We welcome contributions to this project. Please submit a pull request or create an issue if you'd like to help improve this library.

Product Compatible and additional computed target framework versions.
.NET 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 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.

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
0.0.11-alpha 464 10/3/2023
0.0.10-alpha 294 7/24/2023
0.0.9-alpha 85 7/24/2023
0.0.8-alpha 84 7/23/2023
0.0.7-alpha 86 7/21/2023
0.0.6-alpha 77 7/21/2023