@@ -35,7 +35,7 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
3535 ArgumentNullException . ThrowIfNull ( request . Query ) ;
3636
3737 var searchResponse = new SearchResponse ( ) ;
38- var chatCompletionsOptions = new ChatCompletionsOptions ( ) ;
38+ var chatCompletionsOptions = new ChatCompletionsOptions { DeploymentName = this . settings . OpenAIGptDeployment } ;
3939 chatCompletionsOptions . Messages . Add ( new ChatMessage ( ChatRole . System , request . SystemRoleInformation ) ) ;
4040
4141 if ( request . History != null && request . History . Any ( ) )
@@ -59,7 +59,7 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
5959 } ;
6060 }
6161
62- var serviceResponse = await this . client . GetChatCompletionsAsync ( this . settings . OpenAIGptDeployment , chatCompletionsOptions ) ;
62+ var serviceResponse = await this . client . GetChatCompletionsAsync ( chatCompletionsOptions ) ;
6363
6464 if ( serviceResponse == null || ! serviceResponse . Value . Choices . Any ( ) )
6565 {
@@ -110,10 +110,9 @@ private AzureCognitiveSearchChatExtensionConfiguration GetAzureCognitiveSearchDa
110110 ArgumentNullException . ThrowIfNull ( this . settings . OpenAIEndpoint ) ;
111111 ArgumentNullException . ThrowIfNull ( this . settings . OpenAIApiKey ) ;
112112 var useDocumentsIndex = request . SearchIndex == SearchIndexType . Documents ;
113- return new AzureCognitiveSearchChatExtensionConfiguration
113+ var configuration = new AzureCognitiveSearchChatExtensionConfiguration
114114 {
115115 SearchEndpoint = new Uri ( this . settings . SearchServiceUrl ) ,
116- SearchKey = new AzureKeyCredential ( this . settings . SearchServiceAdminKey ) ,
117116 IndexName = useDocumentsIndex ? this . settings . SearchIndexNameBlobDocuments : this . settings . SearchIndexNameBlobChunks ,
118117 FieldMappingOptions = new AzureCognitiveSearchIndexFieldMappingOptions
119118 {
@@ -126,9 +125,14 @@ private AzureCognitiveSearchChatExtensionConfiguration GetAzureCognitiveSearchDa
126125 ShouldRestrictResultScope = request . LimitToDataSource , // Limit responses to data from the data source only
127126 QueryType = GetQueryType ( request ) ,
128127 SemanticConfiguration = request . IsSemanticSearch ? Constants . ConfigurationNames . SemanticConfigurationNameDefault : null ,
129- EmbeddingEndpoint = request . IsVectorSearch ? new Uri ( new Uri ( this . settings . OpenAIEndpoint ) , $ "openai/deployments/{ this . settings . OpenAIEmbeddingDeployment } /embeddings?api-version={ this . settings . OpenAIApiVersion } ") : null ,
130- EmbeddingKey = request . IsVectorSearch ? new AzureKeyCredential ( this . settings . OpenAIApiKey ) : null
128+ EmbeddingEndpoint = request . IsVectorSearch ? new Uri ( new Uri ( this . settings . OpenAIEndpoint ) , $ "openai/deployments/{ this . settings . OpenAIEmbeddingDeployment } /embeddings?api-version={ this . settings . OpenAIApiVersion } ") : null
131129 } ;
130+ configuration . SetSearchKey ( this . settings . SearchServiceAdminKey ) ;
131+ if ( request . IsVectorSearch )
132+ {
133+ configuration . SetEmbeddingKey ( this . settings . OpenAIApiKey ) ;
134+ }
135+ return configuration ;
132136 }
133137
134138 private AzureCognitiveSearchQueryType GetQueryType ( SearchRequest request )
0 commit comments