• Stars
    star
    264
  • Rank 155,103 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 1 year ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Standard-Compliant .NET library for Open AI

Standard.AI.OpenAI

Standard.AI.OpenAI

.NET Nuget Nuget The Standard - COMPLIANT The Standard The Standard Community

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.

Standard-Promise

The most important fulfillment aspect in a Standard complaint system is aimed towards contributing to people, its evolution, and principles. An organization that systematically honors an environment of learning, training, and sharing knowledge is an organization that learns from the past, makes calculated risks for the future, and brings everyone within it up to speed on the current state of things as honestly, rapidly, and efficiently as possible.

We believe that everyone has the right to privacy, and will never do anything that could violate that right. We are committed to writing ethical and responsible software, and will always strive to use our skills, coding, and systems for the good. We believe that these beliefs will help to ensure that our software(s) are safe and secure and that it will never be used to harm or collect personal data for malicious purposes.

The Standard Community as a promise to you is in upholding these values.

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.

Nuget

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}"));
        }
    }
}

Fine-Tunes

The following example demonstrate how you can write your first Fine-tunes program.

Program.cs

using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Standard.AI.OpenAI.Clients.OpenAIs;
using Standard.AI.OpenAI.Models.Configurations;
using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles;
using Standard.AI.OpenAI.Models.Services.Foundations.FineTunes;

