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` |
This commit is contained in:
parent
7f4c688145
commit
6bb9bc47c0
1 changed files with 25 additions and 0 deletions
|
|
@ -123,6 +123,9 @@ fn resolve_api_key(name: &str, api_key: Option<&str>) -> Option<String> {
|
||||||
"glm" | "zhipu" => vec!["GLM_API_KEY"],
|
"glm" | "zhipu" => vec!["GLM_API_KEY"],
|
||||||
"minimax" => vec!["MINIMAX_API_KEY"],
|
"minimax" => vec!["MINIMAX_API_KEY"],
|
||||||
"qianfan" | "baidu" => vec!["QIANFAN_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"],
|
"zai" | "z.ai" => vec!["ZAI_API_KEY"],
|
||||||
"synthetic" => vec!["SYNTHETIC_API_KEY"],
|
"synthetic" => vec!["SYNTHETIC_API_KEY"],
|
||||||
"opencode" | "opencode-zen" => vec!["OPENCODE_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<Box<
|
||||||
"qianfan" | "baidu" => Ok(Box::new(OpenAiCompatibleProvider::new(
|
"qianfan" | "baidu" => Ok(Box::new(OpenAiCompatibleProvider::new(
|
||||||
"Qianfan", "https://aip.baidubce.com", key, AuthStyle::Bearer,
|
"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) ─────────
|
// ── Extended ecosystem (community favorites) ─────────
|
||||||
"groq" => Ok(Box::new(OpenAiCompatibleProvider::new(
|
"groq" => Ok(Box::new(OpenAiCompatibleProvider::new(
|
||||||
|
|
@ -521,6 +533,16 @@ mod tests {
|
||||||
assert!(create_provider("baidu", Some("key")).is_ok());
|
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 ───────────────────────────────────
|
// ── Extended ecosystem ───────────────────────────────────
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -749,6 +771,9 @@ mod tests {
|
||||||
"minimax",
|
"minimax",
|
||||||
"bedrock",
|
"bedrock",
|
||||||
"qianfan",
|
"qianfan",
|
||||||
|
"qwen",
|
||||||
|
"qwen-intl",
|
||||||
|
"qwen-us",
|
||||||
"groq",
|
"groq",
|
||||||
"mistral",
|
"mistral",
|
||||||
"xai",
|
"xai",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue