Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soenneker/soenneker.openai.client.chat
An async thread-safe singleton for the OpenAI Chat (completions) client
https://github.com/soenneker/soenneker.openai.client.chat
async azureopenaichatclient chat client csharp dotnet injection open-ai openai singleton util
Last synced: about 5 hours ago
JSON representation
An async thread-safe singleton for the OpenAI Chat (completions) client
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.openai.client.chat
- Owner: soenneker
- License: mit
- Created: 2024-07-12T01:02:39.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-02T06:35:42.000Z (about 1 month ago)
- Last Synced: 2024-12-02T10:08:23.779Z (about 1 month ago)
- Topics: async, azureopenaichatclient, chat, client, csharp, dotnet, injection, open-ai, openai, singleton, util
- Language: C#
- Homepage: https://soenneker.com
- Size: 445 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![](https://img.shields.io/nuget/v/soenneker.openai.client.chat.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.openai.client.chat/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.openai.client.chat/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.openai.client.chat/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/soenneker.openai.client.chat.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.openai.client.chat/)# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.OpenAI.Client.Chat
### An async thread-safe singleton for the OpenAI Chat (completions) clientThis library provides an implementation for interacting with the OpenAI service. It allows you to configure and utilize a ChatClient to perform various tasks using OpenAI's models.
For the Azure version of this: [Soenneker.Azure.OpenAI.Client.Chat](https://github.com/soenneker/soenneker.azure.openai.client.chat)
## Installation
```
dotnet add package Soenneker.OpenAI.Client.Chat
```Register:
```
builder.services.AddOpenAIChatClientAsSingleton();
````IConfiguration` values:
```
"OpenAI:ApiKey"
"OpenAI:Model"
```## Usage
```csharp
public class OpenAIService
{
private readonly IOpenAIChatClient _chatClient;public OpenAIService(IOpenAIChatClient chatClient)
{
_chatClient = chatClient;
}public async ValueTask Chat(string prompt, CancellationToken cancellationToken = default)
{
var client = await _chatClient.Get(cancellationToken);
ChatCompletion completion = await client.CompleteChatAsync(prompt);
}
}
```