namespace Examples.Standard.AI.OpenAI.Clients.FineTunes
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            var openAIConfigurations = new OpenAIConfigurations
            {
                ApiKey = "YOUR_API_KEY_HERE",
                ApiUrl = "https://api.openai.com"
            };

            IOpenAIClient openAIClient =
                new OpenAIClient(openAIConfigurations);

            MemoryStream memoryStream = CreateRandomStream();

            var aiFile = new AIFile
            {
                Request = new AIFileRequest
                {
                    Name = "Test",
                    Content = memoryStream,
                    Purpose = "fine-tune"
                }
            };

            AIFile file = await openAIClient.AIFiles
                .UploadFileAsync(aiFile);

            var fineTune = new FineTune();
            fineTune.Request = new FineTuneRequest();

            fineTune.Request.FileId =
                file.Response.Id;

            FineTune fineTuneResult =
                await openAIClient.FineTuneClient
                    .SubmitFineTuneAsync(fineTune);

            Console.WriteLine(fineTuneResult);
        }

        private static MemoryStream CreateRandomStream()
        {
            string content = "{\"prompt\": \"<prompt text>\", \"completion\": \"<ideal generated text>\"}";

            return new MemoryStream(Encoding.UTF8.GetBytes(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.
FineTuneClientValidationException This exception is thrown when a validation error occurs while using the fine-tunes client. For example, if required data is missing or invalid.
FineTuneClientDependencyException This exception is thrown when a dependency error occurs while using the fine-tunes client. For example, if a required dependency is unavailable or incompatible.
FineTuneClientDependencyException This exception is thrown when a service error occurs while using the fine-tunes 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:

YouTube

LinkedIn

Twitch

Twitter

Facebook

Past-Sessions

Here's our live sessions to show you how this library was developed from scratch:

Standard.AI.OpenAI YouTube Playlist

Important Notice

This library is a community effort - it is not associated or maintained by OpenAI in any capacity

More Repositories

1

The-Standard

This is The Standard. A collection of decades of experience in the engineering industry. I authored it to help you navigate the vast ocean of knowledge. The Standard is not perfect and never will be, and it reflects the ongoing evolution of the engineering industry. While one person may write it, it is the collection of thoughts from hundreds of engineers I've had the honor to interact with and learn from throughout my life.
1,064
star
2

OtripleS

This is an open source schooling system, dedicated to provide a better experience for schools needing a management and communication and tutoring system all in one place. This project is aiming toward directing all the software development funds and hours to families in need, the idea of the project is to allow schools to use the system as long as the software funds in the school are directed towards financially disadvantaged families and students.
C#
326
star
3

CSharpCodingStandard

This is the Standard for C# Programming language
251
star
4

RESTFulSense

A RESTFul operations client that serializes responses and throws meaningful exceptions for >= 400 status codes.
C#
238
star
5

PrettyBlazor

PrettyBlazor is a Blazor .NET library that enables Blazor developers to use control structures in their Blazor applications through markup without having to use obtrusive C# code to iterate or select particular fragments.
C#
105
star
6

OtripleS.Portal

C#
94
star
7

ADotNet

ADotNet is a.NET library that enables software engineers on the .NET platform to develop AzureDevOps pipelines and Git Actions in C#.
C#
92
star
8

Taarafo.Core

This API attempts to Decentralize Social Networks to De-Productize Humanity
C#
86
star
9

The-Standard-Uzbek

63
star
10

Xeption

A Better Exception for .NET
C#
56
star
11

The-Standard-Team

This is the engineering Standard for team culture, practices and code of conduct.
56
star
12

Standard.AI.Data.EntityIntelligence

.NET library to convert natural language query into SQL queries and generate results
C#
47
star
13

OData.NxT

This repository is for all the work involved in re-envisioning OData
C#
42
star
14

ODataDemo

C#
42
star
15

SharpStyles

C# .NET Library to Serialize C# objects into CSS Rules
C#
39
star
16

RESTFulLinq

RESTFulLinq is an easy way to send LINQ queries to your API fluently
C#
38
star
17

EntityIntelligence.POC

C#
37
star
18

InvisibleApi

ASP.NET Library that allows developers to add an extra layer of security on top of their existing endpoints
C#
33
star
19

EFxceptions

.NET Standard library to convert DbUpdateException into meaningful exceptions
C#
32
star
20

Taarafo.Web

C#
31
star
21

ODataWithoutEF

C#
31
star
22

SchoolEM

C#
30
star
23

LeVent

LeVent is a .NET library to manage local events in any application
C#
29
star
24

Sofee.Core

Sofee is a project that allows users to collect geo-political data such as countries, regions, languages, time zones and all kinds of different data.
C#
23
star
25

InternalMock

.NET library to mock internal private static methods in the same class that is the subject of test.
C#
23
star
26

Refugee.Core

This is an API to help support refugees everywhere around the world.
C#
19
star
27

OData3.1WithSwagger

C#
18
star
28

The-Standard-Codex

It's not enough to know the truth, you must have the courage to wield it into existence. This book will show you how.
18
star
29

ODataWithEDMAndBlazor

C#
16
star
30

POC.NuVerify

This is a POC for a public nuget packages verification
C#
14
star
31

SallyLibrary

C#
12
star
32

The-Blazor-Book

This repository will hold the content of a new book - Designing Enterprise-level Systems with Blazor
12
star
33

InternTrack.Core

C#
12
star
34

taarafo

Free Speech Reimagined
11
star
35

OData3Beta

C#
11
star
36

bVirtualization

This is a Blazor component for Virtualization that supports infinite scrolling with ANY type of data source, whether it's an API or Database or just simply a file on your computer or just in memeory!
C#
11
star
37

The-Standard-Italian

10
star
38

ContextualExperience

C#
10
star
39

GeoApi

An open source API to provide Geo Information about every city in the United States of America
C#
10
star
40

The-Standard-Azerbaijani

10
star
41

The-Standard-Journal

10
star
42

ProvisionAzureWithCSharp

C#
9
star
43

The-Standard-Arabic

9
star
44

Ezregx

A library built by engineers for humans to develop regular expressions - enjoy it!
C#
9
star
45

CulDeSacDemoApi

C#
9
star
46

blazorxreact

Blazor meets ReactJS with OfficeFabric!
HTML
7
star
47

LaQueue

LaQueue is a .NET abstraction library to allow Queue communications & testing locally
C#
7
star
48

SchoolX

Demo Mocking External Dependencies for Acceptance Tests
C#
7
star
49

AOPDemo

C#
6
star
50

anki_robot_with_azure

This is a code snippet to show how you can have Vector use Azure Cognitive Services to identify objects
Python
6
star
51

The-Standard-Spanish

Esto es El Estándar. Una colección de décadas de experiencia en la industria de la ingeniería. Mi autoría sobre El Estándar le ayudará a orientarse en el vasto océano del conocimiento. El Estándar no es perfecto y nunca lo será, y refleja la continua evolución de la industria de la ingeniería. Aunque la haya escrito una sola persona, es la recopilación de los pensamientos de cientos de ingenieros con los que he tenido el honor de interactuar y de los que he aprendido a lo largo de mi vida.
6
star
52

Discord-Dot-Net-Bot

This repo shows the simplest code to write a Discord Bot in C# .NET
C#
6
star
53

The-Standard-Systems-Design

The Standard for Systems Design & Architecture
5
star
54

ODataWithEndpointRouting3.1

C#
5
star
55

StandardGoLang

Building a simple app in Golang according to The Standard
Go
4
star
56

StandardJava

Example to demonstrate implementing The Standard in Java
Java
4
star
57

The-Standard-French

4
star
58

The-Standard-German

4
star
59

BlazorWithIAsyncEnumerableDemo

HTML
4
star
60

PrettyBlazorDemo

Demo for using PrettyBlazor
HTML
4
star
61

OData6Demo

C#
4
star
62

StandardPython

Python
4
star
63

The-Standard-Turkish

4
star
64

RockSteadyGo.Game

ShaderLab
4
star
65

ODataWithCosmosDBPart1

HTML
3
star
66

ODataWithCosmosAndBlazor

C#
3
star
67

The-Standard-Portuguese

3
star
68

EFCoreManyToMany

A quick demo to show many to many relationship with EF Core 3.1
C#
3
star
69

ODataWithDotNet5Demo

C#
3
star
70

TemporalTablesDemo

C#
3
star
71

DynamicComponentBlazorDemo

HTML
3
star
72

Standard.API.RESTFulSense

C#
3
star
73

AspNet6WithOData

C#
3
star
74

FuzzySearch

C#
3
star
75

ODataCosmosDBClient

C#
2
star
76

HiddenApiDemo

C#
2
star
77

The-Standard-Polish

2
star
78

StandardKotlin

Kotlin
2
star
79

WhenWillIBeAMillionaire

A simple calculator in Blazor.NET to give an estimate of how much monthly savings an individual needs to make to become a millionaire
HTML
2
star
80

RockSteadyGo.Core

C#
2
star
81

ABC.Core.Api

C#
2
star
82

Funcai

Experiment project to test post code to an API
JavaScript
2
star
83

InternTrack.Web

C#
2
star
84

The-Standard-Ukrainian

2
star
85

ML.NET-DEMO

C#
2
star
86

AspNetCoreWithPostgresAndOData

This repo has a demo project to show you how you can run ASP.NET Core application with Postgres and OData
C#
2
star
87

Azure-AI-Studio-Demo

This repo demonstrates working with Azure AI Studio fine-tuned instance
C#
2
star
88

JSCalculator

This is a calculator designed using HTML, CSS and JavaScript
JavaScript
1
star
89

HotReloadSimplified

1
star
90

SampleApp

C#
1
star
91

EventoShop

A project to demonstrate Scheduled Eventing
C#
1
star
92

ConDemo

C#
1
star
93

FundamentalsASPNETCore

C#
1
star
94

The-Standard-Malaysian

1
star
95

Standard.Universal.TypeScript

TypeScript
1
star
96

Benchmarking.NET

C#
1
star
97

GraphODataDemo

C#
1
star
98

The-Standard-Experiences

1
star
99

OData.Neo.Java

1
star
100

The-Tri-Nature-Of-Everything

This is an open-source book to dive into The Tri-Nature of Everything Theory.
1
star