Skip to content

Commit

Permalink
[.Net] update dotnet-ci and dotnet-release to use 8.0.x version when …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
LittleLittleCloud authored Jul 15, 2024
1 parent 7205ccc commit 970c196
Show file tree
Hide file tree
Showing 42 changed files with 80 additions and 50 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public async Task CreateMiddlewareAgentAsync()
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;
Expand All @@ -39,8 +38,7 @@ public async Task CreateMiddlewareAgentAsync()
#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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public static async Task RunAsync()
// 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ public static async Task RunWorkflowAsync()
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);
Expand Down Expand Up @@ -329,7 +331,9 @@ public static async Task RunAsync()
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ private static void AddMessagesFromResource(string imageResourcePath, List<IMess
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Dynamic_GroupChat.cs
// Dynamic_Group_Chat.cs

using AutoGen.Core;
using AutoGen.OpenAI;
Expand Down
3 changes: 2 additions & 1 deletion dotnet/sample/AutoGen.OpenAI.Sample/Connect_To_Ollama.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/sample/AutoGen.OpenAI.Sample/Use_Json_Mode.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 4 additions & 1 deletion dotnet/src/AutoGen.Anthropic/Agent/AnthropicClientAgent.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/AutoGen.Anthropic/AnthropicClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public async Task<ChatCompletionResponse> CreateChatCompletionsAsync(ChatComplet
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Anthropic/DTO/ChatCompletionRequest.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 3 additions & 2 deletions dotnet/src/AutoGen.Anthropic/DTO/ChatCompletionResponse.cs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Anthropic/DTO/Content.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Anthropic/DTO/ErrorResponse.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Anthropic/DTO/Tool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Tool.cs

using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Anthropic/Utils/AnthropicConstants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Constants.cs
// AnthropicConstants.cs

namespace AutoGen.Anthropic.Utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// FunctionCallAggregateMessage.cs
// ToolCallAggregateMessage.cs

using System.Collections.Generic;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Gemini/IGeminiClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IVertexGeminiClient.cs
// IGeminiClient.cs

using System.Collections.Generic;
using System.Threading;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Gemini/VertexGeminiClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IGeminiClient.cs
// VertexGeminiClient.cs

using System.Collections.Generic;
using System.Threading;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.Ollama/DTOs/Message.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// ChatResponseUpdate.cs
// Message.cs

using System.Collections.Generic;
using System.Text.Json.Serialization;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// ITextEmbeddingService.cs

using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// OllamaTextEmbeddingService.cs

using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// FunctionContract.cs
// SourceGeneratorFunctionContract.cs

namespace AutoGen.SourceGenerator
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.WebAPI/OpenAI/DTO/OpenAIMessage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// OpenAIChatCompletionOption.cs
// OpenAIMessage.cs

using System.Text.Json.Serialization;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// OpenAIStreamOptions.cs

using System.Text.Json.Serialization;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task AnthropicAgentFunctionCallMessageTest()
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);
Expand Down
7 changes: 6 additions & 1 deletion dotnet/test/AutoGen.Anthropic.Tests/AnthropicClientTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,7 +62,9 @@ public async Task AnthropicClientStreamingChatCompletionTestAsync()
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// AnthropicTestFunctions.cs
// AnthropicTestFunctionCalls.cs

using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down
8 changes: 4 additions & 4 deletions dotnet/test/AutoGen.Gemini.Tests/GeminiAgentTests.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// GeminiVertexClientTests.cs
// VertexGeminiClientTests.cs

using AutoGen.Tests;
using FluentAssertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// OllamaTextEmbeddingServiceTests.cs

using AutoGen.Tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -89,4 +91,4 @@ public void ParameterDescription_Should_Encode_DoubleQuotes()
Assert.Contains("Description = @\"This is a \"\"parameter\"\" description\"", result);
}
}
}
}
4 changes: 3 additions & 1 deletion dotnet/test/AutoGen.Tests/GroupChat/GraphTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

// Copyright (c) Microsoft Corporation. All rights reserved.
// GraphTests.cs

using Xunit;

namespace AutoGen.Tests
Expand Down
Loading

0 comments on commit 970c196

Please sign in to comment.