From 6bb9bc47c02254ca8c057c8ce291aeac5615aabd Mon Sep 17 00:00:00 2001 From: reidliu41 Date: Tue, 17 Feb 2026 00:42:53 +0800 Subject: [PATCH] feat(provider): add Qwen/DashScope provider with multi-region support - Add Alibaba Qwen as an OpenAI-compatible provider via DashScope API - Support three regional endpoints: China (Beijing), Singapore, and US (Virginia) - All regions share a single `DASHSCOPE_API_KEY` environment variable | Config Value | Region | Base URL | |---|---|---| | `qwen` / `dashscope` | China (Beijing) | `dashscope.aliyuncs.com/compatible-mode/v1` | | `qwen-intl` / `dashscope-intl` | Singapore | `dashscope-intl.aliyuncs.com/compatible-mode/v1` | | `qwen-us` / `dashscope-us` | US (Virginia) | `dashscope-us.aliyuncs.com/compatible-mode/v1` | --- src/providers/mod.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/providers/mod.rs b/src/providers/mod.rs index b342675..d411fed 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -123,6 +123,9 @@ fn resolve_api_key(name: &str, api_key: Option<&str>) -> Option { "glm" | "zhipu" => vec!["GLM_API_KEY"], "minimax" => vec!["MINIMAX_API_KEY"], "qianfan" | "baidu" => vec!["QIANFAN_API_KEY"], + "qwen" | "dashscope" | "qwen-intl" | "dashscope-intl" | "qwen-us" | "dashscope-us" => { + vec!["DASHSCOPE_API_KEY"] + } "zai" | "z.ai" => vec!["ZAI_API_KEY"], "synthetic" => vec!["SYNTHETIC_API_KEY"], "opencode" | "opencode-zen" => vec!["OPENCODE_API_KEY"], @@ -235,6 +238,15 @@ pub fn create_provider(name: &str, api_key: Option<&str>) -> anyhow::Result Ok(Box::new(OpenAiCompatibleProvider::new( "Qianfan", "https://aip.baidubce.com", key, AuthStyle::Bearer, ))), + "qwen" | "dashscope" => Ok(Box::new(OpenAiCompatibleProvider::new( + "Qwen", "https://dashscope.aliyuncs.com/compatible-mode/v1", key, AuthStyle::Bearer, + ))), + "qwen-intl" | "dashscope-intl" => Ok(Box::new(OpenAiCompatibleProvider::new( + "Qwen", "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", key, AuthStyle::Bearer, + ))), + "qwen-us" | "dashscope-us" => Ok(Box::new(OpenAiCompatibleProvider::new( + "Qwen", "https://dashscope-us.aliyuncs.com/compatible-mode/v1", key, AuthStyle::Bearer, + ))), // ── Extended ecosystem (community favorites) ───────── "groq" => Ok(Box::new(OpenAiCompatibleProvider::new( @@ -521,6 +533,16 @@ mod tests { assert!(create_provider("baidu", Some("key")).is_ok()); } + #[test] + fn factory_qwen() { + assert!(create_provider("qwen", Some("key")).is_ok()); + assert!(create_provider("dashscope", Some("key")).is_ok()); + assert!(create_provider("qwen-intl", Some("key")).is_ok()); + assert!(create_provider("dashscope-intl", Some("key")).is_ok()); + assert!(create_provider("qwen-us", Some("key")).is_ok()); + assert!(create_provider("dashscope-us", Some("key")).is_ok()); + } + // ── Extended ecosystem ─────────────────────────────────── #[test] @@ -749,6 +771,9 @@ mod tests { "minimax", "bedrock", "qianfan", + "qwen", + "qwen-intl", + "qwen-us", "groq", "mistral", "xai",