Skip to content

Commit

Permalink
[.Net] fix #3203 (#3204)
Browse files Browse the repository at this point in the history
* add net6 & net8

* update

* add tools and stop sequence
  • Loading branch information
LittleLittleCloud authored and victordibia committed Jul 30, 2024
1 parent d5f9444 commit d9185c0
Show file tree
Hide file tree
Showing 36 changed files with 63 additions and 40 deletions.
3 changes: 2 additions & 1 deletion dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<Import Project="./eng/MetaInfo.props" />
<Import Project="./eng/Sign.props" />
<PropertyGroup>
<TestTargetFramework>net8.0</TestTargetFramework>
<PackageTargetFrameworks>netstandard2.0;net6.0;net8.0</PackageTargetFrameworks>
<TestTargetFrameworks>net8.0</TestTargetFrameworks>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<SignAssembly>True</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS8981;CS8600;CS8602;CS8604;CS8618;CS0219;SKEXP0054;SKEXP0050;SKEXP0110</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IncludeResourceFolder>true</IncludeResourceFolder>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS8981;CS8600;CS8602;CS8604;CS8618;CS0219;SKEXP0054;SKEXP0050;SKEXP0110</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS8981;CS8600;CS8602;CS8604;CS8618;CS0219;SKEXP0054;SKEXP0050;SKEXP0110</NoWarn>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/AutoGen.Anthropic/AutoGen.Anthropic.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>AutoGen.Anthropic</RootNamespace>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.Anthropic</RootNamespace>
</PropertyGroup>

<Import Project="$(RepoRoot)/nuget/nuget-package.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
var field = value.GetType().GetField(value.ToString());
var attribute = field.GetCustomAttribute<JsonPropertyNameAttribute>();
var attribute = field?.GetCustomAttribute<JsonPropertyNameAttribute>();

