From 77640e21982bbf6796d9632e5ef29512f060b71f Mon Sep 17 00:00:00 2001 From: reidliu41 Date: Tue, 17 Feb 2026 10:17:13 +0800 Subject: [PATCH] feat(provider): add LM Studio provider alias - Add `lmstudio` / `lm-studio` as a built-in provider alias for local LM Studio instances (`http://localhost:1234/v1`) - Uses a dummy API key when none is provided, since LM Studio does not require authentication - Users can connect to remote LM Studio instances via `custom:http://:1234/v1` --- src/providers/mod.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 14d1b58..66e653b 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -292,9 +292,26 @@ pub fn create_provider_with_url( "copilot" | "github-copilot" => Ok(Box::new(OpenAiCompatibleProvider::new( "GitHub Copilot", "https://api.githubcopilot.com", key, AuthStyle::Bearer, ))), - "nvidia" | "nvidia-nim" | "build.nvidia.com" => Ok(Box::new(OpenAiCompatibleProvider::new( - "NVIDIA NIM", "https://integrate.api.nvidia.com/v1", key, AuthStyle::Bearer, - ))), + "lmstudio" | "lm-studio" => { + let lm_studio_key = api_key + .map(str::trim) + .filter(|value| !value.is_empty()) + .unwrap_or("lm-studio"); + Ok(Box::new(OpenAiCompatibleProvider::new( + "LM Studio", + "http://localhost:1234/v1", + Some(lm_studio_key), + AuthStyle::Bearer, + ))) + } + "nvidia" | "nvidia-nim" | "build.nvidia.com" => Ok(Box::new( + OpenAiCompatibleProvider::new( + "NVIDIA NIM", + "https://integrate.api.nvidia.com/v1", + key, + AuthStyle::Bearer, + ), + )), // ── Bring Your Own Provider (custom URL) ─────────── // Format: "custom:https://your-api.com" or "custom:http://localhost:1234" @@ -569,6 +586,13 @@ mod tests { assert!(create_provider("dashscope-us", Some("key")).is_ok()); } + #[test] + fn factory_lmstudio() { + assert!(create_provider("lmstudio", Some("key")).is_ok()); + assert!(create_provider("lm-studio", Some("key")).is_ok()); + assert!(create_provider("lmstudio", None).is_ok()); + } + // ── Extended ecosystem ─────────────────────────────────── #[test] @@ -823,6 +847,7 @@ mod tests { "qwen", "qwen-intl", "qwen-us", + "lmstudio", "groq", "mistral", "xai",