Skip to content

Commit

Permalink
fix: update LMStudio API Endpoint and added model name support (#4732)
Browse files Browse the repository at this point in the history
* fix: update LMStudio API Endpoint and added model name support

* fix: ensure modelName non-null

* fix: add braces around if branch

---------

Co-authored-by: Ryan Sweet <[email protected]>
Co-authored-by: Xiaoyun Zhang <[email protected]>
  • Loading branch information
3 people authored Dec 27, 2024
1 parent e710f9d commit 90a44b5
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions dotnet/src/AutoGen/LMStudioConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@ namespace AutoGen;
/// </summary>
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");
if (modelName == null)
{
throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null");
}
this.ModelName = modelName;
}

public LMStudioConfig(Uri uri)
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;
}

public string Host { get; }
Expand All @@ -33,15 +43,15 @@ 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
{
Endpoint = this.Uri,
});

// model name doesn't matter for LM Studio

return client.GetChatClient("model-name");
return client.GetChatClient(this.ModelName);
}
}

0 comments on commit 90a44b5

Please sign in to comment.