if (attribute != null)
{
Expand Down
7 changes: 5 additions & 2 deletions dotnet/src/AutoGen.Core/AutoGen.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.Core</RootNamespace>
</PropertyGroup>

Expand All @@ -17,7 +17,10 @@
<ItemGroup>
<PackageReference Include="JsonSchema.Net.Generation" Version="$(JsonSchemaVersion)" />
<PackageReference Include="System.Memory.Data" Version="8.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>AutoGen.DotnetInteractive</RootNamespace>
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public async Task<bool> StartAsync(string workingDirectory, CancellationToken ct

public bool RestoreDotnetInteractive()
{
if (this.installingDirectory is null)
{
throw new Exception("Installing directory is not set");
}

this.WriteLine("Restore dotnet interactive tool");
// write RestoreInteractive.config from embedded resource to this.workingDirectory
var assembly = Assembly.GetAssembly(typeof(InteractiveService))!;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Gemini/AutoGen.Gemini.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<Import Project="$(RepoRoot)/nuget/nuget-package.props" />
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.LMStudio/AutoGen.LMStudio.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.LMStudio</RootNamespace>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.LMStudio/LMStudioAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
{
// request.RequestUri = new Uri($"{_modelServiceUrl}{request.RequestUri.PathAndQuery}");
var uriBuilder = new UriBuilder(_modelServiceUrl);
uriBuilder.Path = request.RequestUri.PathAndQuery;
uriBuilder.Path = request.RequestUri?.PathAndQuery ?? throw new InvalidOperationException("RequestUri is null");
request.RequestUri = uriBuilder.Uri;
return base.SendAsync(request, cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Mistral/AutoGen.Mistral.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.Mistral</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
var field = value.GetType().GetField(value.ToString());
var attribute = field.GetCustomAttribute<JsonPropertyNameAttribute>();
var attribute = field?.GetCustomAttribute<JsonPropertyNameAttribute>();

if (attribute != null)
{
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/AutoGen.Mistral/MistralClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async IAsyncEnumerable<ChatCompletionResponse> StreamingChatCompletionsAs
var response = await HttpRequestRaw(HttpMethod.Post, chatCompletionRequest, streaming: true);
using var stream = await response.Content.ReadAsStreamAsync();
using StreamReader reader = new StreamReader(stream);
string line;
string? line = null;

SseEvent currentEvent = new SseEvent();
while ((line = await reader.ReadLineAsync()) != null)
Expand All @@ -67,13 +67,13 @@ public async IAsyncEnumerable<ChatCompletionResponse> StreamingChatCompletionsAs
else if (currentEvent.EventType == null)
{
var res = await JsonSerializer.DeserializeAsync<ChatCompletionResponse>(
new MemoryStream(Encoding.UTF8.GetBytes(currentEvent.Data))) ?? throw new Exception("Failed to deserialize response");
new MemoryStream(Encoding.UTF8.GetBytes(currentEvent.Data ?? string.Empty))) ?? throw new Exception("Failed to deserialize response");
yield return res;
}
else if (currentEvent.EventType != null)
{
var res = await JsonSerializer.DeserializeAsync<ErrorResponse>(
new MemoryStream(Encoding.UTF8.GetBytes(currentEvent.Data)));
new MemoryStream(Encoding.UTF8.GetBytes(currentEvent.Data ?? string.Empty)));
throw new Exception(res?.Error.Message);
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Ollama/AutoGen.Ollama.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.Ollama</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private IEnumerable<IMessage> ProcessMultiModalMessage(MultiModalMessage multiMo

// collect all the images
var images = imageMessages.SelectMany(m => ProcessImageMessage((ImageMessage)m, agent)
.SelectMany(m => (m as IMessage<Message>)?.Content.Images));
.SelectMany(m => (m as IMessage<Message>)?.Content.Images ?? []));

var message = new Message()
{
Expand Down
10 changes: 10 additions & 0 deletions dotnet/src/AutoGen.OpenAI/Agent/OpenAIChatAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ private ChatCompletionsOptions CreateChatCompletionsOptions(GenerateReplyOptions
settings.Temperature = options?.Temperature ?? settings.Temperature;
settings.MaxTokens = options?.MaxToken ?? settings.MaxTokens;

foreach (var functions in this.options.Tools)
{
settings.Tools.Add(functions);
}

foreach (var stopSequence in this.options.StopSequences)
{
settings.StopSequences.Add(stopSequence);
}

var openAIFunctionDefinitions = options?.Functions?.Select(f => f.ToOpenAIFunctionDefinition()).ToList();
if (openAIFunctionDefinitions is { Count: > 0 })
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.OpenAI/AutoGen.OpenAI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.OpenAI</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen.SemanticKernel</RootNamespace>
<NoWarn>$(NoWarn);SKEXP0110</NoWarn>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen/AutoGen.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>$(PackageTargetFrameworks)</TargetFrameworks>
<RootNamespace>AutoGen</RootNamespace>
</PropertyGroup>

Expand Down
10 changes: 7 additions & 3 deletions dotnet/src/AutoGen/Middleware/HumanInputMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HumanInputMiddleware : IMiddleware
private readonly string prompt;
private readonly string exitKeyword;
private Func<IEnumerable<IMessage>, CancellationToken, Task<bool>> isTermination;
private Func<string> getInput = Console.ReadLine;
private Func<string?> getInput = Console.ReadLine;
private Action<string> writeLine = Console.WriteLine;
public string? Name => nameof(HumanInputMiddleware);

Expand All @@ -27,7 +27,7 @@ public HumanInputMiddleware(
string exitKeyword = "exit",
HumanInputMode mode = HumanInputMode.AUTO,
Func<IEnumerable<IMessage>, CancellationToken, Task<bool>>? isTermination = null,
Func<string>? getInput = null,
Func<string?>? getInput = null,
Action<string>? writeLine = null)
{
this.prompt = prompt;
Expand Down Expand Up @@ -56,6 +56,8 @@ public async Task<IMessage> InvokeAsync(MiddlewareContext context, IAgent agent,
return new TextMessage(Role.Assistant, GroupChatExtension.TERMINATE, agent.Name);
}

input ??= string.Empty;

return new TextMessage(Role.Assistant, input, agent.Name);
}

Expand All @@ -74,6 +76,8 @@ public async Task<IMessage> InvokeAsync(MiddlewareContext context, IAgent agent,
return new TextMessage(Role.Assistant, GroupChatExtension.TERMINATE, agent.Name);
}

input ??= string.Empty;

return new TextMessage(Role.Assistant, input, agent.Name);
}

Expand All @@ -85,7 +89,7 @@ private async Task<bool> DefaultIsTermination(IEnumerable<IMessage> messages, Ca
return messages?.Last().IsGroupChatTerminateMessage() is true;
}

private string GetInput()
private string? GetInput()
{
return Console.ReadLine();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>True</IsTestProject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>True</IsTestProject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>True</IsTestProject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>True</IsTestProject>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);SKEXP0110</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>True</IsTestProject>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/AutoGen.Tests/AutoGen.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<IsTestProject>True</IsTestProject>
<NoWarn>$(NoWarn);xUnit1013;SKEXP0110</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down

0 comments on commit d9185c0

Please sign in to comment.