Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to .NET 9.0 and update Azure SDK, SK and other packages #394

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions app/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Azure.AI.FormRecognizer" Version="4.1.0" />
<PackageVersion Include="Azure.AI.OpenAI" Version="1.0.0-beta.17" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
<PackageVersion Include="Azure.Identity" Version="1.12.0" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.2.0-beta.1" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.4.0" />
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
<PackageVersion Include="Azure.Search.Documents" Version="11.6.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.23.0" />
<PackageVersion Include="Azure.Storage.Files.Shares" Version="12.19.1" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.19.1" />
<PackageVersion Include="Blazor.LocalStorage.WebAssembly" Version="8.0.0" />
Expand All @@ -20,32 +20,31 @@
<PackageVersion Include="CommunityToolkit.Maui" Version="7.0.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Markdig" Version="0.37.0" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.8" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="8.0.8" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.6.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.4" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.5" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.8" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageVersion Include="Microsoft.ML" Version="3.0.1" />
<PackageVersion Include="Microsoft.ML" Version="4.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.17.2" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.38.0" />
<PackageVersion Include="MudBlazor" Version="6.11.1" />
<PackageVersion Include="PdfSharpCore" Version="1.3.65" />
<PackageVersion Include="Pinecone.NET" Version="2.1.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
Expand Down
4 changes: 2 additions & 2 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 443

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY ["Directory.Build.props", "."]
COPY ["Directory.Packages.props", "."]
Expand Down
10 changes: 2 additions & 8 deletions app/SharedWebComponents/SharedWebComponents.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blazor.LocalStorage.WebAssembly" />
<PackageReference Include="Blazor.SessionStorage.WebAssembly" />
Expand All @@ -21,13 +18,10 @@
<PackageReference Include="MudBlazor" />
<PackageReference Include="System.Linq.Async" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\shared\Shared\Shared.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DOTNET_EXPERIMENTAL_HOST_PATH>C:\Program Files\dotnet\dotnet.exe</DOTNET_EXPERIMENTAL_HOST_PATH>
<SdkResolverMSBuildTaskHostRuntimeVersion>9.0.2</SdkResolverMSBuildTaskHostRuntimeVersion>
</PropertyGroup>
</Project>
4 changes: 3 additions & 1 deletion app/backend/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using OpenAI;

namespace MinimalApi.Extensions;

internal static class ServiceCollectionExtensions
Expand Down Expand Up @@ -61,7 +63,7 @@ internal static IServiceCollection AddAzureServices(this IServiceCollection serv
var azureOpenAiServiceEndpoint = config["AzureOpenAiServiceEndpoint"];
ArgumentNullException.ThrowIfNullOrEmpty(azureOpenAiServiceEndpoint);

var openAIClient = new OpenAIClient(new Uri(azureOpenAiServiceEndpoint), s_azureCredential);
var openAIClient = new AzureOpenAIClient(new Uri(azureOpenAiServiceEndpoint), s_azureCredential);

return openAIClient;
}
Expand Down
48 changes: 27 additions & 21 deletions app/backend/Extensions/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using OpenAI;

namespace MinimalApi.Extensions;

