diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 2e679412f63..f4074b06169 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -67,6 +67,31 @@ jobs: dotnet build --no-restore --configuration Release -bl /p:SignAssembly=true - name: Unit Test run: dotnet test --no-build -bl --configuration Release + aot-test: # this make sure the AutoGen.Core is aot compatible + strategy: + fail-fast: false # ensures the entire test matrix is run, even if one permutation fails + matrix: + os: [ ubuntu-latest ] + version: [ net8.0 ] + needs: build + defaults: + run: + working-directory: dotnet + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # fetching all + + - name: Setup dotnet + uses: actions/setup-dotnet@v4 + with: + global-json-file: dotnet/global.json + + - name: publish AOT testApp, assert static analysis warning count, and run the app + shell: pwsh + run: ./.tools/test-aot-compatibility.ps1 ${{ matrix.version }} openai-test: name: Run openai test runs-on: ubuntu-latest @@ -75,7 +100,7 @@ jobs: run: working-directory: dotnet if: success() && (github.ref == 'refs/heads/main') - needs: build + needs: aot-test steps: - uses: actions/checkout@v4 with: diff --git a/dotnet/.tools/test-aot-compatibility.ps1 b/dotnet/.tools/test-aot-compatibility.ps1 new file mode 100644 index 00000000000..071edcd956d --- /dev/null +++ b/dotnet/.tools/test-aot-compatibility.ps1 @@ -0,0 +1,41 @@ +param([string]$targetNetFramework) + +$rootDirectory = Split-Path $PSScriptRoot -Parent +$publishOutput = dotnet publish $rootDirectory/test/AutoGen.AotCompatibility.Tests -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true + +$actualWarningCount = 0 + +foreach ($line in $($publishOutput -split "`r`n")) +{ + if ($line -like "*analysis warning IL*") + { + Write-Host $line + + $actualWarningCount += 1 + } +} + +pushd $rootDirectory/test/AutoGen.AotCompatibility.Tests/bin/Release/$targetNetFramework/linux-x64 + +Write-Host "Executing test App..." +./AutoGen.AotCompatibility.Tests +Write-Host "Finished executing test App" + +if ($LastExitCode -ne 0) +{ + Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode +} + +popd + +Write-Host "Actual warning count is:", $actualWarningCount +$expectedWarningCount = 0 + +$testPassed = 0 +if ($actualWarningCount -ne $expectedWarningCount) +{ + $testPassed = 1 + Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount +} + +Exit $testPassed \ No newline at end of file diff --git a/dotnet/AutoGen.sln b/dotnet/AutoGen.sln index de2549cae13..2bc106c0aca 100644 --- a/dotnet/AutoGen.sln +++ b/dotnet/AutoGen.sln @@ -43,15 +43,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama", "src\AutoG EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama.Tests", "test\AutoGen.Ollama.Tests\AutoGen.Ollama.Tests.csproj", "{03E31CAA-3728-48D3-B936-9F11CF6C18FE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Ollama.Sample", "sample\AutoGen.Ollama.Sample\AutoGen.Ollama.Sample.csproj", "{93AA4D0D-6EE4-44D5-AD77-7F73A3934544}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama.Sample", "sample\AutoGen.Ollama.Sample\AutoGen.Ollama.Sample.csproj", "{93AA4D0D-6EE4-44D5-AD77-7F73A3934544}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.SemanticKernel.Sample", "sample\AutoGen.SemanticKernel.Sample\AutoGen.SemanticKernel.Sample.csproj", "{52958A60-3FF7-4243-9058-34A6E4F55C31}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.SemanticKernel.Sample", "sample\AutoGen.SemanticKernel.Sample\AutoGen.SemanticKernel.Sample.csproj", "{52958A60-3FF7-4243-9058-34A6E4F55C31}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic", "src\AutoGen.Anthropic\AutoGen.Anthropic.csproj", "{6A95E113-B824-4524-8F13-CD0C3E1C8804}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic", "src\AutoGen.Anthropic\AutoGen.Anthropic.csproj", "{6A95E113-B824-4524-8F13-CD0C3E1C8804}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic.Tests", "test\AutoGen.Anthropic.Tests\AutoGen.Anthropic.Tests.csproj", "{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Tests", "test\AutoGen.Anthropic.Tests\AutoGen.Anthropic.Tests.csproj", "{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.AotCompatibility.Tests", "test\AutoGen.AotCompatibility.Tests\AutoGen.AotCompatibility.Tests.csproj", "{6B82F26D-5040-4453-B21B-C8D1F913CE4C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -147,6 +149,10 @@ Global {834B4E85-64E5-4382-8465-548F332E5298}.Debug|Any CPU.Build.0 = Debug|Any CPU {834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.ActiveCfg = Release|Any CPU {834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.Build.0 = Release|Any CPU + {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -167,13 +173,14 @@ Global {1DFABC4A-8458-4875-8DCB-59F3802DAC65} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} {D36A85F9-C172-487D-8192-6BFE5D05B4A7} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} {B61388CA-DC73-4B7F-A7B2-7B9A86C9229E} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} - {6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06} - {815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} - {834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9} {9F9E6DED-3D92-4970-909A-70FC11F1A665} = {18BF8DD7-0585-48BF-8F97-AD333080CE06} {03E31CAA-3728-48D3-B936-9F11CF6C18FE} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} {93AA4D0D-6EE4-44D5-AD77-7F73A3934544} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9} {52958A60-3FF7-4243-9058-34A6E4F55C31} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9} + {6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06} + {815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} + {834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9} + {6B82F26D-5040-4453-B21B-C8D1F913CE4C} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B} diff --git a/dotnet/eng/Version.props b/dotnet/eng/Version.props index ae213015471..a43da436b38 100644 --- a/dotnet/eng/Version.props +++ b/dotnet/eng/Version.props @@ -12,6 +12,6 @@ 17.7.0 1.0.0-beta.24229.4 8.0.0 - 4.0.0 + 4.3.0.2 \ No newline at end of file diff --git a/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs b/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs index 281274048ed..4cb8fdbb34e 100644 --- a/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs +++ b/dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs @@ -1,13 +1,13 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // ContentConverter.cs using AutoGen.Anthropic.DTO; -namespace AutoGen.Anthropic.Converters; using System; using System.Text.Json; using System.Text.Json.Serialization; +namespace AutoGen.Anthropic.Converters; public sealed class ContentBaseConverter : JsonConverter { diff --git a/dotnet/src/AutoGen.Core/AutoGen.Core.csproj b/dotnet/src/AutoGen.Core/AutoGen.Core.csproj index ebbec3f0a46..60aeb3ae3fc 100644 --- a/dotnet/src/AutoGen.Core/AutoGen.Core.csproj +++ b/dotnet/src/AutoGen.Core/AutoGen.Core.csproj @@ -17,6 +17,7 @@ + diff --git a/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs b/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs index 3dbba9668f9..d948c051752 100644 --- a/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs +++ b/dotnet/src/AutoGen.Core/Extension/MessageExtension.cs @@ -25,7 +25,7 @@ public static string FormatMessage(this IMessage message) ToolCallResultMessage toolCallResultMessage => toolCallResultMessage.FormatMessage(), AggregateMessage aggregateMessage => aggregateMessage.FormatMessage(), _ => message.ToString(), - }; + } ?? string.Empty; } public static string FormatMessage(this TextMessage message) diff --git a/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs b/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs index cd17a21f8b9..5e82931ab65 100644 --- a/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs +++ b/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs @@ -95,7 +95,7 @@ public async Task SelectNextSpeakerAsync(IAgent currentSpeaker, IEnumera if (agentNames.Count() == 1) { - return this.agents.FirstOrDefault(x => x.Name == agentNames.First()); + return this.agents.First(x => x.Name == agentNames.First()); } } diff --git a/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj b/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj index f1bb8e0afab..25cc05fec92 100644 --- a/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj +++ b/dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj @@ -15,10 +15,6 @@ - - - - diff --git a/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs b/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs index 8f1825e2fa0..246e50cc6c5 100644 --- a/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs +++ b/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs @@ -314,9 +314,9 @@ private IEnumerable ProcessMultiModalMessage(IAgent agent, M private ChatMessageImageContentItem CreateChatMessageImageContentItemFromImageMessage(ImageMessage message) { - return message.Data is null + return message.Data is null && message.Url is not null ? new ChatMessageImageContentItem(new Uri(message.Url)) - : new ChatMessageImageContentItem(message.Data, message.Data.MediaType); + : new ChatMessageImageContentItem(message.Data, message.Data?.MediaType); } private IEnumerable ProcessToolCallMessage(IAgent agent, ToolCallMessage message) diff --git a/dotnet/src/AutoGen/AutoGen.csproj b/dotnet/src/AutoGen/AutoGen.csproj index 7e14ad4e73f..c54b7c84a3b 100644 --- a/dotnet/src/AutoGen/AutoGen.csproj +++ b/dotnet/src/AutoGen/AutoGen.csproj @@ -15,7 +15,6 @@ - diff --git a/dotnet/test/AutoGen.AotCompatibility.Tests/AutoGen.AotCompatibility.Tests.csproj b/dotnet/test/AutoGen.AotCompatibility.Tests/AutoGen.AotCompatibility.Tests.csproj new file mode 100644 index 00000000000..aec9660bb92 --- /dev/null +++ b/dotnet/test/AutoGen.AotCompatibility.Tests/AutoGen.AotCompatibility.Tests.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + enable + enable + true + true + True + true + true + + + + + + + + + + + + diff --git a/dotnet/test/AutoGen.AotCompatibility.Tests/Program.cs b/dotnet/test/AutoGen.AotCompatibility.Tests/Program.cs new file mode 100644 index 00000000000..ad2b881ef6c --- /dev/null +++ b/dotnet/test/AutoGen.AotCompatibility.Tests/Program.cs @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Program.cs + +Console.WriteLine("Hello, World!");