ManagedCode.OpenAI.Azure
0.0.6-alpha
Prefix Reserved
See the version list below for details.
dotnet add package ManagedCode.OpenAI.Azure --version 0.0.6-alpha
NuGet\Install-Package ManagedCode.OpenAI.Azure -Version 0.0.6-alpha
<PackageReference Include="ManagedCode.OpenAI.Azure" Version="0.0.6-alpha" />
paket add ManagedCode.OpenAI.Azure --version 0.0.6-alpha
#r "nuget: ManagedCode.OpenAI.Azure, 0.0.6-alpha"
// Install ManagedCode.OpenAI.Azure as a Cake Addin #addin nuget:?package=ManagedCode.OpenAI.Azure&version=0.0.6-alpha&prerelease // Install ManagedCode.OpenAI.Azure as a Cake Tool #tool nuget:?package=ManagedCode.OpenAI.Azure&version=0.0.6-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.
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 | Versions 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. |
-
net7.0
- Azure.AI.OpenAI (>= 1.0.0-beta.5)
- ManagedCode.OpenAI (>= 0.0.6-alpha)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.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 |
---|---|---|
0.0.11-alpha | 486 | 10/3/2023 |
0.0.10-alpha | 314 | 7/24/2023 |
0.0.9-alpha | 99 | 7/24/2023 |
0.0.8-alpha | 101 | 7/23/2023 |
0.0.7-alpha | 101 | 7/21/2023 |
0.0.6-alpha | 94 | 7/21/2023 |