@@ -57,12 +57,7 @@ public string Model
5757
5858 public async Task < List < string > > FetchAvailableModelsAsync ( )
5959 {
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 ( ) ;
60+ var allModels = GetOpenAIClient ( ) . GetOpenAIModelClient ( ) . GetModels ( ) ;
6661 AvailableModels = new List < string > ( ) ;
6762 foreach ( var model in allModels . Value )
6863 AvailableModels . Add ( model . Id ) ;
@@ -82,15 +77,15 @@ public async Task<List<string>> FetchAvailableModelsAsync()
8277
8378 public ChatClient GetChatClient ( )
8479 {
85- if ( string . IsNullOrEmpty ( Model ) )
86- return null ;
80+ return ! string . IsNullOrEmpty ( Model ) ? GetOpenAIClient ( ) . GetChatClient ( Model ) : null ;
81+ }
8782
83+ private OpenAIClient GetOpenAIClient ( )
84+ {
8885 var credential = new ApiKeyCredential ( ReadApiKeyFromEnv ? Environment . GetEnvironmentVariable ( ApiKey ) : ApiKey ) ;
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 ) ;
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 } ) ;
9489 }
9590
9691 private string _name = string . Empty ;
0 commit comments