HigLabo.OpenAI 8.0.0.1

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

// Install HigLabo.OpenAI as a Cake Tool
#tool nuget:?package=HigLabo.OpenAI&version=8.0.0.1                

See article https://www.codeproject.com/Articles/5372480/Csharp-OpenAI-library-that-support-Assistants-API

How to use? Download via Nuget

HigLabo.OpenAI

All source code is https://github.com/higty/higlabo/tree/master/Net7

HigLabo.OpenAI is that.

You can see sample code at https://github.com/higty/higlabo/blob/master/Net7/HigLabo.OpenAI.SampleConsoleApp/OpenAIPlayground.cs

The main class is OpenAIClient. You create OpenAIClient class for OpenAI API.

C# var apiKey = "your api key of OpenAI"; var client = new OpenAIClient(apiKey); For Azure endpoint.

C# var apiKey = "your api key of OpenAI"; var client = new OpenAIClient(new AzureSettings(apiKey, "https://tinybetter-work-for-our-future.openai.azure.com/", "MyDeploymentName")); Call ChatCompletion endpoint.

C# var p = new ChatCompletionsParameter(); var theme = "How to enjoy coffee"; p.Messages.Add(new ChatMessage(ChatMessageRole.User , $"Can you provide me with some ideas for blog posts about {theme}?")); p.Model = "gpt-3.5-turbo"; var res = await client.ChatCompletionsAsync(p); foreach (var choice in res.Choices) { Console.Write(choice.Message.Content); } Consume ChatCompletion endpoint with server sent event.

C# var theme = "How to enjoy coffee"; await foreach (var chunk in client.ChatCompletionsStreamAsync($"Can you provide me with some ideas for blog posts about {theme}?", "gpt-3.5-turbo")) { foreach (var choice in chunk.Choices) { Console.Write(choice.Delta.Content); } } Console.WriteLine(); Console.WriteLine("DONE"); ChatCompletion with function calling.

C# Shrink ▲
var p = new ChatCompletionsParameter(); //ChatGPT can correct Newyork,Sanflansisco to New york and San Flancisco. p.Messages.Add(new ChatMessage(ChatMessageRole.User, $"I want to know the whether of these locations. Newyork, Sanflansisco, Paris, Tokyo.")); p.Model = "gpt-3.5-turbo";

var tool = new ToolObject("function"); tool.Function = new FunctionObject(); tool.Function.Name = "getWhether"; tool.Function.Description = "This service can get whether of specified location."; tool.Function.Parameters = new { type = "object", properties = new { locationList = new { type = "array", description = "Location list that you want to know.", items = new { type = "string", } } } }; p.Tools = new List<ToolObject>(); p.Tools.Add(tool);

var processor = new ChatCompletionFunctionCallingProcessor(); //You must set Stream property to true to receive server sent event stream on chat completion endpoint. p.Stream = true; await foreach (var chunk in client.GetStreamAsync(p)) { foreach (var choice in chunk.Choices) { Console.Write(choice.Delta.Content); processor.Process(chunk); } } Console.WriteLine();

var f = processor.GetFunctionCall(); if (f != null) { Console.WriteLine("■Function name is " + f.Name); Console.WriteLine("■Arguments is " + f.Arguments); } Console.WriteLine(); Console.WriteLine("DONE"); Upload file for fine tuning or pass to assitants.

C# var p = new FileUploadParameter(); p.SetFile("my_file.pdf", File.ReadAllBytes("D:\Data\my_file.pdf")); p.Purpose = "assistants"; var res = await client.FileUploadAsync(p); Console.WriteLine(res); Image generation

C# var res = await client.ImagesGenerationsAsync("Blue sky and green field."); foreach (var item in res.Data) { Console.WriteLine(item.Url); } Create Assistant via API

C# var p = new AssistantCreateParameter(); p.Name = "Legal tutor"; p.Instructions = "You are a personal legal tutor. Write and run code to legal questions based on passed files."; p.Model = "gpt-4-1106-preview";

p.Tools = new List<ToolObject>(); p.Tools.Add(new ToolObject("code_interpreter")); p.Tools.Add(new ToolObject("retrieval"));

var res = await client.AssistantCreateAsync(p); Console.WriteLine(res); Add files to assistant.

C# var res = await client.FilesAsync(); foreach (var item in res.Data) { if (item.Purpose == "assistants") { var res1 = await cl.AssistantFileCreateAsync(id, item.Id); } } Get run and steps intomarion of thread.

C# var threadId = "thread_xxxxxxxxxxxx"; var res = await client.RunsAsync(threadId); foreach (var item in res.Data) { var res1 = await cl.RunStepsAsync(threadId, item.Id); foreach (var step in res1.Data) { if (step.Step_Details != null) { Console.WriteLine(step.Step_Details.GetDescription()); } } }

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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
8.18.0.1 101 10/16/2024
8.18.0 147 9/11/2024
8.17.0 148 8/23/2024
8.16.0 126 8/17/2024
8.15.0 252 7/23/2024
8.14.0.1 201 6/13/2024
8.14.0 104 6/5/2024
8.13.0 380 5/12/2024
8.12.0 82 5/12/2024
8.11.0 130 5/6/2024
8.10.0 112 5/6/2024
8.9.0 94 5/3/2024
8.8.0.1 121 4/30/2024
8.8.0 146 4/21/2024
8.7.0 132 4/19/2024
8.6.0 251 4/16/2024
8.5.0 506 4/12/2024
8.4.0 144 4/7/2024
8.3.2 191 3/18/2024
8.3.1 124 3/18/2024
8.3.0 122 3/17/2024
8.2.0 378 2/23/2024
8.1.0 178 2/11/2024
8.0.2.1 120 2/11/2024
8.0.2 108 2/3/2024
8.0.1.1 316 1/12/2024
8.0.1 358 1/8/2024
8.0.0.6 104 1/7/2024
8.0.0.5 181 1/1/2024
8.0.0.4 162 12/23/2023
8.0.0.3 173 12/13/2023
8.0.0.2 199 12/2/2023
8.0.0.1 125 12/2/2023
8.0.0 197 11/21/2023
7.2.0 168 5/12/2024
7.1.0 150 2/11/2024
7.0.3.1 265 12/2/2023
7.0.3 163 11/21/2023
7.0.2 185 11/12/2023
7.0.1 130 11/11/2023
7.0.0 124 11/11/2023
6.0.0 262 12/3/2023
2.1.1 116 2/11/2024
2.1.0 155 12/3/2023