Standard.AI.OpenAI
0.6.0
dotnet add package Standard.AI.OpenAI --version 0.6.0
NuGet\Install-Package Standard.AI.OpenAI -Version 0.6.0
<PackageReference Include="Standard.AI.OpenAI" Version="0.6.0" />
paket add Standard.AI.OpenAI --version 0.6.0
#r "nuget: Standard.AI.OpenAI, 0.6.0"
// Install Standard.AI.OpenAI as a Cake Addin #addin nuget:?package=Standard.AI.OpenAI&version=0.6.0 // Install Standard.AI.OpenAI as a Cake Tool #tool nuget:?package=Standard.AI.OpenAI&version=0.6.0
Standard.AI.OpenAI
Introduction
Standard.AI.OpenAI is a Standard-Compliant .NET library built on top of OpenAI API RESTful endpoints to enable software engineers to develop AI-Powered solutions in .NET.
Standard-Compliance
This library was built according to The Standard. The library follows engineering principles, patterns and tooling as recommended by The Standard.
This library is also a community effort which involved many nights of pair-programming, test-driven development and in-depth exploration research and design discussions.
How to use this library?
In order to use this library there are prerequists that you must complete before you can write your first AI-Powered C#.NET program. These steps are as follows:
OpenAI Account
You must create an OpenAI account with the following link: Click here
Nuget Package
Install the Standard.AI.OpenAI library in your project. Use the method best suited for your development preference listed at the Nuget Link above or below.
API Keys
Once you've created an OpenAI account. Now, go ahead and generate an API key from the following link: Click here
Hello, World!
Once you've completed the aforementioned steps, let's write our very first program with Standard.AI.OpenAI as follows:
Completions
The following example demonstrate how you can write your first Completions program.
Program.cs
using System;
using System.Threading.Tasks;
using Standard.AI.OpenAI.Clients.OpenAIs;
using Standard.AI.OpenAI.Models.Configurations;
using Standard.AI.OpenAI.Models.Services.Foundations.Completions;
namespace ExampleOpenAIDotNet
{
internal class Program
{
static async Task Main(string[] args)
{
var openAIConfigurations = new OpenAIConfigurations
{
ApiKey = "YOUR_API_KEY_HERE",
OrganizationId = "YOUR_OPTIONAL_ORG_ID_HERE"
};
var openAIClient = new OpenAIClient(openAIConfigurations);
var inputCompletion = new Completion
{
Request = new CompletionRequest
{
Prompts = new string[] { "Human: Hello!" },
Model = "text-davinci-003"
}
};
Completion resultCompletion =
await openAIClient.Completions.PromptCompletionAsync(
inputCompletion);
Array.ForEach(
resultCompletion.Response.Choices,
choice => Console.WriteLine(choice.Text));
}
}
}
Chat Completions
The following example demonstrate how you can write your first Chat Completions program.
Program.cs
using System;
using System.Threading.Tasks;
using Standard.AI.OpenAI.Clients.OpenAIs;
using Standard.AI.OpenAI.Models.Configurations;
using Standard.AI.OpenAI.Models.Services.Foundations.ChatCompletions;
namespace ExampleOpenAIDotNet
{
internal class Program
{
static async Task Main(string[] args)
{
var openAIConfigurations = new OpenAIConfigurations
{
ApiKey = "YOUR_API_KEY_HERE",
OrganizationId = "YOUR_OPTIONAL_ORG_ID_HERE"
};
var openAIClient = new OpenAIClient(openAIConfigurations);
var chatCompletion = new ChatCompletion
{
Request = new ChatCompletionRequest
{
Model = "gpt-3.5-turbo",
Messages = new ChatCompletionMessage[]
{
new ChatCompletionMessage
{
Content = "What is c#?",
Role = "user",
}
},
}
};
ChatCompletion resultChatCompletion =
await openAIClient.ChatCompletions.SendChatCompletionAsync(
chatCompletion);
Array.ForEach(
resultChatCompletion.Response.Choices,
choice => Console.WriteLine(
value: $"{choice.Message.Role}: {choice.Message.Content}"));
}
}
}
Exceptions
Standard.AI.OpenAI may throw following exceptions:
Exception Name | When it will be thrown |
---|---|
ChatCompletionClientValidationException |
This exception is thrown when a validation error occurs while using the chat completion client. For example, if required data is missing or invalid. |
ChatCompletionClientDependencyException |
This exception is thrown when a dependency error occurs while using the chat completion client. For example, if a required dependency is unavailable or incompatible. |
ChatCompletionClientServiceException |
This exception is thrown when a service error occurs while using the chat completion client. For example, if there is a problem with the server or any other service failure. |
How to Contribute
If you want to contribute to this project please review the following documents:
If you have a question make sure you either open an issue or join our The Standard Community discord server.
Live-Sessions
Our live-sessions are scheduled on The Standard Calendar make sure you adjust the time to your city/timezone to be able to join us.
We broadcast on multiple platforms:
Past-Sessions
Here's our live sessions to show you how this library was developed from scratch:
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
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- RESTFulSense (>= 2.15.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Standard.AI.OpenAI:
Package | Downloads |
---|---|
FenixAlliance.ABS.Integrations.OpenAI
Application Component for the Alliance Business Suite. |
GitHub repositories
This package is not used by any popular GitHub repositories.
This beta release offers fine-tuning and retrieving all files.