From a82cf7c156971e2b196a3351da5d6c5c0d2a7523 Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Tue, 7 May 2024 13:29:47 -0700 Subject: [PATCH 1/4] add lmstudio agent to assistant agent --- dotnet/Directory.Build.props | 3 ++- dotnet/src/AutoGen/Agent/ConversableAgent.cs | 13 ++++++++++++- dotnet/src/AutoGen/AutoGen.csproj | 4 ++++ dotnet/test/AutoGen.Tests/SingleAgentTest.cs | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dotnet/Directory.Build.props b/dotnet/Directory.Build.props index 5641c6cacbb4..66eb18ae5729 100644 --- a/dotnet/Directory.Build.props +++ b/dotnet/Directory.Build.props @@ -7,8 +7,9 @@ net8.0 preview enable - True + true $(MSBuildThisFileDirectory)eng/opensource.snk + 0024000004800000940000000602000000240000525341310004000001000100f1d038d0b85ae392ad72011df91e9343b0b5df1bb8080aa21b9424362d696919e0e9ac3a8bca24e283e10f7a569c6f443e1d4e3ebc84377c87ca5caa562e80f9932bf5ea91b7862b538e13b8ba91c7565cf0e8dfeccfea9c805ae3bda044170ecc7fc6f147aeeac422dd96aeb9eb1f5a5882aa650efe2958f2f8107d2038f2ab CS1998;CS1591 $(NoWarn);$(CSNoWarn);NU5104 true diff --git a/dotnet/src/AutoGen/Agent/ConversableAgent.cs b/dotnet/src/AutoGen/Agent/ConversableAgent.cs index d79d25192979..fe1470502022 100644 --- a/dotnet/src/AutoGen/Agent/ConversableAgent.cs +++ b/dotnet/src/AutoGen/Agent/ConversableAgent.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using AutoGen.LMStudio; using AutoGen.OpenAI; namespace AutoGen; @@ -74,15 +75,25 @@ public ConversableAgent( this.functions = llmConfig?.FunctionContracts; } + /// + /// For test purpose only. + /// + internal IAgent? InnerAgent => this.innerAgent; + private IAgent? CreateInnerAgentFromConfigList(ConversableAgentConfig config) { IAgent? agent = null; foreach (var llmConfig in config.ConfigList ?? Enumerable.Empty()) { - var nextAgent = llmConfig switch + IAgent nextAgent = llmConfig switch { AzureOpenAIConfig azureConfig => new GPTAgent(this.Name!, this.systemMessage, azureConfig, temperature: config.Temperature ?? 0), OpenAIConfig openAIConfig => new GPTAgent(this.Name!, this.systemMessage, openAIConfig, temperature: config.Temperature ?? 0), + LMStudioConfig lmStudioConfig => new LMStudioAgent( + name: this.Name, + config: lmStudioConfig, + systemMessage: this.systemMessage, + temperature: config.Temperature ?? 0), _ => throw new ArgumentException($"Unsupported config type {llmConfig.GetType()}"), }; diff --git a/dotnet/src/AutoGen/AutoGen.csproj b/dotnet/src/AutoGen/AutoGen.csproj index 8f4bbccb5d22..7e14ad4e73fd 100644 --- a/dotnet/src/AutoGen/AutoGen.csproj +++ b/dotnet/src/AutoGen/AutoGen.csproj @@ -26,5 +26,9 @@ + + + + diff --git a/dotnet/test/AutoGen.Tests/SingleAgentTest.cs b/dotnet/test/AutoGen.Tests/SingleAgentTest.cs index ae566889bf58..f0308f22eaf9 100644 --- a/dotnet/test/AutoGen.Tests/SingleAgentTest.cs +++ b/dotnet/test/AutoGen.Tests/SingleAgentTest.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using AutoGen.LMStudio; using AutoGen.OpenAI; using Azure.AI.OpenAI; using FluentAssertions; @@ -146,6 +147,24 @@ public async Task AssistantAgentFunctionCallTestAsync() await UpperCaseTest(assistantAgent); } + [Fact] + public async Task ItCreateAssistantAgentFromLMStudioConfigAsync() + { + var host = "http://localhost"; + var port = 8080; + var lmStudioConfig = new LMStudioConfig(host, port); + + var assistantAgent = new AssistantAgent( + name: "assistant", + llmConfig: new ConversableAgentConfig() + { + ConfigList = [lmStudioConfig], + }); + + assistantAgent.Name.Should().Be("assistant"); + assistantAgent.InnerAgent.Should().BeOfType(); + } + [Fact] public async Task AssistantAgentDefaultReplyTestAsync() From d785a4a37aea11c9ba1d50319c443689495c7c87 Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Tue, 7 May 2024 13:39:55 -0700 Subject: [PATCH 2/4] fix #2609 --- dotnet/src/AutoGen.LMStudio/LMStudioConfig.cs | 11 ++++++- .../MistralClientAgentTests.cs | 2 +- dotnet/test/AutoGen.Tests/SingleAgentTest.cs | 29 +++++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dotnet/src/AutoGen.LMStudio/LMStudioConfig.cs b/dotnet/src/AutoGen.LMStudio/LMStudioConfig.cs index 4cf18210a43a..3864630b3d89 100644 --- a/dotnet/src/AutoGen.LMStudio/LMStudioConfig.cs +++ b/dotnet/src/AutoGen.LMStudio/LMStudioConfig.cs @@ -13,6 +13,15 @@ public LMStudioConfig(string host, int port, int version = 1) this.Host = host; this.Port = port; this.Version = version; + this.Uri = new Uri($"http://{host}:{port}/v{version}"); + } + + public LMStudioConfig(Uri uri) + { + this.Uri = uri; + this.Host = uri.Host; + this.Port = uri.Port; + this.Version = int.Parse(uri.Segments[1].TrimStart('v')); } public string Host { get; } @@ -21,5 +30,5 @@ public LMStudioConfig(string host, int port, int version = 1) public int Version { get; } - public Uri Uri => new Uri($"http://{Host}:{Port}/v{Version}"); + public Uri Uri { get; } } diff --git a/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs b/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs index 5a9d1f95c73e..bcd5f1309fa3 100644 --- a/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs +++ b/dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs @@ -37,7 +37,7 @@ public async Task MistralAgentChatCompletionTestAsync() model: "open-mistral-7b") .RegisterMessageConnector(); var singleAgentTest = new SingleAgentTest(_output); - await singleAgentTest.UpperCaseTest(agent); + await singleAgentTest.UpperCaseTestAsync(agent); await singleAgentTest.UpperCaseStreamingTestAsync(agent); } diff --git a/dotnet/test/AutoGen.Tests/SingleAgentTest.cs b/dotnet/test/AutoGen.Tests/SingleAgentTest.cs index f0308f22eaf9..79d2b9c2f3f5 100644 --- a/dotnet/test/AutoGen.Tests/SingleAgentTest.cs +++ b/dotnet/test/AutoGen.Tests/SingleAgentTest.cs @@ -43,7 +43,7 @@ public async Task GPTAgentTestAsync() var agent = new GPTAgent("gpt", "You are a helpful AI assistant", config); - await UpperCaseTest(agent); + await UpperCaseTestAsync(agent); await UpperCaseStreamingTestAsync(agent); } @@ -118,7 +118,7 @@ public async Task GPTFunctionCallAgentTestAsync() var agentWithFunction = new GPTAgent("gpt", "You are a helpful AI assistant", config, 0, functions: new[] { this.EchoAsyncFunction }); await EchoFunctionCallTestAsync(agentWithFunction); - await UpperCaseTest(agentWithFunction); + await UpperCaseTestAsync(agentWithFunction); } [ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")] @@ -144,7 +144,7 @@ public async Task AssistantAgentFunctionCallTestAsync() llmConfig: llmConfig); await EchoFunctionCallTestAsync(assistantAgent); - await UpperCaseTest(assistantAgent); + await UpperCaseTestAsync(assistantAgent); } [Fact] @@ -165,6 +165,24 @@ public async Task ItCreateAssistantAgentFromLMStudioConfigAsync() assistantAgent.InnerAgent.Should().BeOfType(); } + [ApiKeyFact("LMStudio_ENDPOINT")] + public async Task ItTestAssistantAgentFromLMStudioConfigAsync() + { + var Uri = Environment.GetEnvironmentVariable("LMStudio_ENDPOINT") ?? throw new ArgumentException("LMStudio_ENDPOINT is not set"); + var lmStudioConfig = new LMStudioConfig(new Uri(Uri)); + + var assistantAgent = new AssistantAgent( + name: "assistant", + llmConfig: new ConversableAgentConfig() + { + ConfigList = [lmStudioConfig], + }); + + assistantAgent.Name.Should().Be("assistant"); + assistantAgent.InnerAgent.Should().BeOfType(); + await this.UpperCaseTestAsync(assistantAgent); + } + [Fact] public async Task AssistantAgentDefaultReplyTestAsync() @@ -205,7 +223,6 @@ public async Task AssistantAgentFunctionCallSelfExecutionTestAsync() }); await EchoFunctionCallExecutionTestAsync(assistantAgent); - await UpperCaseTest(assistantAgent); } [ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")] @@ -225,7 +242,7 @@ public async Task GPTAgentFunctionCallSelfExecutionTestAsync() await EchoFunctionCallExecutionStreamingTestAsync(agent); await EchoFunctionCallExecutionTestAsync(agent); - await UpperCaseTest(agent); + await UpperCaseTestAsync(agent); } /// @@ -302,7 +319,7 @@ public async Task EchoFunctionCallExecutionStreamingTestAsync(IStreamingAgent ag } } - public async Task UpperCaseTest(IAgent agent) + public async Task UpperCaseTestAsync(IAgent agent) { var message = new TextMessage(Role.System, "You are a helpful AI assistant that convert user message to upper case"); var uppCaseMessage = new TextMessage(Role.User, "abcdefg"); From 6297208e2360ce8db9fd05f9d040640affa06197 Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Tue, 7 May 2024 13:41:30 -0700 Subject: [PATCH 3/4] update updatelog --- dotnet/website/update.md | 1 + 1 file changed, 1 insertion(+) diff --git a/dotnet/website/update.md b/dotnet/website/update.md index b65ab128ef7a..3d905c0ab115 100644 --- a/dotnet/website/update.md +++ b/dotnet/website/update.md @@ -2,6 +2,7 @@ - [API Breaking Change] Update the return type of `IStreamingAgent.GenerateStreamingReplyAsync` from `Task>` to `IAsyncEnumerable` - [API Breaking Change] Update the return type of `IStreamingMiddleware.InvokeAsync` from `Task>` to `IAsyncEnumerable` - [API Breaking Change] Mark `RegisterReply`, `RegisterPreProcess` and `RegisterPostProcess` as obsolete. You can replace them with `RegisterMiddleware` +- Fix [Issue 2609](https://github.com/microsoft/autogen/issues/2609) ##### Update on 0.0.12 (2024-04-22) - Add AutoGen.Mistral package to support Mistral.AI models ##### Update on 0.0.11 (2024-04-10) From 96f7bc15523052512ad8f57a0c15cea5e2d58c73 Mon Sep 17 00:00:00 2001 From: Xiaoyun Zhang Date: Tue, 7 May 2024 13:43:11 -0700 Subject: [PATCH 4/4] Update Directory.Build.props --- dotnet/Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/Directory.Build.props b/dotnet/Directory.Build.props index 66eb18ae5729..aeb667438e26 100644 --- a/dotnet/Directory.Build.props +++ b/dotnet/Directory.Build.props @@ -7,7 +7,7 @@ net8.0 preview enable - true + True $(MSBuildThisFileDirectory)eng/opensource.snk 0024000004800000940000000602000000240000525341310004000001000100f1d038d0b85ae392ad72011df91e9343b0b5df1bb8080aa21b9424362d696919e0e9ac3a8bca24e283e10f7a569c6f443e1d4e3ebc84377c87ca5caa562e80f9932bf5ea91b7862b538e13b8ba91c7565cf0e8dfeccfea9c805ae3bda044170ecc7fc6f147aeeac422dd96aeb9eb1f5a5882aa650efe2958f2f8107d2038f2ab CS1998;CS1591 @@ -21,4 +21,4 @@ $(MSBuildThisFileDirectory) - \ No newline at end of file +