Skip to content

Commit a35be79

Browse files
chore: update README to use ChatClient instead of OpenAIClient
1 parent c488445 commit a35be79

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ AudioClient whisperClient = client.GetAudioClient("whisper-1");
143143

144144
The OpenAI clients are **thread-safe** and can be safely registered as **singletons** in ASP.NET Core's Dependency Injection container. This maximizes resource efficiency and HTTP connection reuse.
145145

146-
Register the `OpenAIClient` as a singleton in your `Program.cs`:
146+
Register the `ChatClient` as a singleton in your `Program.cs`:
147147

148148
```csharp
149-
builder.Services.AddSingleton<OpenAIClient>(serviceProvider =>
149+
builder.Services.AddSingleton<ChatClient>(serviceProvider =>
150150
{
151151
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
152152

153-
return new OpenAIClient(apiKey);
153+
return new ChatClient(apiKey);
154154
});
155155
```
156156

@@ -161,18 +161,17 @@ Then inject and use the client in your controllers or services:
161161
[Route("api/[controller]")]
162162
public class ChatController : ControllerBase
163163
{
164-
private readonly OpenAIClient _openAIClient;
164+
private readonly ChatClient _chatClient;
165165

166-
public ChatController(OpenAIClient openAIClient)
166+
public ChatController(ChatClient chatClient)
167167
{
168-
_openAIClient = openAIClient;
168+
_chatClient = chatClient;
169169
}
170170

171171
[HttpPost("complete")]
172172
public async Task<IActionResult> CompleteChat([FromBody] string message)
173173
{
174-
ChatClient chatClient = _openAIClient.GetChatClient("gpt-4o");
175-
ChatCompletion completion = await chatClient.CompleteChatAsync(message);
174+
ChatCompletion completion = await _chatClient.CompleteChatAsync(message);
176175

177176
return Ok(new { response = completion.Content[0].Text });
178177
}

0 commit comments

Comments
 (0)