@@ -182,24 +182,27 @@ Your only goal is to retrieve a single commit message.
182
182
183
183
public async Task ChatAsync ( string prompt , string question , CancellationToken cancellation , Action < string > onUpdate )
184
184
{
185
- var finalKey = _readApiKeyFromEnv ? Environment . GetEnvironmentVariable ( _apiKey ) : _apiKey ;
186
- var server = new Uri ( _server ) ;
187
- var key = new ApiKeyCredential ( finalKey ) ;
188
- var oaiClient = _server . Contains ( "openai.azure.com/" , StringComparison . Ordinal )
189
- ? new AzureOpenAIClient ( server , key )
190
- : new OpenAIClient ( key , new ( ) { Endpoint = server } ) ;
191
- var client = oaiClient . GetChatClient ( _model ) ;
192
- var messages = new List < ChatMessage > ( ) ;
193
- messages . Add ( _model . Equals ( "o1-mini" , StringComparison . Ordinal ) ? new UserChatMessage ( prompt ) : new SystemChatMessage ( prompt ) ) ;
194
- messages . Add ( new UserChatMessage ( question ) ) ;
185
+ var key = _readApiKeyFromEnv ? Environment . GetEnvironmentVariable ( _apiKey ) : _apiKey ;
186
+ var endPoint = new Uri ( _server ) ;
187
+ var credential = new ApiKeyCredential ( key ) ;
188
+ var client = _server . Contains ( "openai.azure.com/" , StringComparison . Ordinal )
189
+ ? new AzureOpenAIClient ( endPoint , credential )
190
+ : new OpenAIClient ( credential , new ( ) { Endpoint = endPoint } ) ;
191
+
192
+ var chatClient = client . GetChatClient ( _model ) ;
193
+ var messages = new List < ChatMessage > ( )
194
+ {
195
+ _model . Equals ( "o1-mini" , StringComparison . Ordinal ) ? new UserChatMessage ( prompt ) : new SystemChatMessage ( prompt ) ,
196
+ new UserChatMessage ( question ) ,
197
+ } ;
195
198
196
199
try
197
200
{
198
201
var rsp = new OpenAIResponse ( onUpdate ) ;
199
202
200
203
if ( _streaming )
201
204
{
202
- var updates = client . CompleteChatStreamingAsync ( messages , null , cancellation ) ;
205
+ var updates = chatClient . CompleteChatStreamingAsync ( messages , null , cancellation ) ;
203
206
204
207
await foreach ( var update in updates )
205
208
{
@@ -209,7 +212,7 @@ public async Task ChatAsync(string prompt, string question, CancellationToken ca
209
212
}
210
213
else
211
214
{
212
- var completion = await client . CompleteChatAsync ( messages , null , cancellation ) ;
215
+ var completion = await chatClient . CompleteChatAsync ( messages , null , cancellation ) ;
213
216
214
217
if ( completion . Value . Content . Count > 0 )
215
218
rsp . Append ( completion . Value . Content [ 0 ] . Text ) ;
0 commit comments