Skip to content

Commit e6d92ec

Browse files
committed
Upgrade to .NET 8
1 parent 7cb41ef commit e6d92ec

File tree

6 files changed

+36
-86
lines changed

6 files changed

+36
-86
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "coreclr",
77
"request": "launch",
88
"preLaunchTask": "build",
9-
"program": "${workspaceFolder}/src/Azure.AISearch.WebApp/bin/Debug/net6.0/Azure.AISearch.WebApp.dll",
9+
"program": "${workspaceFolder}/src/Azure.AISearch.WebApp/bin/Debug/net8.0/Azure.AISearch.WebApp.dll",
1010
"args": [],
1111
"cwd": "${workspaceFolder}/src/Azure.AISearch.WebApp",
1212
"stopAtEntry": false,

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dotnet.defaultSolution": "src/Azure.AISearch.sln",
33
"azureFunctions.projectSubpath": "src\\Azure.AISearch.FunctionApp.DotNet",
4-
"azureFunctions.deploySubpath": "src\\Azure.AISearch.FunctionApp.DotNet/bin/Release/net6.0/publish",
4+
"azureFunctions.deploySubpath": "src\\Azure.AISearch.FunctionApp.DotNet/bin/Release/net8.0/publish",
55
"azureFunctions.projectLanguage": "C#",
66
"azureFunctions.projectRuntime": "~4",
77
"debug.internalConsoleOptions": "neverOpen",

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"type": "func",
111111
"dependsOn": "build (functions)",
112112
"options": {
113-
"cwd": "${workspaceFolder}/src\\Azure.AISearch.FunctionApp.DotNet/bin/Debug/net6.0"
113+
"cwd": "${workspaceFolder}/src\\Azure.AISearch.FunctionApp.DotNet/bin/Debug/net8.0"
114114
},
115115
"command": "host start",
116116
"isBackground": true,
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<UserSecretsId>aspnet-Azure.AISearch.FunctionApp-f7443d62-1b7f-4015-9c0f-643ec0cf8bf6</UserSecretsId>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.12" />
10+
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.17" />
1111
<PackageReference Include="Azure.Search.Documents" Version="11.5.0-beta.5" />
1212
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
1414
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
15-
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
16-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.1" />
15+
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
16+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.17.1" />
1717
</ItemGroup>
1818
<ItemGroup>
1919
<None Update="host.json">
@@ -24,4 +24,7 @@
2424
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
2525
</None>
2626
</ItemGroup>
27+
<PropertyGroup>
28+
<NoWarn>$(NoWarn);SKEXP0050</NoWarn>
29+
</PropertyGroup>
2730
</Project>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<UserSecretsId>aspnet-Azure.AISearch.WebApp-7b22bd67-30f4-40a6-ada8-882b828f0636</UserSecretsId>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.12" />
11+
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.17" />
1212
<PackageReference Include="Azure.Search.Documents" Version="11.5.0-beta.5" />
13-
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
14-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.25" />
15-
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
16-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.1" />
13+
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
14+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.8" />
15+
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
16+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.17.1" />
1717
</ItemGroup>
1818

1919
</Project>

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

Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,16 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
8686
{
8787
// Process citations within the answer, which take the form "[doc1][doc2]..." and refer to the (1-based) index of
8888
// the citations in the tool message.
89-
foreach (var extensionMessage in answerMessage.AzureExtensionsContext.Messages.Where(m => m.Role == ChatRole.Tool))
89+
var citationIndex = 0;
90+
foreach (var citation in answerMessage.AzureExtensionsContext.Citations)
9091
{
91-
Console.WriteLine(extensionMessage.Content);
92-
var content = JsonSerializer.Deserialize<ChatResponseMessageContent>(extensionMessage.Content!);
93-
if (content?.Citations != null && content.Citations.Any())
92+
answerText = answerText.Replace($"[doc{++citationIndex}]", $"<cite>{citation.Title}</cite>", StringComparison.OrdinalIgnoreCase);
93+
searchResponse.SearchResults.Add(new SearchResult
9494
{
95-
var citationIndex = 0;
96-
foreach (var citation in content.Citations)
97-
{
98-
answerText = answerText.Replace($"[doc{++citationIndex}]", $"<cite>{citation.Title}</cite>", StringComparison.OrdinalIgnoreCase);
99-
searchResponse.SearchResults.Add(new SearchResult
100-
{
101-
DocumentId = citation.Id,
102-
DocumentTitle = citation.Title,
103-
Captions = string.IsNullOrWhiteSpace(citation.Content) ? Array.Empty<string>() : new[] { citation.Content }
104-
});
105-
}
106-
// Stop looping through the tool messages once we find the first one holding the citations.
107-
break;
108-
}
95+
DocumentId = citation.Filepath,
96+
DocumentTitle = citation.Title,
97+
Captions = string.IsNullOrWhiteSpace(citation.Content) ? Array.Empty<string>() : new[] { citation.Content }
98+
});
10999
}
110100
}
111101

@@ -114,19 +104,19 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
114104
return searchResponse;
115105
}
116106

