Betalgo.OpenAI
8.7.2
`Betalgo.OpenAI` has changed its package ID and namespace and will now be called `Betalgo.Ranul.OpenAI`. This change improves compatibility with Microsoft libraries and aligns with a new project called Ranul Tinga.
For the migration guide: https://github.com/betalgo/openai/wiki/Migration-Guides-for-breaking-changes
For more details: https://blog.kayhantolga.com/ai-updates-series-1
dotnet add package Betalgo.OpenAI --version 8.7.2
NuGet\Install-Package Betalgo.OpenAI -Version 8.7.2
<PackageReference Include="Betalgo.OpenAI" Version="8.7.2" />
paket add Betalgo.OpenAI --version 8.7.2
#r "nuget: Betalgo.OpenAI, 8.7.2"
// Install Betalgo.OpenAI as a Cake Addin #addin nuget:?package=Betalgo.OpenAI&version=8.7.2 // Install Betalgo.OpenAI as a Cake Tool #tool nuget:?package=Betalgo.OpenAI&version=8.7.2
Overview
A .NET Library for accessing OpenAI's API, provided as a community library. This Library allows you to integrate OpenAI's capabilities into your .NET applications with ease.
⭐ We appreciate your star, it helps!
Community Links
We have a very new and channel. Please come and help us build the .NET AI community.
Install Packages
Core Library
Install-Package Betalgo.OpenAI
Experimental Utilities Library
Install-Package Betalgo.OpenAI.Utilities
Documentation and Links
API Documentation
Acknowledgements
Maintenance of this project is made possible by all the bug reporters, contributors, and sponsors.
💖 Sponsors:
@betalgo, Laser Cat Eyes
@tylerje, @oferavnery, @MayDay-wpf, @AnukarOP, @Removable, @Scar11
Sample Usage
The repository contains a sample project named OpenAI.Playground to help you understand how the library works. However, please exercise caution while experimenting, as some test methods may result in unintended consequences such as file deletion or fine-tuning.
!! It is highly recommended that you use a separate account instead of your primary account while using the playground. Some test methods may add or delete your files and models, potentially causing unwanted issues. !!
Your API Key can be obtained from here: https://platform.openai.com/account/api-keys
Your Organization ID can be found here: https://platform.openai.com/account/org-settings
Without Using Dependency Injection
var openAiService = new OpenAIService(new OpenAiOptions()
{
ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY")
});
Using Dependency Injection
secrets.json
"OpenAIServiceOptions": {
"ApiKey": "Your api key goes here",
"Organization": "Your Organization Id goes here (optional)",
"UseBeta": "true/false (optional)"
}
(To use user secrets: Right-click your project name in "Solution Explorer", then click "Manage User Secrets". This is a good way to keep your API keys secure.)
Program.cs
serviceCollection.AddOpenAIService();
OR
serviceCollection.AddOpenAIService(settings => { settings.ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY"); });
After injecting your service, you can retrieve it from the service provider:
var openAiService = serviceProvider.GetRequiredService<IOpenAIService>();
You can set a default model (optional):
openAiService.SetDefaultModelId(Models.Gpt_4o);
Chat GPT Sample
var completionResult = await openAiService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are a helpful assistant."),
ChatMessage.FromUser("Who won the world series in 2020?"),
ChatMessage.FromAssistant("The Los Angeles Dodgers won the World Series in 2020."),
ChatMessage.FromUser("Where was it played?")
},
Model = Models.Gpt_4o,
});
if (completionResult.Successful)
{
Console.WriteLine(completionResult.Choices.First().Message.Content);
}
Notes
Due to time constraints, not all methods have been thoroughly tested or fully documented. If you encounter any issues, please report them or submit a pull request. Your contributions are always appreciated.
Needless to say, I cannot accept responsibility for any damage caused by using the library.
Changelog
8.7.2
- Fixed incorrect Azure Urls.
- Token usage response extended with
PromptTokensDetails
,audio_tokens
andcached_tokens
. - Model list extended with
Gpt_4o_2024_08_06
andChatgpt_4o_latest
.
8.7.1
- moved
strict
paremeter fromToolDefinition
toFunctionDefinition
8.7.0
- Added Support for o1 reasing models (
o1-mini
ando1-preview
). - Added
MaxCompletionTokens
forchat completions
. - Added support for
ParallelToolCalls
forchat completions
. - Added support for
ServiceTier
forchat completions
. - Added support for
ChunkingStrategy
inVector Store
andVector Store Files
. - Added support for
Strict
inToolDefinition
. - Added support for
MaxNumberResults
andRankingOptions
forFileSearchTool
. - Added support for
ReasoningTokens
fortoken usage
. - Added support for
ResponseFormatOneOfType
forAssistantResponse.cs
.
More Change Logs
For any issues, contributions, or feedback, feel free to reach out or submit a pull request.
Betalgo X: Betalgo (@Betalgo) / X (twitter.com)
Betalgo Linkedin: Betalgo | LinkedIn
Tolga X: Tolga Kayhan (@kayhantolga) / X (twitter.com)
Tolga Linkedin: Tolga Kayhan | LinkedIn
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. 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 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- System.Net.Http.Json (>= 8.0.0)
-
net6.0
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
-
net7.0
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
NuGet packages (18)
Showing the top 5 NuGet packages that depend on Betalgo.OpenAI:
Package | Downloads |
---|---|
Soenneker.OpenAI.Client
An async thread-safe singleton for the OpenAI client by Betalgo |
|
Betalgo.OpenAI.Utilities
Utility tools for Betalgo.OpenAI - Dotnet SDK for OpenAI ChatGPT, Whisper, GPT-4 and DALL·E |
|
Squidex.CLI.Core
Command Line Interface for Squidex Headless CMS |
|
OuroborosAI.Core
Powerful layer on top of OpenAI supporting chaining and recursion scenarios. Includes fluent SDK for chaining, templates, and text processing. Still very early an .NET 7 only; Docs and broader support to follow. |
|
JS.Abp.AI.OpenAI
Package Description |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on Betalgo.OpenAI:
Repository | Stars |
---|---|
betalgo/openai
.NET library for the OpenAI service API by Betalgo Ranul
|
|
cmu-sei/GHOSTS
GHOSTS is a realistic user simulation framework for cyber experimentation, simulation, training, and exercise
|
|
FireCubeStudios/Clippy
Bring back Clippy on Windows 10/11!
|
|
MayDay-wpf/AIBotPublic
AIBot PRO 是一个基于.NET 6 的 AI聚合客户端 to C 弱 to B 可以集成众多AI产品(ChatGPT,Gemini,Claude,文心一言,通义千问,讯飞星火),无感切换对话,支持知识库、插件开发、AI流程引擎(workflow)、以及开放平台对外输出定制化的特色AI API
|
|
FireCubeStudios/Run
WinUI 3 Run
|
Version | Downloads | Last updated | |
---|---|---|---|
8.7.2 | 17,462 | 10/10/2024 | |
8.7.1 | 14,127 | 9/24/2024 | |
8.7.0 | 944 | 9/23/2024 | |
8.6.2 | 33,221 | 8/26/2024 | |
8.6.1 | 41,490 | 7/18/2024 | |
8.6.0 | 11,832 | 7/11/2024 | |
8.5.1 | 34,102 | 6/18/2024 | |
8.5.0 | 6,951 | 6/15/2024 | |
8.4.0 | 7,406 | 6/11/2024 | |
8.3.0 | 11,206 | 6/3/2024 | |
8.2.2 | 35,105 | 5/18/2024 | |
8.1.1 | 27,733 | 4/20/2024 | |
8.1.0 | 15,095 | 4/16/2024 | |
8.0.1 | 6,192 | 4/11/2024 | |
8.0.0 | 6,440 | 4/9/2024 | |
7.4.7 | 5,998 | 4/6/2024 | |
7.4.6 | 139,048 | 2/7/2024 | |
7.4.5 | 8,805 | 2/1/2024 | |
7.4.4 | 2,828 | 1/30/2024 | |
7.4.3 | 110,195 | 12/11/2023 | |
7.4.2 | 7,298 | 12/6/2023 | |
7.4.1 | 48,332 | 11/15/2023 | |
7.4.0 | 16,023 | 11/10/2023 | |
7.3.1 | 30,900 | 10/19/2023 | |
7.2.0 | 37,134 | 10/6/2023 | |
7.1.5 | 174,631 | 8/6/2023 | |
7.1.3 | 9,116 | 7/30/2023 | |
7.0.0 | 235,265 | 5/31/2023 | |
6.8.6 | 59,293 | 5/11/2023 | |
6.8.5 | 42,551 | 4/19/2023 | |
6.8.2 | 1,083 | 3/28/2023 |