Skip to content

Commit

Permalink
Fix Aspire code related warnings (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc authored Dec 6, 2024
1 parent 41d5111 commit 695fddb
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 50 deletions.
14 changes: 7 additions & 7 deletions KernelMemory.sln
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "all-azure", "tools\aspire\a
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "volatile-openai", "tools\aspire\volatile-openai\volatile-openai.csproj", "{D81B99FF-E13D-4127-AC01-4BF0C8B02C71}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Extensions", "tools\aspire\Aspire.Extensions\Aspire.Extensions.csproj", "{4E5BAA7B-7DB6-4F24-8D91-E9C3AC9773E7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dev", "dev", "{3C1C483D-2C09-4B0D-9394-82B2AF1D61F1}"
ProjectSection(SolutionItems) = preProject
tools\dev\build.sh = tools\dev\build.sh
Expand All @@ -360,6 +358,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "km-cli", "km-cli", "{239F5F
tools\km-cli\upload-file.sh = tools\km-cli\upload-file.sh
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire", "extensions\Aspire\Aspire\Aspire.csproj", "{41A5A076-B35D-4191-B98C-65AD5782A108}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -661,10 +661,10 @@ Global
{D81B99FF-E13D-4127-AC01-4BF0C8B02C71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D81B99FF-E13D-4127-AC01-4BF0C8B02C71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D81B99FF-E13D-4127-AC01-4BF0C8B02C71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E5BAA7B-7DB6-4F24-8D91-E9C3AC9773E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E5BAA7B-7DB6-4F24-8D91-E9C3AC9773E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E5BAA7B-7DB6-4F24-8D91-E9C3AC9773E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E5BAA7B-7DB6-4F24-8D91-E9C3AC9773E7}.Release|Any CPU.Build.0 = Release|Any CPU
{41A5A076-B35D-4191-B98C-65AD5782A108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41A5A076-B35D-4191-B98C-65AD5782A108}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41A5A076-B35D-4191-B98C-65AD5782A108}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41A5A076-B35D-4191-B98C-65AD5782A108}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -770,11 +770,11 @@ Global
{07A91D09-CA4D-425F-83AD-F955336AACD7} = {CA49F1A1-C3FA-4E99-ACB3-D7FF33D47976}
{6E5EB6F3-17E2-4C71-B35A-5F8F0B7E407F} = {07A91D09-CA4D-425F-83AD-F955336AACD7}
{D81B99FF-E13D-4127-AC01-4BF0C8B02C71} = {07A91D09-CA4D-425F-83AD-F955336AACD7}
{4E5BAA7B-7DB6-4F24-8D91-E9C3AC9773E7} = {07A91D09-CA4D-425F-83AD-F955336AACD7}
{3C1C483D-2C09-4B0D-9394-82B2AF1D61F1} = {CA49F1A1-C3FA-4E99-ACB3-D7FF33D47976}
{239F5FE9-EAEE-4FA7-A3D5-09608FBA6EED} = {CA49F1A1-C3FA-4E99-ACB3-D7FF33D47976}
{CA49F1A1-C3FA-4E99-ACB3-D7FF33D47976} = {6EF76FD8-4C35-4370-8539-5DDF45357A50}
{7BA7F1B2-19E2-46EB-B000-513EE2F65769} = {6EF76FD8-4C35-4370-8539-5DDF45357A50}
{41A5A076-B35D-4191-B98C-65AD5782A108} = {155DA079-E267-49AF-973A-D1D44681970F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC136C62-115C-41D1-B414-F9473EFF6EA8}
Expand Down
5 changes: 2 additions & 3 deletions examples/303-dotnet-aspire/303-dotnet-aspire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<RootNamespace>Microsoft.KernelMemory.Aspire.AppHost</RootNamespace>
<AssemblyName>Microsoft.KernelMemory.Aspire.Example303.AppHost</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\extensions\Aspire\Aspire\Aspire.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\extensions\AzureOpenAI\AzureOpenAI\AzureOpenAI.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\extensions\OpenAI\OpenAI\OpenAI.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\service\Core\Core.csproj" IsAspireProjectResource="false" />
Expand Down
11 changes: 8 additions & 3 deletions examples/303-dotnet-aspire/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.

using Aspire.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.Aspire;
using Projects;

namespace Microsoft.KernelMemory.Aspire.AppHost;

internal static class Program
{
private const string QdrantImage = "qdrant/qdrant";
Expand Down Expand Up @@ -67,7 +69,10 @@ private static void RunFromCode()
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Endpoint", s_azureOpenAIEmbeddingConfig.Endpoint)
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Deployment", s_azureOpenAIEmbeddingConfig.Deployment);

builder.Build().Run();
builder
.ShowDashboardUrl()
.LaunchDashboard()
.Build().Run();
}