117-
private AzureCognitiveSearchChatExtensionConfiguration GetAzureCognitiveSearchDataSource(SearchRequest request)
107+
private AzureSearchChatExtensionConfiguration GetAzureCognitiveSearchDataSource(SearchRequest request)
118108
{
119109
ArgumentNullException.ThrowIfNull(this.settings.SearchServiceUrl);
120110
ArgumentNullException.ThrowIfNull(this.settings.SearchServiceAdminKey);
121111
ArgumentNullException.ThrowIfNull(this.settings.OpenAIEndpoint);
122112
ArgumentNullException.ThrowIfNull(this.settings.OpenAIApiKey);
123113
var useDocumentsIndex = request.SearchIndex == SearchIndexType.Documents;
124-
return new AzureCognitiveSearchChatExtensionConfiguration
114+
return new AzureSearchChatExtensionConfiguration
125115
{
126116
SearchEndpoint = new Uri(this.settings.SearchServiceUrl),
127-
Key = this.settings.SearchServiceAdminKey,
117+
Authentication = new OnYourDataApiKeyAuthenticationOptions(this.settings.SearchServiceAdminKey),
128118
IndexName = useDocumentsIndex ? this.settings.SearchIndexNameBlobDocuments : this.settings.SearchIndexNameBlobChunks,
129-
FieldMappingOptions = new AzureCognitiveSearchIndexFieldMappingOptions
119+
FieldMappingOptions = new AzureSearchIndexFieldMappingOptions
130120
{
131121
ContentFieldNames = { useDocumentsIndex ? nameof(Document.Content) : nameof(DocumentChunk.Content) },
132122
TitleFieldName = useDocumentsIndex ? nameof(Document.Title) : nameof(DocumentChunk.SourceDocumentTitle),
@@ -140,78 +130,35 @@ private AzureCognitiveSearchChatExtensionConfiguration GetAzureCognitiveSearchDa
140130
Strictness = request.Strictness ?? Constants.Defaults.Strictness,
141131
DocumentCount = request.DocumentCount ?? Constants.Defaults.DocumentCount,
142132
SemanticConfiguration = request.IsSemanticSearch ? Constants.ConfigurationNames.SemanticConfigurationNameDefault : null,
143-
EmbeddingEndpoint = request.IsVectorSearch ? new Uri(new Uri(this.settings.OpenAIEndpoint), $"openai/deployments/{this.settings.OpenAIEmbeddingDeployment}/embeddings?api-version={this.settings.OpenAIApiVersion}") : null,
144-
EmbeddingKey = request.IsVectorSearch ? this.settings.OpenAIApiKey : null
133+
VectorizationSource = request.IsVectorSearch ? new OnYourDataDeploymentNameVectorizationSource(this.settings.OpenAIEmbeddingDeployment) : null
145134
};
146135
}
147136

148-
private AzureCognitiveSearchQueryType GetQueryType(SearchRequest request)
137+
private AzureSearchQueryType GetQueryType(SearchRequest request)
149138
{
150139
if (request.QueryType == QueryType.TextStandard)
151140
{
152-
return AzureCognitiveSearchQueryType.Simple;
141+
return AzureSearchQueryType.Simple;
153142
}
154143
else if (request.QueryType == QueryType.TextSemantic)
155144
{
156-
return AzureCognitiveSearchQueryType.Semantic;
145+
return AzureSearchQueryType.Semantic;
157146
}
158147
else if (request.QueryType == QueryType.Vector)
159148
{
160-
return AzureCognitiveSearchQueryType.Vector;
149+
return AzureSearchQueryType.Vector;
161150
}
162151
else if (request.QueryType == QueryType.HybridStandard)
163152
{
164-
return AzureCognitiveSearchQueryType.VectorSimpleHybrid;
153+
return AzureSearchQueryType.VectorSimpleHybrid;
165154
}
166155
else if (request.QueryType == QueryType.HybridSemantic)
167156
{
168-
return AzureCognitiveSearchQueryType.VectorSemanticHybrid;
157+
return AzureSearchQueryType.VectorSemanticHybrid;
169158
}
170159
else
171160
{
172161
throw new NotSupportedException($"Unsupported query type \"{request.QueryType}\".");
173162
}
174163
}
175-
176-
// These model classes are based on the Azure OpenAI playground and samples
177-
// to use while waiting for .NET SDK support.
178-
179-
private class ChatResponseMessageContent
180-
{
181-
[JsonPropertyName("citations")]
182-
public IList<Citation> Citations { get; set; } = new List<Citation>();
183-
184-
[JsonPropertyName("intent")]
185-
public string? Intent { get; set; } // This seems to be yet another nested JSON object, as an array of strings
186-
}
187-
188-
private class Citation
189-
{
190-
[JsonPropertyName("content")]
191-
public string? Content { get; set; }
192-
193-
[JsonPropertyName("id")]
194-
public string? Id { get; set; }
195-
196-
[JsonPropertyName("title")]
197-
public string? Title { get; set; }
198-
199-
[JsonPropertyName("filepath")]
200-
public string? Filepath { get; set; }
201-
202-
[JsonPropertyName("url")]
203-
public string? Url { get; set; }
204-
205-
[JsonPropertyName("metadata")]
206-
public CitationMetadata Metadata { get; set; } = new CitationMetadata();
207-
208-
[JsonPropertyName("chunk_id")]
209-
public string? ChunkId { get; set; }
210-
}
211-
212-
private class CitationMetadata
213-
{
214-
[JsonPropertyName("chunking")]
215-
public string? Chunking { get; set; }
216-
}
217164
}

0 commit comments

Comments
 (0)