[.Net] update dotnet-ci and dotnet-release to use 8.0.x version when setting up .NET. And enable format check (#3136)

* use 8.0.x versin

* enable format check

* change file header

* apply code format

* add instructions in ci to fix format error

* add comment back
This commit is contained in:
Xiaoyun Zhang 2024-07-15 12:33:10 -07:00 committed by GitHub
parent 7205ccc3b9
commit 970c1961dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
42 changed files with 80 additions and 50 deletions

View File

@ -56,11 +56,16 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: dotnet/global.json
dotnet-version: '8.0.x'
- name: Restore dependencies
run: |
# dotnet nuget add source --name dotnet-tool https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json --configfile NuGet.config
dotnet restore -bl
- name: Format check
run: |
echo "Format check"
echo "If you see any error in this step, please run 'dotnet format' locally to format the code."
dotnet format --verify-no-changes -v diag --no-restore
- name: Build
run: |
echo "Build AutoGen"

View File

@ -32,7 +32,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: dotnet/global.json
dotnet-version: '8.0.x'
- name: Restore dependencies
run: |
dotnet restore -bl

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// AnthropicSamples.cs
// Create_Anthropic_Agent.cs
using AutoGen.Anthropic.Extensions;
using AutoGen.Anthropic.Utils;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Single_Anthropic_Tool.cs
// Create_Anthropic_Agent_With_Tool.cs
using AutoGen.Anthropic.DTO;
using AutoGen.Anthropic.Extensions;

View File

@ -20,8 +20,7 @@ public class MiddlewareAgentCodeSnippet
var middlewareAgent = new MiddlewareAgent(innerAgent: agent);
middlewareAgent.Use(async (messages, options, agent, ct) =>
{
var lastMessage = messages.Last() as TextMessage;
if (lastMessage != null && lastMessage.Content.Contains("Hello World"))
if (messages.Last() is TextMessage lastMessage && lastMessage.Content.Contains("Hello World"))
{
lastMessage.Content = $"[middleware 0] {lastMessage.Content}";
return lastMessage;
@ -39,8 +38,7 @@ public class MiddlewareAgentCodeSnippet
#region register_middleware_agent
middlewareAgent = agent.RegisterMiddleware(async (messages, options, agent, ct) =>
{
var lastMessage = messages.Last() as TextMessage;
if (lastMessage != null && lastMessage.Content.Contains("Hello World"))
if (messages.Last() is TextMessage lastMessage && lastMessage.Content.Contains("Hello World"))
{
lastMessage.Content = $"[middleware 0] {lastMessage.Content}";
return lastMessage;

View File

@ -17,14 +17,18 @@ public partial class Example04_Dynamic_GroupChat_Coding_Task
// setup dotnet interactive
var workDir = Path.Combine(Path.GetTempPath(), "InteractiveService");
if (!Directory.Exists(workDir))
{
Directory.CreateDirectory(workDir);
}
using var service = new InteractiveService(workDir);
var dotnetInteractiveFunctions = new DotnetInteractiveFunction(service);
var result = Path.Combine(workDir, "result.txt");
if (File.Exists(result))
{
File.Delete(result);
}
await service.StartAsync(workDir, default);

View File

@ -225,7 +225,9 @@ public partial class Example07_Dynamic_GroupChat_Calculate_Fibonacci
long the39thFibonacciNumber = 63245986;
var workDir = Path.Combine(Path.GetTempPath(), "InteractiveService");
if (!Directory.Exists(workDir))
{
Directory.CreateDirectory(workDir);
}
using var service = new InteractiveService(workDir);
var dotnetInteractiveFunctions = new DotnetInteractiveFunction(service);
@ -329,7 +331,9 @@ public partial class Example07_Dynamic_GroupChat_Calculate_Fibonacci
long the39thFibonacciNumber = 63245986;
var workDir = Path.Combine(Path.GetTempPath(), "InteractiveService");
if (!Directory.Exists(workDir))
{
Directory.CreateDirectory(workDir);
}
using var service = new InteractiveService(workDir);
var dotnetInteractiveFunctions = new DotnetInteractiveFunction(service);

View File

@ -1,3 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Example13_OpenAIAgent_JsonMode.cs
// this example has been moved to https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.OpenAI.Sample/Use_Json_Mode.cs
// this example has been moved to https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.OpenAI.Sample/Use_Json_Mode.cs

View File

@ -50,7 +50,9 @@ public static class Example15_GPT4V_BinaryDataImageMessage
foreach (string file in Directory.GetFiles(imageResourcePath))
{
if (!_mediaTypeMappings.TryGetValue(Path.GetExtension(file).ToLowerInvariant(), out var mediaType))
{
continue;
}
using var fs = new FileStream(file, FileMode.Open, FileAccess.Read);
var ms = new MemoryStream();

View File

@ -1,3 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Example16_OpenAIChatAgent_ConnectToThirdPartyBackend.cs
// this example has been moved to https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.OpenAI.Sample/Connect_To_Ollama.cs
// this example has been moved to https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.OpenAI.Sample/Connect_To_Ollama.cs

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Dynamic_GroupChat.cs
// Dynamic_Group_Chat.cs
using AutoGen.Core;
using AutoGen.OpenAI;

View File

@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Example16_OpenAIChatAgent_ConnectToThirdPartyBackend.cs
// Connect_To_Ollama.cs
#region using_statement
using AutoGen.Core;
using AutoGen.OpenAI.Extension;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Example13_OpenAIAgent_JsonMode.cs
// Use_Json_Mode.cs
using System.Text.Json;
using System.Text.Json.Serialization;

View File

@ -1,4 +1,7 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// AnthropicClientAgent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

View File

@ -48,7 +48,9 @@ public sealed class AnthropicClient : IDisposable
var responseStream = await httpResponseMessage.Content.ReadAsStreamAsync();
if (httpResponseMessage.IsSuccessStatusCode)
{
return await DeserializeResponseAsync<ChatCompletionResponse>(responseStream, cancellationToken);
}
ErrorResponse res = await DeserializeResponseAsync<ErrorResponse>(responseStream, cancellationToken);
throw new Exception(res.Error?.Message);

View File

@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// ContentConverter.cs
using AutoGen.Anthropic.DTO;
// ContentBaseConverter.cs
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using AutoGen.Anthropic.DTO;
namespace AutoGen.Anthropic.Converters;
public sealed class ContentBaseConverter : JsonConverter<ContentBase>

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// ChatCompletionRequest.cs
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace AutoGen.Anthropic.DTO;

View File

@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// ChatCompletionResponse.cs
namespace AutoGen.Anthropic.DTO;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace AutoGen.Anthropic.DTO;
public class ChatCompletionResponse
{
[JsonPropertyName("content")]

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Content.cs
using System.Text.Json.Nodes;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// ErrorResponse.cs
using System.Text.Json.Serialization;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Tool.cs
using System.Collections.Generic;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Constants.cs
// AnthropicConstants.cs
namespace AutoGen.Anthropic.Utils;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// FunctionCallAggregateMessage.cs
// ToolCallAggregateMessage.cs
using System.Collections.Generic;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IVertexGeminiClient.cs
// IGeminiClient.cs
using System.Collections.Generic;
using System.Threading;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IGeminiClient.cs
// VertexGeminiClient.cs
using System.Collections.Generic;
using System.Threading;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// ChatResponseUpdate.cs
// Message.cs
using System.Collections.Generic;
using System.Text.Json.Serialization;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// ITextEmbeddingService.cs
using System.Threading;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// OllamaTextEmbeddingService.cs
using System;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// TextEmbeddingsRequest.cs
using System.Text.Json.Serialization;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// TextEmbeddingsResponse.cs
using System.Text.Json.Serialization;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// FunctionContract.cs
// SourceGeneratorFunctionContract.cs
namespace AutoGen.SourceGenerator
{

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// OpenAIChatCompletionOption.cs
// OpenAIMessage.cs
using System.Text.Json.Serialization;

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// OpenAIStreamOptions.cs
using System.Text.Json.Serialization;

View File

@ -188,7 +188,7 @@ public class AnthropicClientAgentTest
IMessage[] chatHistory = [
new TextMessage(Role.User, "what's the weather in Philadelphia?"),
new ToolCallMessage([toolCall], from: "assistant"),
new ToolCallResultMessage([toolCall], from: "user" ),
new ToolCallResultMessage([toolCall], from: "user"),
];
var reply = await agent.SendAsync(chatHistory: chatHistory);

View File

@ -1,4 +1,7 @@
using System.Text;
// Copyright (c) Microsoft Corporation. All rights reserved.
// AnthropicClientTest.cs
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
@ -59,7 +62,9 @@ public class AnthropicClientTests
foreach (ChatCompletionResponse result in results)
{
if (result.Delta is not null && !string.IsNullOrEmpty(result.Delta.Text))
{
sb.Append(result.Delta.Text);
}
}
string resultContent = sb.ToString();

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// AnthropicTestFunctions.cs
// AnthropicTestFunctionCalls.cs
using System.Text.Json;
using System.Text.Json.Serialization;

View File

@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// GeminiAgentTests.cs
using AutoGen.Tests;
using Google.Cloud.AIPlatform.V1;
using AutoGen.Core;
using FluentAssertions;
using AutoGen.Gemini.Extension;
using static Google.Cloud.AIPlatform.V1.Part;
using AutoGen.Tests;
using FluentAssertions;
using Google.Cloud.AIPlatform.V1;
using Xunit.Abstractions;
using static Google.Cloud.AIPlatform.V1.Part;
namespace AutoGen.Gemini.Tests;
public class GeminiAgentTests

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// GeminiVertexClientTests.cs
// VertexGeminiClientTests.cs
using AutoGen.Tests;
using FluentAssertions;

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// OllamaTextEmbeddingServiceTests.cs
using AutoGen.Tests;

View File

@ -1,7 +1,9 @@
// Using directives
// Copyright (c) Microsoft Corporation. All rights reserved.
// FunctionCallTemplateEncodingTests.cs
using System.Text.Json; // Needed for JsonSerializer
using Xunit; // Needed for Fact and Assert
using AutoGen.SourceGenerator.Template; // Needed for FunctionCallTemplate
using Xunit; // Needed for Fact and Assert
namespace AutoGen.SourceGenerator.Tests
{
@ -89,4 +91,4 @@ namespace AutoGen.SourceGenerator.Tests
Assert.Contains("Description = @\"This is a \"\"parameter\"\" description\"", result);
}
}
}
}

View File

@ -1,4 +1,6 @@

// Copyright (c) Microsoft Corporation. All rights reserved.
// GraphTests.cs
using Xunit;
namespace AutoGen.Tests

View File

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// OpenAIChatCompletionMiddlewareTests.cs
// EchoAgent.cs
using System.Runtime.CompilerServices;
using AutoGen.Core;