From 45ea5e7deb63808eb16c09199c4286bad4979e03 Mon Sep 17 00:00:00 2001 From: Kimi <86585011+kimmywork@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:22:11 +0800 Subject: [PATCH 1/3] fix: update LMStudio API Endpoint and added model name support --- dotnet/src/AutoGen/LMStudioConfig.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dotnet/src/AutoGen/LMStudioConfig.cs b/dotnet/src/AutoGen/LMStudioConfig.cs index 4605b051142f..e27f7af92b6e 100644 --- a/dotnet/src/AutoGen/LMStudioConfig.cs +++ b/dotnet/src/AutoGen/LMStudioConfig.cs @@ -13,18 +13,20 @@ namespace AutoGen; /// public class LMStudioConfig : ILLMConfig { - public LMStudioConfig(string host, int port) + public LMStudioConfig(string host, int port, string modelName) { this.Host = host; this.Port = port; - this.Uri = new Uri($"http://{host}:{port}"); + this.Uri = new Uri($"http://{host}:{port}/v1"); + this.ModelName = modelName; } - public LMStudioConfig(Uri uri) + public LMStudioConfig(Uri uri, string modelName) { this.Uri = uri; this.Host = uri.Host; this.Port = uri.Port; + this.ModelName = modelName; } public string Host { get; } @@ -33,6 +35,8 @@ public LMStudioConfig(Uri uri) public Uri Uri { get; } + public string ModelName { get; } + internal ChatClient CreateChatClient() { var client = new OpenAIClient(new ApiKeyCredential("api-key"), new OpenAIClientOptions @@ -40,8 +44,6 @@ internal ChatClient CreateChatClient() Endpoint = this.Uri, }); - // model name doesn't matter for LM Studio - - return client.GetChatClient("model-name"); + return client.GetChatClient(this.ModelName); } } From cd1f6c10ffbe63126fbae6326a9d09aef2f56008 Mon Sep 17 00:00:00 2001 From: K Date: Fri, 20 Dec 2024 14:57:43 +0800 Subject: [PATCH 2/3] fix: ensure modelName non-null --- dotnet/src/AutoGen/LMStudioConfig.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dotnet/src/AutoGen/LMStudioConfig.cs b/dotnet/src/AutoGen/LMStudioConfig.cs index e27f7af92b6e..2601b7b6ddc1 100644 --- a/dotnet/src/AutoGen/LMStudioConfig.cs +++ b/dotnet/src/AutoGen/LMStudioConfig.cs @@ -18,6 +18,8 @@ public LMStudioConfig(string host, int port, string modelName) this.Host = host; this.Port = port; this.Uri = new Uri($"http://{host}:{port}/v1"); + if (modelName == null) + throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null"); this.ModelName = modelName; } @@ -26,6 +28,8 @@ public LMStudioConfig(Uri uri, string modelName) this.Uri = uri; this.Host = uri.Host; this.Port = uri.Port; + if (modelName == null) + throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null"); this.ModelName = modelName; } From ae741370e176db738500b5d94ab0c2d24e0e9536 Mon Sep 17 00:00:00 2001 From: K Date: Fri, 20 Dec 2024 15:11:13 +0800 Subject: [PATCH 3/3] fix: add braces around if branch --- dotnet/src/AutoGen/LMStudioConfig.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dotnet/src/AutoGen/LMStudioConfig.cs b/dotnet/src/AutoGen/LMStudioConfig.cs index 2601b7b6ddc1..29c60ff13f39 100644 --- a/dotnet/src/AutoGen/LMStudioConfig.cs +++ b/dotnet/src/AutoGen/LMStudioConfig.cs @@ -19,7 +19,9 @@ public LMStudioConfig(string host, int port, string modelName) this.Port = port; this.Uri = new Uri($"http://{host}:{port}/v1"); if (modelName == null) + { throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null"); + } this.ModelName = modelName; } @@ -29,7 +31,9 @@ public LMStudioConfig(Uri uri, string modelName) this.Host = uri.Host; this.Port = uri.Port; if (modelName == null) + { throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null"); + } this.ModelName = modelName; }