MyGit

betalgo/openai

Fork: 527 Star: 2900 (更新于 2024-10-31 08:48:42)

license: MIT

Language: C# .

OpenAI .NET sdk - Azure OpenAI, ChatGPT, Whisper, and DALL-E

最后发布版本: v8.7.0 ( 2024-09-23 20:48:43)

官方网址 GitHub网址

Betalgo Ranul OpenAI Github Readme banner

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! GitHub Repo stars

Community Links

We have a very new Discord and Static Badge channel. Please come and help us build the .NET AI community.

Install Packages

Core Library

Betalgo.OpenAI

Install-Package Betalgo.OpenAI

Experimental Utilities Library

Betalgo.OpenAI.Utilities

Install-Package Betalgo.OpenAI.Utilities

Documentation and Links

API Documentation

  • Betalgo.OpenAI: Static Badge
  • Betalgo.OpenAI.Utilities: Static Badge

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 and cached_tokens.
  • Model list extended with Gpt_4o_2024_08_06 and Chatgpt_4o_latest.

8.7.1

  • moved strict paremeter from ToolDefinition to FunctionDefinition

8.7.0

  • Added Support for o1 reasing models (o1-mini and o1-preview).
  • Added MaxCompletionTokens for chat completions.
  • Added support for ParallelToolCalls for chat completions.
  • Added support for ServiceTier for chat completions.
  • Added support for ChunkingStrategy in Vector Store and Vector Store Files.
  • Added support for Strict in ToolDefinition.
  • Added support for MaxNumberResults and RankingOptions for FileSearchTool.
  • Added support for ReasoningTokens for token usage.
  • Added support for ResponseFormatOneOfType for AssistantResponse.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

最近版本更新:(数据更新于 2024-10-06 23:29:10)

2024-09-23 20:48:43 v8.7.0

2024-08-26 23:24:14 v8.6.2

2024-07-19 02:38:32 v8.6.1

2024-07-19 02:37:49 v8.6.0

2024-06-18 19:27:13 v8.5.1

2024-06-16 01:16:34 v8.5.0

2024-06-11 22:33:47 v8.4.0

2024-06-04 04:33:38 v8.3.0

2024-05-19 02:46:15 v8.2.2

2024-04-21 06:18:02 v8.1.1

主题(topics):

azure-openai, chatgpt, csharp, dall-e, dotnet, gpt-3, gpt-4, openai, openai-api, sdk, whisper, whisper-ai

betalgo/openai同语言 C#最近更新仓库

2024-11-04 20:01:02 Pik-4/HsMod

2024-11-03 23:57:50 jellyfin/jellyfin

2024-10-31 10:00:36 metatube-community/jellyfin-plugin-metatube

2024-10-30 03:58:07 AlchlcDvl/TownOfUsReworked

2024-10-26 07:18:02 Azure/azure-sdk-for-net

2024-10-23 06:18:57 PowerShell/PowerShell