internal static class WebApplicationExtensions
Expand Down Expand Up @@ -43,29 +45,26 @@ private static async IAsyncEnumerable<ChatChunkResponse> OnPostChatPromptAsync(
[EnumeratorCancellation] CancellationToken cancellationToken)
{
var deploymentId = config["AZURE_OPENAI_CHATGPT_DEPLOYMENT"];
var response = await client.GetChatCompletionsStreamingAsync(
new ChatCompletionsOptions
{
DeploymentName = deploymentId,
Messages =
{
new ChatRequestSystemMessage("""
var chatClient = client.GetChatClient(deploymentId);
var messages = new List<OpenAI.Chat.ChatMessage>
{
new OpenAI.Chat.SystemChatMessage("""
You're an AI assistant for developers, helping them write code more efficiently.
You're name is **Blazor 📎 Clippy** and you're an expert Blazor developer.
You're also an expert in ASP.NET Core, C#, TypeScript, and even JavaScript.
You will always reply with a Markdown formatted response.
"""),
new ChatRequestUserMessage("What's your name?"),
new ChatRequestAssistantMessage("Hi, my name is **Blazor 📎 Clippy**! Nice to meet you."),
new ChatRequestUserMessage(prompt.Prompt)
}
}, cancellationToken);
new OpenAI.Chat.SystemChatMessage(@"What's your name?"),
new OpenAI.Chat.AssistantChatMessage(@"Hi, my name is **Blazor 📎 Clippy**! Nice to meet you."),
new OpenAI.Chat.UserChatMessage(prompt.Prompt)
};
var response = chatClient.CompleteChatStreamingAsync(messages: messages, cancellationToken: cancellationToken);

await foreach (var choice in response.WithCancellation(cancellationToken))
{
if (choice.ContentUpdate is { Length: > 0 })
if (choice.ContentUpdate is { Count: > 0 })
{
yield return new ChatChunkResponse(choice.ContentUpdate.Length, choice.ContentUpdate);
yield return new ChatChunkResponse(choice.ContentUpdate.Count, choice.ContentUpdate.ToString()!);
}
}
}
Expand Down Expand Up @@ -146,14 +145,21 @@ private static async Task<IResult> OnPostImagePromptAsync(
IConfiguration config,
CancellationToken cancellationToken)
{
var result = await client.GetImageGenerationsAsync(new ImageGenerationOptions
{
Prompt = prompt.Prompt,
},
cancellationToken);
//ToDo: update image generation model name
var imageGenerationModelName = config["AZURE_OPENAI_IMAGE_DEPLOYMENT"] ?? "dall-e-3";
Console.WriteLine(@$"===============================
Image generation model name: {imageGenerationModelName}
=============================================");
var imageClient = client.GetImageClient(imageGenerationModelName);

var result = await imageClient.GenerateImageAsync(prompt.Prompt);

var imageUrls = result.Value.Data.Select(i => i.Url).ToList();
var response = new ImageResponse(result.Value.Created, imageUrls);
var imageUrls = new List<Uri>
{
result.Value.ImageUri
};
//var response = new ImageResponse(result.Value..Created, imageUrls);
var response = new ImageResponse(DateTime.Now, imageUrls);

return TypedResults.Ok(response);
}
Expand Down
9 changes: 2 additions & 7 deletions app/backend/MinimalApi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
Expand All @@ -11,7 +10,6 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<PublishRelease>true</PublishRelease>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.FormRecognizer" />
<PackageReference Include="Azure.AI.OpenAI" />
Expand All @@ -24,14 +22,11 @@
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" />
<PackageReference Include="Microsoft.ML" />
<PackageReference Include="Microsoft.SemanticKernel" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
<PackageReference Include="PdfSharpCore" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\frontend\ClientApp.csproj" />
<ProjectReference Include="..\shared\Shared\Shared.csproj" />
</ItemGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion app/backend/Services/ReadRetrieveReadChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Embeddings;
using OpenAI;

namespace MinimalApi.Services;
#pragma warning disable SKEXP0011 // Mark members as static
Expand Down Expand Up @@ -84,7 +85,7 @@ public async Task<ChatAppResponse> ReplyAsync(
string? query = null;
if (overrides?.RetrievalMode != RetrievalMode.Vector)
{
var getQueryChat = new ChatHistory(@"You are a helpful AI assistant, generate search query for followup question.
var getQueryChat = new ChatHistory(@"You are a helpful AI assistant, generate search query for follow up question.
Make your respond simple and precise. Return the query only, do not return any other text.
e.g.
Northwind Health Plus AND standard plan.
Expand Down
9 changes: 2 additions & 7 deletions app/frontend/ClientApp.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UserSecretsId>48daa172-8fe4-4b81-94b2-0d5a3a5ad30e</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazor.LocalStorage.WebAssembly" />
<PackageReference Include="Blazor.SessionStorage.WebAssembly" />
Expand All @@ -19,14 +17,11 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SharedWebComponents\SharedWebComponents.csproj" />
<ProjectReference Include="..\shared\Shared\Shared.csproj" />
</ItemGroup>

<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion app/functions/EmbedFunctions/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using OpenAI;

var host = new HostBuilder()
.ConfigureServices(services =>
Expand Down Expand Up @@ -70,7 +71,7 @@ uri is not null
{
var openaiEndPoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new ArgumentNullException("AZURE_OPENAI_ENDPOINT is null");
embeddingModelName = Environment.GetEnvironmentVariable("AZURE_OPENAI_EMBEDDING_DEPLOYMENT") ?? throw new ArgumentNullException("AZURE_OPENAI_EMBEDDING_DEPLOYMENT is null");
openAIClient = new OpenAIClient(new Uri(openaiEndPoint), new DefaultAzureCredential());
openAIClient = new AzureOpenAIClient(new Uri(openaiEndPoint), new DefaultAzureCredential());
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion app/prepdocs/PrepareDocs/Program.Clients.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using OpenAI;

internal static partial class Program
{
private static BlobContainerClient? s_corpusContainerClient;
Expand Down Expand Up @@ -178,7 +180,7 @@ private static Task<OpenAIClient> GetOpenAIClientAsync(AppOptions options) =>
{
var endpoint = o.AzureOpenAIServiceEndpoint;
ArgumentNullException.ThrowIfNullOrEmpty(endpoint);
s_openAIClient = new OpenAIClient(
s_openAIClient = new AzureOpenAIClient(
new Uri(endpoint),
DefaultCredential);
}
Expand Down
5 changes: 2 additions & 3 deletions app/shared/Shared/Models/ResponseChoice.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Text.Json.Serialization;
using Azure.AI.OpenAI;

namespace Shared.Models;

Expand Down Expand Up @@ -44,8 +43,8 @@ public record ResponseChoice(
[property: JsonPropertyName("context")] ResponseContext Context,
[property: JsonPropertyName("citationBaseUrl")] string CitationBaseUrl)
{
[JsonPropertyName("content_filter_results")]
public ContentFilterResult? ContentFilterResult { get; set; }
//[JsonPropertyName("content_filter_results")]
//public ContentFilterResult? ContentFilterResult { get; set; }

}

Expand Down
8 changes: 4 additions & 4 deletions app/shared/Shared/Services/AzureSearchEmbedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
using System.Text.RegularExpressions;
using Azure;
using Azure.AI.FormRecognizer.DocumentAnalysis;
using Azure.AI.OpenAI;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using Azure.Search.Documents.Models;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Microsoft.Extensions.Logging;
using OpenAI;
using Shared.Models;

public sealed partial class AzureSearchEmbedService(
Expand Down Expand Up @@ -449,8 +449,9 @@ private async Task IndexSectionsAsync(IEnumerable<Section> sections)
var batch = new IndexDocumentsBatch<SearchDocument>();
foreach (var section in sections)
{
var embeddings = await openAIClient.GetEmbeddingsAsync(new Azure.AI.OpenAI.EmbeddingsOptions(embeddingModelName, [section.Content.Replace('\r', ' ')]));
var embedding = embeddings.Value.Data.FirstOrDefault()?.Embedding.ToArray() ?? [];
var embeddingsClient = openAIClient.GetEmbeddingClient(embeddingModelName);
var embeddings = await embeddingsClient.GenerateEmbeddingAsync(input: section.Content.Replace('\r', ' '));
var embedding = embeddings.Value.ToFloats(); // .Value.Data.FirstOrDefault()?.Embedding.ToArray() ?? [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment at the end of this needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that was part of the package upgrade tests, deleted the unused comment.

batch.Actions.Add(new IndexDocumentsAction<SearchDocument>(
IndexActionType.MergeOrUpload,
new SearchDocument
Expand Down Expand Up @@ -494,5 +495,4 @@ private async Task IndexSectionsAsync(IEnumerable<Section> sections)
}
}
}

}
Loading
Loading