Skip to content

Commit 84c7c24

Browse files
[.Net] Add AOT compatible check for AutoGen.Core (#2858)
* add AutoGen.AotCompatibility test * add aot test * fix build error * update ps1 path
1 parent 5f29d6b commit 84c7c24

File tree

13 files changed

+118
-21
lines changed

13 files changed

+118
-21
lines changed

.github/workflows/dotnet-build.yml

+26-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ jobs:
6767
dotnet build --no-restore --configuration Release -bl /p:SignAssembly=true
6868
- name: Unit Test
6969
run: dotnet test --no-build -bl --configuration Release
70+
aot-test: # this make sure the AutoGen.Core is aot compatible
71+
strategy:
72+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
73+
matrix:
74+
os: [ ubuntu-latest ]
75+
version: [ net8.0 ]
76+
needs: build
77+
defaults:
78+
run:
79+
working-directory: dotnet
80+
81+
runs-on: ${{ matrix.os }}
82+
steps:
83+
- uses: actions/checkout@v4
84+
with:
85+
fetch-depth: 0 # fetching all
86+
87+
- name: Setup dotnet
88+
uses: actions/setup-dotnet@v4
89+
with:
90+
global-json-file: dotnet/global.json
91+
92+
- name: publish AOT testApp, assert static analysis warning count, and run the app
93+
shell: pwsh
94+
run: ./.tools/test-aot-compatibility.ps1 ${{ matrix.version }}
7095
openai-test:
7196
name: Run openai test
7297
runs-on: ubuntu-latest
@@ -75,7 +100,7 @@ jobs:
75100
run:
76101
working-directory: dotnet
77102
if: success() && (github.ref == 'refs/heads/main')
78-
needs: build
103+
needs: aot-test
79104
steps:
80105
- uses: actions/checkout@v4
81106
with:
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
param([string]$targetNetFramework)
2+
3+
$rootDirectory = Split-Path $PSScriptRoot -Parent
4+
$publishOutput = dotnet publish $rootDirectory/test/AutoGen.AotCompatibility.Tests -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
5+
6+
$actualWarningCount = 0
7+
8+
foreach ($line in $($publishOutput -split "`r`n"))
9+
{
10+
if ($line -like "*analysis warning IL*")
11+
{
12+
Write-Host $line
13+
14+
$actualWarningCount += 1
15+
}
16+
}
17+
18+
pushd $rootDirectory/test/AutoGen.AotCompatibility.Tests/bin/Release/$targetNetFramework/linux-x64
19+
20+
Write-Host "Executing test App..."
21+
./AutoGen.AotCompatibility.Tests
22+
Write-Host "Finished executing test App"
23+
24+
if ($LastExitCode -ne 0)
25+
{
26+
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
27+
}
28+
29+
popd
30+
31+
Write-Host "Actual warning count is:", $actualWarningCount
32+
$expectedWarningCount = 0
33+
34+
$testPassed = 0
35+
if ($actualWarningCount -ne $expectedWarningCount)
36+
{
37+
$testPassed = 1
38+
Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount
39+
}
40+
41+
Exit $testPassed

dotnet/AutoGen.sln

+15-8
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama", "src\AutoG
4343
EndProject
4444
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama.Tests", "test\AutoGen.Ollama.Tests\AutoGen.Ollama.Tests.csproj", "{03E31CAA-3728-48D3-B936-9F11CF6C18FE}"
4545
EndProject
46-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Ollama.Sample", "sample\AutoGen.Ollama.Sample\AutoGen.Ollama.Sample.csproj", "{93AA4D0D-6EE4-44D5-AD77-7F73A3934544}"
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Ollama.Sample", "sample\AutoGen.Ollama.Sample\AutoGen.Ollama.Sample.csproj", "{93AA4D0D-6EE4-44D5-AD77-7F73A3934544}"
4747
EndProject
48-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.SemanticKernel.Sample", "sample\AutoGen.SemanticKernel.Sample\AutoGen.SemanticKernel.Sample.csproj", "{52958A60-3FF7-4243-9058-34A6E4F55C31}"
48+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.SemanticKernel.Sample", "sample\AutoGen.SemanticKernel.Sample\AutoGen.SemanticKernel.Sample.csproj", "{52958A60-3FF7-4243-9058-34A6E4F55C31}"
4949
EndProject
50-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic", "src\AutoGen.Anthropic\AutoGen.Anthropic.csproj", "{6A95E113-B824-4524-8F13-CD0C3E1C8804}"
50+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic", "src\AutoGen.Anthropic\AutoGen.Anthropic.csproj", "{6A95E113-B824-4524-8F13-CD0C3E1C8804}"
5151
EndProject
52-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic.Tests", "test\AutoGen.Anthropic.Tests\AutoGen.Anthropic.Tests.csproj", "{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6}"
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Tests", "test\AutoGen.Anthropic.Tests\AutoGen.Anthropic.Tests.csproj", "{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6}"
5353
EndProject
54-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}"
54+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}"
55+
EndProject
56+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.AotCompatibility.Tests", "test\AutoGen.AotCompatibility.Tests\AutoGen.AotCompatibility.Tests.csproj", "{6B82F26D-5040-4453-B21B-C8D1F913CE4C}"
5557
EndProject
5658
Global
5759
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -147,6 +149,10 @@ Global
147149
{834B4E85-64E5-4382-8465-548F332E5298}.Debug|Any CPU.Build.0 = Debug|Any CPU
148150
{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.ActiveCfg = Release|Any CPU
149151
{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.Build.0 = Release|Any CPU
152+
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
153+
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
154+
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
155+
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.Build.0 = Release|Any CPU
150156
EndGlobalSection
151157
GlobalSection(SolutionProperties) = preSolution
152158
HideSolutionNode = FALSE
@@ -167,13 +173,14 @@ Global
167173
{1DFABC4A-8458-4875-8DCB-59F3802DAC65} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
168174
{D36A85F9-C172-487D-8192-6BFE5D05B4A7} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
169175
{B61388CA-DC73-4B7F-A7B2-7B9A86C9229E} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
170-
{6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
171-
{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
172-
{834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
173176
{9F9E6DED-3D92-4970-909A-70FC11F1A665} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
174177
{03E31CAA-3728-48D3-B936-9F11CF6C18FE} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
175178
{93AA4D0D-6EE4-44D5-AD77-7F73A3934544} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
176179
{52958A60-3FF7-4243-9058-34A6E4F55C31} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
180+
{6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
181+
{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
182+
{834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
183+
{6B82F26D-5040-4453-B21B-C8D1F913CE4C} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
177184
EndGlobalSection
178185
GlobalSection(ExtensibilityGlobals) = postSolution
179186
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}

dotnet/eng/Version.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
<MicrosoftNETTestSdkVersion>17.7.0</MicrosoftNETTestSdkVersion>
1313
<MicrosoftDotnetInteractive>1.0.0-beta.24229.4</MicrosoftDotnetInteractive>
1414
<MicrosoftSourceLinkGitHubVersion>8.0.0</MicrosoftSourceLinkGitHubVersion>
15-
<JsonSchemaVersion>4.0.0</JsonSchemaVersion>
15+
<JsonSchemaVersion>4.3.0.2</JsonSchemaVersion>
1616
</PropertyGroup>
1717
</Project>

dotnet/src/AutoGen.Anthropic/Converters/ContentBaseConverter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// ContentConverter.cs
33

44
using AutoGen.Anthropic.DTO;
55

6-
namespace AutoGen.Anthropic.Converters;
76

87
using System;
98
using System.Text.Json;
109
using System.Text.Json.Serialization;
10+
namespace AutoGen.Anthropic.Converters;
1111

1212
public sealed class ContentBaseConverter : JsonConverter<ContentBase>
1313
{

dotnet/src/AutoGen.Core/AutoGen.Core.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<ItemGroup>
1818
<PackageReference Include="JsonSchema.Net.Generation" Version="$(JsonSchemaVersion)" />
1919
<PackageReference Include="System.Memory.Data" Version="8.0.0" />
20+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
2021
</ItemGroup>
2122

2223
</Project>

dotnet/src/AutoGen.Core/Extension/MessageExtension.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static string FormatMessage(this IMessage message)
2525
ToolCallResultMessage toolCallResultMessage => toolCallResultMessage.FormatMessage(),
2626
AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => aggregateMessage.FormatMessage(),
2727
_ => message.ToString(),
28-
};
28+
} ?? string.Empty;
2929
}
3030

3131
public static string FormatMessage(this TextMessage message)

dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public async Task<IAgent> SelectNextSpeakerAsync(IAgent currentSpeaker, IEnumera
9595

9696
if (agentNames.Count() == 1)
9797
{
98-
return this.agents.FirstOrDefault(x => x.Name == agentNames.First());
98+
return this.agents.First(x => x.Name == agentNames.First());
9999
}
100100
}
101101

dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
</Description>
1616
</PropertyGroup>
1717

18-
<ItemGroup>
19-
<PackageReference Include="System.Memory.Data" Version="8.0.0" />
20-
</ItemGroup>
21-
2218
<ItemGroup>
2319
<ProjectReference Include="..\AutoGen.Core\AutoGen.Core.csproj" />
2420
</ItemGroup>

dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ private IEnumerable<ChatRequestMessage> ProcessMultiModalMessage(IAgent agent, M
314314

315315
private ChatMessageImageContentItem CreateChatMessageImageContentItemFromImageMessage(ImageMessage message)
316316
{
317-
return message.Data is null
317+
return message.Data is null && message.Url is not null
318318
? new ChatMessageImageContentItem(new Uri(message.Url))
319-
: new ChatMessageImageContentItem(message.Data, message.Data.MediaType);
319+
: new ChatMessageImageContentItem(message.Data, message.Data?.MediaType);
320320
}
321321

322322
private IEnumerable<ChatRequestMessage> ProcessToolCallMessage(IAgent agent, ToolCallMessage message)

dotnet/src/AutoGen/AutoGen.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="JsonSchema.Net.Generation" Version="$(JsonSchemaVersion)" />
1918
<ProjectReference Include="..\AutoGen.LMStudio\AutoGen.LMStudio.csproj" />
2019
<ProjectReference Include="..\AutoGen.Mistral\AutoGen.Mistral.csproj" />
2120
<ProjectReference Include="..\AutoGen.SemanticKernel\AutoGen.SemanticKernel.csproj" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<PublishAot>true</PublishAot>
9+
<InvariantGlobalization>true</InvariantGlobalization>
10+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
11+
<SelfContained>true</SelfContained>
12+
<IsAotCompatible>true</IsAotCompatible>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<TrimmerRootAssembly Include="AutoGen.Core" />
20+
<TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Path="$(RepoRoot)\src\%(Identity)\%(Identity).csproj" />
21+
<ProjectReference Include="@(TrimmerRootAssembly->'%(Path)')" />
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Program.cs
3+
4+
Console.WriteLine("Hello, World!");

0 commit comments

Comments
 (0)