@@ -57,7 +57,12 @@ public string Model
5757
5858 public async Task < List < string > > FetchAvailableModelsAsync ( )
5959 {
60- var allModels = GetOpenAIClient ( ) . GetOpenAIModelClient ( ) . GetModels ( ) ;
60+ var credential = new ApiKeyCredential ( ReadApiKeyFromEnv ? Environment . GetEnvironmentVariable ( ApiKey ) : ApiKey ) ;
61+ var client = Server . Contains ( "openai.azure.com/" , StringComparison . Ordinal )
62+ ? new AzureOpenAIClient ( new Uri ( Server ) , credential )
63+ : new OpenAIClient ( credential , new ( ) { Endpoint = new Uri ( Server ) } ) ;
64+
65+ var allModels = client . GetOpenAIModelClient ( ) . GetModels ( ) ;
6166 AvailableModels = new List < string > ( ) ;
6267 foreach ( var model in allModels . Value )
6368 AvailableModels . Add ( model . Id ) ;
@@ -77,15 +82,15 @@ public async Task<List<string>> FetchAvailableModelsAsync()
7782
7883 public ChatClient GetChatClient ( )
7984 {
80- return ! string . IsNullOrEmpty ( Model ) ? GetOpenAIClient ( ) . GetChatClient ( Model ) : null ;
81- }
85+ if ( string . IsNullOrEmpty ( Model ) )
86+ return null ;
8287
83- private OpenAIClient GetOpenAIClient ( )
84- {
8588 var credential = new ApiKeyCredential ( ReadApiKeyFromEnv ? Environment . GetEnvironmentVariable ( ApiKey ) : ApiKey ) ;
86- return Server . Contains ( "openai.azure.com/" , StringComparison . Ordinal )
87- ? new AzureOpenAIClient ( new Uri ( Server ) , credential , new AzureOpenAIClientOptions ( ) { UserAgentApplicationId = string . Empty } )
88- : new OpenAIClient ( credential , new ( ) { Endpoint = new Uri ( Server ) , UserAgentApplicationId = string . Empty } ) ;
89+ var client = Server . Contains ( "openai.azure.com/" , StringComparison . Ordinal )
90+ ? new AzureOpenAIClient ( new Uri ( Server ) , credential )
91+ : new OpenAIClient ( credential , new ( ) { Endpoint = new Uri ( Server ) } ) ;
92+
93+ return client . GetChatClient ( Model ) ;
8994 }
9095
9196 private string _name = string . Empty ;
0 commit comments