private static void RunFromDockerWithOpenAI(string openAIKey, string dockerTag = "latest")
Expand Down
32 changes: 32 additions & 0 deletions extensions/Aspire/Aspire/Aspire.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RollForward>LatestMajor</RollForward>
<AssemblyName>Microsoft.KernelMemory.Aspire</AssemblyName>
<RootNamespace>Microsoft.KernelMemory.Aspire</RootNamespace>
<NoWarn>$(NoWarn);</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\service\Core\Core.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting" />
<PackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>

<PropertyGroup>
<IsPackable>false</IsPackable>
<PackageId>Microsoft.KernelMemory.Aspire</PackageId>
<Product>.NET Aspire extensions for Kernel Memory</Product>
<Description>Make it easier to develop and work with Kernel Memory</Description>
<PackageTags>Aspire, Memory, RAG, Kernel Memory, AI, Artificial Intelligence, Embeddings, Vector DB, Vector Search, Memory DB</PackageTags>
<DocumentationFile>bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\README.md" Link="README.md" Pack="true" PackagePath="." Visible="false" />
</ItemGroup>
</Project>
43 changes: 43 additions & 0 deletions extensions/Aspire/Aspire/DashboardExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Aspire.Hosting;

namespace Microsoft.KernelMemory.Aspire;

