@@ -182,24 +182,27 @@ Your only goal is to retrieve a single commit message.
182182
183183 public async Task ChatAsync ( string prompt , string question , CancellationToken cancellation , Action < string > onUpdate )
184184 {
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+ } ;
195198
196199 try
197200 {
198201 var rsp = new OpenAIResponse ( onUpdate ) ;
199202
200203 if ( _streaming )
201204 {
202- var updates = client . CompleteChatStreamingAsync ( messages , null , cancellation ) ;
205+ var updates = chatClient . CompleteChatStreamingAsync ( messages , null , cancellation ) ;
203206
204207 await foreach ( var update in updates )
205208 {
@@ -209,7 +212,7 @@ public async Task ChatAsync(string prompt, string question, CancellationToken ca
209212 }
210213 else
211214 {
212- var completion = await client . CompleteChatAsync ( messages , null , cancellation ) ;
215+ var completion = await chatClient . CompleteChatAsync ( messages , null , cancellation ) ;
213216
214217 if ( completion . Value . Content . Count > 0 )
215218 rsp . Append ( completion . Value . Content [ 0 ] . Text ) ;
0 commit comments