HigLabo.OpenAI
8.0.0.1
Prefix Reserved
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
<PackageReference Include="HigLabo.OpenAI" Version="8.0.0.1" />
<PackageVersion Include="HigLabo.OpenAI" Version="8.0.0.1" />
<PackageReference Include="HigLabo.OpenAI" />
paket add HigLabo.OpenAI --version 8.0.0.1
#r "nuget: HigLabo.OpenAI, 8.0.0.1"
#:package HigLabo.OpenAI@8.0.0.1
#addin nuget:?package=HigLabo.OpenAI&version=8.0.0.1
#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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- HigLabo.Core (>= 8.0.0)
- HigLabo.NewtonsoftJson (>= 8.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 |
|---|---|---|
| 10.1.0.3 | 34 | 4/11/2026 |
| 10.1.0.2 | 35 | 4/11/2026 |
| 10.1.0.1 | 30 | 4/11/2026 |
| 10.1.0 | 100 | 3/9/2026 |
| 9.8.1.1 | 229 | 11/23/2025 |
| 9.8.1 | 222 | 11/23/2025 |
| 9.8.0 | 164 | 10/12/2025 |
| 9.7.0.2 | 154 | 10/12/2025 |
| 9.7.0.1 | 219 | 10/7/2025 |
| 9.7.0 | 214 | 10/7/2025 |
| 9.6.2 | 266 | 8/30/2025 |
| 9.6.1 | 257 | 8/30/2025 |
| 9.6.0 | 144 | 8/23/2025 |
| 9.5.0 | 154 | 8/23/2025 |
| 9.4.0 | 208 | 5/30/2025 |
| 9.3.1 | 176 | 5/30/2025 |
| 9.3.0 | 243 | 5/25/2025 |
| 9.2.1 | 226 | 5/25/2025 |
| 9.2.0 | 221 | 5/22/2025 |
| 8.0.0.1 | 210 | 12/2/2023 |