Skip to content

Commit f75103f

Browse files
* add lmstudio agent to assistant agent * fix microsoft#2609 * update updatelog * Update Directory.Build.props
1 parent ecc4113 commit f75103f

File tree

7 files changed

+72
-10
lines changed

7 files changed

+72
-10
lines changed

dotnet/Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<SignAssembly>True</SignAssembly>
1111
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)eng/opensource.snk</AssemblyOriginatorKeyFile>
12+
<PublicKey>0024000004800000940000000602000000240000525341310004000001000100f1d038d0b85ae392ad72011df91e9343b0b5df1bb8080aa21b9424362d696919e0e9ac3a8bca24e283e10f7a569c6f443e1d4e3ebc84377c87ca5caa562e80f9932bf5ea91b7862b538e13b8ba91c7565cf0e8dfeccfea9c805ae3bda044170ecc7fc6f147aeeac422dd96aeb9eb1f5a5882aa650efe2958f2f8107d2038f2ab</PublicKey>
1213
<CSNoWarn>CS1998;CS1591</CSNoWarn>
1314
<NoWarn>$(NoWarn);$(CSNoWarn);NU5104</NoWarn>
1415
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -20,4 +21,4 @@
2021
<PropertyGroup>
2122
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
2223
</PropertyGroup>
23-
</Project>
24+
</Project>

dotnet/src/AutoGen.LMStudio/LMStudioConfig.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ public LMStudioConfig(string host, int port, int version = 1)
1313
this.Host = host;
1414
this.Port = port;
1515
this.Version = version;
16+
this.Uri = new Uri($"http://{host}:{port}/v{version}");
17+
}
18+
19+
public LMStudioConfig(Uri uri)
20+
{
21+
this.Uri = uri;
22+
this.Host = uri.Host;
23+
this.Port = uri.Port;
24+
this.Version = int.Parse(uri.Segments[1].TrimStart('v'));
1625
}
1726

1827
public string Host { get; }
@@ -21,5 +30,5 @@ public LMStudioConfig(string host, int port, int version = 1)
2130

2231
public int Version { get; }
2332

24-
public Uri Uri => new Uri($"http://{Host}:{Port}/v{Version}");
33+
public Uri Uri { get; }
2534
}

dotnet/src/AutoGen/Agent/ConversableAgent.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using AutoGen.LMStudio;
910
using AutoGen.OpenAI;
1011

1112
namespace AutoGen;
@@ -74,15 +75,25 @@ public ConversableAgent(
7475
this.functions = llmConfig?.FunctionContracts;
7576
}
7677

78+
/// <summary>
79+
/// For test purpose only.
80+
/// </summary>
81+
internal IAgent? InnerAgent => this.innerAgent;
82+
7783
private IAgent? CreateInnerAgentFromConfigList(ConversableAgentConfig config)
7884
{
7985
IAgent? agent = null;
8086
foreach (var llmConfig in config.ConfigList ?? Enumerable.Empty<ILLMConfig>())
8187
{
82-
var nextAgent = llmConfig switch
88+
IAgent nextAgent = llmConfig switch
8389
{
8490
AzureOpenAIConfig azureConfig => new GPTAgent(this.Name!, this.systemMessage, azureConfig, temperature: config.Temperature ?? 0),
8591
OpenAIConfig openAIConfig => new GPTAgent(this.Name!, this.systemMessage, openAIConfig, temperature: config.Temperature ?? 0),
92+
LMStudioConfig lmStudioConfig => new LMStudioAgent(
93+
name: this.Name,
94+
config: lmStudioConfig,
95+
systemMessage: this.systemMessage,
96+
temperature: config.Temperature ?? 0),
8697
_ => throw new ArgumentException($"Unsupported config type {llmConfig.GetType()}"),
8798
};
8899

dotnet/src/AutoGen/AutoGen.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
<ProjectReference Include="..\AutoGen.Core\AutoGen.Core.csproj" />
2727
<ProjectReference Include="..\AutoGen.OpenAI\AutoGen.OpenAI.csproj" />
2828
</ItemGroup>
29+
30+
<ItemGroup>
31+
<InternalsVisibleTo Include="AutoGen.Tests" />
32+
</ItemGroup>
2933

3034
</Project>

dotnet/test/AutoGen.Mistral.Tests/MistralClientAgentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task MistralAgentChatCompletionTestAsync()
3737
model: "open-mistral-7b")
3838
.RegisterMessageConnector();
3939
var singleAgentTest = new SingleAgentTest(_output);
40-
await singleAgentTest.UpperCaseTest(agent);
40+
await singleAgentTest.UpperCaseTestAsync(agent);
4141
await singleAgentTest.UpperCaseStreamingTestAsync(agent);
4242
}
4343

dotnet/test/AutoGen.Tests/SingleAgentTest.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Threading.Tasks;
9+
using AutoGen.LMStudio;
910
using AutoGen.OpenAI;
1011
using Azure.AI.OpenAI;
1112
using FluentAssertions;
@@ -42,7 +43,7 @@ public async Task GPTAgentTestAsync()
4243