public static class Dashboard
{
/// <summary>
/// Show Aspire dashboard URL before the logging start.
/// </summary>
public static IDistributedApplicationBuilder ShowDashboardUrl(this IDistributedApplicationBuilder builder, bool withStyle = false)
{
Console.WriteLine(withStyle
? $"\u001b[1mAspire dashboard URL: {GetUrl(builder)}\u001b[0m\n\n"
: $"Aspire dashboard URL: {GetUrl(builder)}\n\n");
return builder;
}

/// <summary>
/// Wait 5 seconds and automatically open the browser (when using 'dotnet run' the browser doesn't open)
/// </summary>
public static IDistributedApplicationBuilder LaunchDashboard(this IDistributedApplicationBuilder builder, int delay = 5000)
{
Task.Run(async () =>
{
await Task.Delay(delay).ConfigureAwait(false);
Process.Start(new ProcessStartInfo { FileName = GetUrl(builder), UseShellExecute = true });
});

return builder;
}

private static string GetUrl(IDistributedApplicationBuilder builder)
{
string token = builder.Configuration["AppHost:BrowserToken"] ?? string.Empty;
string url = builder.Configuration["ASPNETCORE_URLS"]?.Split(";")[0] ?? throw new ArgumentException("ASPNETCORE_URLS is empty");
return $"{url}/login?t={token}";
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Collections.Generic;
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Microsoft.KernelMemory.Configuration;

namespace Microsoft.KernelMemory.Aspire;

public static class AspireExtensions
public static class KernelMemoryEnvironmentExtensions
{
public static IResourceBuilder<T> WithKmServiceConfig<T>(
this IResourceBuilder<T> builder, string serviceName, object config)
Expand Down
8 changes: 8 additions & 0 deletions extensions/Aspire/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# .NET Aspire for Kernel Memory

[![Discord](https://img.shields.io/discord/1063152441819942922?label=Discord&logo=discord&logoColor=white&color=d82679)](https://aka.ms/KMdiscord)

This project contains
[.NET Aspire](https://learn.microsoft.com/dotnet/aspire)
extensions to make it easier to run Kernel Memory locally
and in the cloud.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void ItRecognizesErrorsFromNulls()
[InlineData(HttpStatusCode.Unused)] // 306
[InlineData(HttpStatusCode.RedirectKeepVerb)] // 307
[InlineData(HttpStatusCode.PermanentRedirect)] // 308
public void ItRecognizesErrors(HttpStatusCode statusCode)
public void ItRecognizesErrors1(HttpStatusCode statusCode)
{
Assert.False(statusCode.IsTransientError());
Assert.False(HttpErrors.IsTransientError((int)statusCode));
Expand Down Expand Up @@ -68,7 +68,7 @@ public void ItRecognizesErrors(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.Unused)] // 306
[InlineData(HttpStatusCode.RedirectKeepVerb)] // 307
[InlineData(HttpStatusCode.PermanentRedirect)] // 308
public void ItRecognizesErrors(HttpStatusCode? statusCode)
public void ItRecognizesErrors2(HttpStatusCode? statusCode)
{
Assert.False(statusCode.IsTransientError());
Assert.False(statusCode.IsFatalError());
Expand All @@ -85,7 +85,7 @@ public void ItRecognizesErrors(HttpStatusCode? statusCode)
[InlineData(HttpStatusCode.ServiceUnavailable)] // 503
[InlineData(HttpStatusCode.GatewayTimeout)] // 504
[InlineData(HttpStatusCode.InsufficientStorage)] // 507
public void ItRecognizesTransientErrors(HttpStatusCode statusCode)
public void ItRecognizesTransientErrors1(HttpStatusCode statusCode)
{
Assert.True(statusCode.IsTransientError());
Assert.True(HttpErrors.IsTransientError((int)statusCode));
Expand All @@ -105,7 +105,7 @@ public void ItRecognizesTransientErrors(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.ServiceUnavailable)] // 503
[InlineData(HttpStatusCode.GatewayTimeout)] // 504
[InlineData(HttpStatusCode.InsufficientStorage)] // 507
public void ItRecognizesTransientErrors(HttpStatusCode? statusCode)
public void ItRecognizesTransientErrors2(HttpStatusCode? statusCode)
{
Assert.True(statusCode.IsTransientError());
Assert.False(statusCode.IsFatalError());
Expand Down Expand Up @@ -138,7 +138,7 @@ public void ItRecognizesTransientErrors(HttpStatusCode? statusCode)
[InlineData(HttpStatusCode.LoopDetected)] // 508
[InlineData(HttpStatusCode.NotExtended)] // 510
[InlineData(HttpStatusCode.NetworkAuthenticationRequired)] // 511
public void ItRecognizesFatalErrors(HttpStatusCode statusCode)
public void ItRecognizesFatalErrors1(HttpStatusCode statusCode)
{
Assert.False(statusCode.IsTransientError());
Assert.False(HttpErrors.IsTransientError((int)statusCode));
Expand Down Expand Up @@ -174,7 +174,7 @@ public void ItRecognizesFatalErrors(HttpStatusCode statusCode)
[InlineData(HttpStatusCode.LoopDetected)] // 508
[InlineData(HttpStatusCode.NotExtended)] // 510
[InlineData(HttpStatusCode.NetworkAuthenticationRequired)] // 511
public void ItRecognizesFatalErrors(HttpStatusCode? statusCode)
public void ItRecognizesFatalErrors2(HttpStatusCode? statusCode)
{
Assert.False(statusCode.IsTransientError());
Assert.True(statusCode.IsFatalError());
Expand Down
22 changes: 0 additions & 22 deletions tools/aspire/Aspire.Extensions/Aspire.Extensions.csproj

This file was deleted.

7 changes: 6 additions & 1 deletion tools/aspire/all-azure/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Aspire.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.KernelMemory.Safety.AzureAIContentSafety;
using Projects;

Expand Down Expand Up @@ -50,6 +52,9 @@ private static void RunFromCode()
.WithKmContentSafetyModerationEnvironment("AzureAIContentSafety", s_azureAIContentSafetyConfig)
.WithKmOcrEnvironment("AzureAIDocIntel", s_azureAIDocIntelConfig);

builder.Build().Run();
builder
.ShowDashboardUrl()
.LaunchDashboard()
.Build().Run();
}
}
5 changes: 2 additions & 3 deletions tools/aspire/all-azure/all-azure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<AssemblyName>Microsoft.KernelMemory.Aspire.AllAzure.AppHost</AssemblyName>
<RootNamespace>Microsoft.KernelMemory.Aspire.AppHost</RootNamespace>
<NoWarn>$(NoWarn);IDE0058;IDE0160;</NoWarn>
</PropertyGroup>
Expand All @@ -19,8 +18,8 @@

<ItemGroup>
<ProjectReference Include="..\..\..\service\Service\Service.csproj" />
<ProjectReference Include="..\..\..\extensions\Aspire\Aspire\Aspire.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\extensions\KM\KernelMemory\KernelMemory.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\Aspire.Extensions\Aspire.Extensions.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>
7 changes: 6 additions & 1 deletion tools/aspire/volatile-openai/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Aspire.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.KernelMemory.DocumentStorage.DevTools;
using Microsoft.KernelMemory.MemoryStorage.DevTools;
using Microsoft.KernelMemory.Pipeline.Queue.DevTools;
Expand Down Expand Up @@ -46,6 +48,9 @@ private static void RunFromCode()
.WithKmContentSafetyModerationEnvironment(null) // ensure moderation is disabled
.WithKmOcrEnvironment(null); // ensure OCR is disabled;

builder.Build().Run();
builder
.ShowDashboardUrl()
.LaunchDashboard()
.Build().Run();
}
}
5 changes: 2 additions & 3 deletions tools/aspire/volatile-openai/volatile-openai.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<AssemblyName>Microsoft.KernelMemory.Aspire.Volatile.AppHost</AssemblyName>
<RootNamespace>Microsoft.KernelMemory.Aspire.AppHost</RootNamespace>
<NoWarn>$(NoWarn);IDE0058;IDE0160;</NoWarn>
</PropertyGroup>
Expand All @@ -19,8 +18,8 @@

<ItemGroup>
<ProjectReference Include="..\..\..\service\Service\Service.csproj" />
<ProjectReference Include="..\..\..\extensions\Aspire\Aspire\Aspire.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\extensions\KM\KernelMemory\KernelMemory.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\Aspire.Extensions\Aspire.Extensions.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>

0 comments on commit 695fddb

Please sign in to comment.