Skip to content

Commit 31ef3d5

Browse files
committed
Update Azure.AI.OpenAI package
1 parent e80988a commit 31ef3d5

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/Azure.AISearch.WebApp/Azure.AISearch.WebApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.7" />
11+
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.9" />
1212
<PackageReference Include="Azure.Search.Documents" Version="11.5.0-beta.4" />
1313
<PackageReference Include="Azure.Storage.Blobs" Version="12.17.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.20" />

src/Azure.AISearch.WebApp/Services/AzureOpenAIEmbeddingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public AzureOpenAIEmbeddingService(AppSettings settings)
1818

1919
public async Task<IReadOnlyList<float>> GetEmbeddingAsync(string text)
2020
{
21-
var response = await this.openAIClient.GetEmbeddingsAsync(this.embeddingDeploymentName, new EmbeddingsOptions(text));
22-
return response.Value.Data[0].Embedding;
21+
var response = await this.openAIClient.GetEmbeddingsAsync(new EmbeddingsOptions(this.embeddingDeploymentName, new[] { text }));
22+
return response.Value.Data[0].Embedding.ToArray();
2323
}
2424
}

src/Azure.AISearch.WebApp/Services/AzureOpenAISearchService.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)