HigLabo.OpenAI 8.0.0.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. 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.13.0 75 5/12/2024
8.12.0 48 5/12/2024
8.11.0 98 5/6/2024
8.10.0 84 5/6/2024
8.9.0 77 5/3/2024
8.8.0.1 83 4/30/2024
8.8.0 106 4/21/2024
8.7.0 93 4/19/2024
8.6.0 108 4/16/2024
8.5.0 193 4/12/2024
8.4.0 105 4/7/2024
8.3.2 151 3/18/2024
8.3.1 98 3/18/2024
8.3.0 111 3/17/2024
8.2.0 279 2/23/2024
8.1.0 157 2/11/2024
8.0.2.1 92 2/11/2024
8.0.2 96 2/3/2024
8.0.1.1 294 1/12/2024
8.0.1 334 1/8/2024
8.0.0.6 95 1/7/2024
8.0.0.5 156 1/1/2024
8.0.0.4 137 12/23/2023
8.0.0.3 164 12/13/2023
8.0.0.2 171 12/2/2023
8.0.0.1 117 12/2/2023
8.0.0 179 11/21/2023
7.2.0 47 5/12/2024
7.1.0 103 2/11/2024
7.0.3.1 222 12/2/2023
7.0.3 142 11/21/2023
7.0.2 161 11/12/2023
7.0.1 107 11/11/2023
7.0.0 114 11/11/2023
6.0.0 186 12/3/2023
2.1.1 99 2/11/2024
2.1.0 127 12/3/2023