4344
var agent = new GPTAgent("gpt", "You are a helpful AI assistant", config);
4445

45-
await UpperCaseTest(agent);
46+
await UpperCaseTestAsync(agent);
4647
await UpperCaseStreamingTestAsync(agent);
4748
}
4849

@@ -117,7 +118,7 @@ public async Task GPTFunctionCallAgentTestAsync()
117118
var agentWithFunction = new GPTAgent("gpt", "You are a helpful AI assistant", config, 0, functions: new[] { this.EchoAsyncFunction });
118119

119120
await EchoFunctionCallTestAsync(agentWithFunction);
120-
await UpperCaseTest(agentWithFunction);
121+
await UpperCaseTestAsync(agentWithFunction);
121122
}
122123

123124
[ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")]
@@ -143,7 +144,43 @@ public async Task AssistantAgentFunctionCallTestAsync()
143144
llmConfig: llmConfig);
144145

145146
await EchoFunctionCallTestAsync(assistantAgent);
146-
await UpperCaseTest(assistantAgent);
147+
await UpperCaseTestAsync(assistantAgent);
148+
}
149+
150+
[Fact]
151+
public async Task ItCreateAssistantAgentFromLMStudioConfigAsync()
152+
{
153+
var host = "http://localhost";
154+
var port = 8080;
155+
var lmStudioConfig = new LMStudioConfig(host, port);
156+
157+
var assistantAgent = new AssistantAgent(
158+
name: "assistant",
159+
llmConfig: new ConversableAgentConfig()
160+
{
161+
ConfigList = [lmStudioConfig],
162+
});
163+
164+
assistantAgent.Name.Should().Be("assistant");
165+
assistantAgent.InnerAgent.Should().BeOfType<LMStudioAgent>();
166+
}
167+
168+
[ApiKeyFact("LMStudio_ENDPOINT")]
169+
public async Task ItTestAssistantAgentFromLMStudioConfigAsync()
170+
{
171+
var Uri = Environment.GetEnvironmentVariable("LMStudio_ENDPOINT") ?? throw new ArgumentException("LMStudio_ENDPOINT is not set");
172+
var lmStudioConfig = new LMStudioConfig(new Uri(Uri));
173+
174+
var assistantAgent = new AssistantAgent(
175+
name: "assistant",
176+
llmConfig: new ConversableAgentConfig()
177+
{
178+
ConfigList = [lmStudioConfig],
179+
});
180+
181+
assistantAgent.Name.Should().Be("assistant");
182+
assistantAgent.InnerAgent.Should().BeOfType<LMStudioAgent>();
183+
await this.UpperCaseTestAsync(assistantAgent);
147184
}
148185

149186

@@ -186,7 +223,6 @@ public async Task AssistantAgentFunctionCallSelfExecutionTestAsync()
186223
});
187224

188225
await EchoFunctionCallExecutionTestAsync(assistantAgent);
189-
await UpperCaseTest(assistantAgent);
190226
}
191227

192228
[ApiKeyFact("AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT")]
@@ -206,7 +242,7 @@ public async Task GPTAgentFunctionCallSelfExecutionTestAsync()
206242

207243
await EchoFunctionCallExecutionStreamingTestAsync(agent);
208244
await EchoFunctionCallExecutionTestAsync(agent);
209-
await UpperCaseTest(agent);
245+
await UpperCaseTestAsync(agent);
210246
}
211247

212248
/// <summary>
@@ -283,7 +319,7 @@ public async Task EchoFunctionCallExecutionStreamingTestAsync(IStreamingAgent ag
283319
}
284320
}
285321

286-
public async Task UpperCaseTest(IAgent agent)
322+
public async Task UpperCaseTestAsync(IAgent agent)
287323
{
288324
var message = new TextMessage(Role.System, "You are a helpful AI assistant that convert user message to upper case");
289325
var uppCaseMessage = new TextMessage(Role.User, "abcdefg");

dotnet/website/update.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- [API Breaking Change] Update the return type of `IStreamingAgent.GenerateStreamingReplyAsync` from `Task<IAsyncEnumerable<IStreamingMessage>>` to `IAsyncEnumerable<IStreamingMessage>`
33
- [API Breaking Change] Update the return type of `IStreamingMiddleware.InvokeAsync` from `Task<IAsyncEnumerable<IStreamingMessage>>` to `IAsyncEnumerable<IStreamingMessage>`
44
- [API Breaking Change] Mark `RegisterReply`, `RegisterPreProcess` and `RegisterPostProcess` as obsolete. You can replace them with `RegisterMiddleware`
5+
- Fix [Issue 2609](https://github.com/microsoft/autogen/issues/2609)
56
##### Update on 0.0.12 (2024-04-22)
67
- Add AutoGen.Mistral package to support Mistral.AI models
78
##### Update on 0.0.11 (2024-04-10)

0 commit comments

Comments
 (0)