Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

feat(llm): add iFlytek Spark (Astron MaaS) provider

FenjuFu6702bc1a86fd
diff --git a/app/models/llm_provider.py b/app/models/llm_provider.py
index 2ca17a9c..fbf86a56 100644
--- a/app/models/llm_provider.py
+++ b/app/models/llm_provider.py
@@ -318,6 +318,17 @@ LLM_PROVIDER_REGISTRY = (
default_model="mimo-v2.5-pro",
default_base_url="https://api.xiaomimimo.com/v1",
),
+ # 讯飞星辰 MaaS 的按量付费和 Token Plan 使用不同的 OpenAI 兼容地址,
+ # 两边的 API Key 不能混用。这里默认按量付费,Token Plan 用户在 Base URL
+ # 中改填 maas-token-api 的地址即可。
+ LLMProviderSpec(
+ "iflytek",
+ "iFlytek Spark (Astron MaaS)",
+ api_key_url="https://maas.xfyun.cn/",
+ default_model="spark-x2.5",
+ default_base_url="https://maas-api.cn-huabei-1.xf-yun.com/v2",
+ model_docs_url="https://maas.xfyun.cn/modelSquare",
+ ),
# 聚合与统一接入平台
LLMProviderSpec(
"shengsuanyun",
diff --git a/config.example.toml b/config.example.toml
index e2cf103a..d6004c36 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -354,6 +354,14 @@ mimo_api_key = ""
mimo_base_url = ""
mimo_model_name = ""
+# iFlytek Spark on Astron MaaS (OpenAI-compatible). Pay-as-you-go keys use the
+# default base URL; Token Plan keys need
+# https://maas-token-api.cn-huabei-1.xf-yun.com/v2 instead.
+# API key: https://maas.xfyun.cn/
+iflytek_api_key = ""
+iflytek_base_url = ""
+iflytek_model_name = ""
+
# Cloudflare AI Gateway. The token requires AI Gateway Read/Edit and Workers AI
# Read permissions. Leave gateway_id empty to use the Registry default.
# Dashboard: https://dash.cloudflare.com/
diff --git a/test/services/test_llm.py b/test/services/test_llm.py
index 500c3677..af4032b8 100644
--- a/test/services/test_llm.py
+++ b/test/services/test_llm.py
@@ -414,6 +414,16 @@ class TestLiteLLMProvider(unittest.TestCase):
"https://y-api.bestvirtualgoods.com/app/keys",
)
self.assertEqual(yapi.model_docs_url, "https://y-api.bestvirtualgoods.com/models")
+ iflytek = get_llm_provider("iflytek")
+ self.assertEqual(iflytek.default_model, "spark-x2.5")
+ self.assertEqual(
+ iflytek.default_base_url,
+ "https://maas-api.cn-huabei-1.xf-yun.com/v2",
+ )
+ self.assertEqual(iflytek.adapter, "openai_compatible")
+ self.assertTrue(iflytek.requires_api_key)
+ self.assertEqual(iflytek.api_key_url, "https://maas.xfyun.cn/")
+ self.assertEqual(iflytek.model_docs_url, "https://maas.xfyun.cn/modelSquare")
pollinations = get_llm_provider("pollinations")
self.assertEqual(pollinations.default_model, "openai-fast")
self.assertEqual(
@@ -462,6 +472,7 @@ class TestLiteLLMProvider(unittest.TestCase):
"grok",
"minimax",
"mimo",
+ "iflytek",
"shengsuanyun",
"apimart",
"cloudflare",
@@ -1449,6 +1460,55 @@ class TestLiteLLMProvider(unittest.TestCase):
)
self.assertEqual(result, "hello\nevolink")
+ def test_iflytek_provider_uses_openai_compatible_client(self):
+ """
+ iFlytek Astron MaaS serves Spark over OpenAI-compatible Chat Completions.
+ Pay-as-you-go is the default; a Token Plan base URL saved by the user
+ must be used as-is because keys from one plan do not work on the other.
+ """
+ config.app["llm_provider"] = "iflytek"
+ config.app["iflytek_api_key"] = "iflytek-key"
+ config.app["iflytek_model_name"] = ""
+
+ class FakeCompletions:
+ def create(self, **kwargs):
+ self.kwargs = kwargs
+ message = types.SimpleNamespace(content="hello\niflytek")
+ choice = types.SimpleNamespace(message=message)
+ return types.SimpleNamespace(choices=[choice])
+
+ for configured_base_url, expected_base_url in (
+ ("", "https://maas-api.cn-huabei-1.xf-yun.com/v2"),
+ (
+ "https://maas-token-api.cn-huabei-1.xf-yun.com/v2",
+ "https://maas-token-api.cn-huabei-1.xf-yun.com/v2",
+ ),
+ ):
+ with self.subTest(base_url=configured_base_url):
+ config.app["iflytek_base_url"] = configured_base_url
+ fake_completions = FakeCompletions()
+ fake_client = types.SimpleNamespace(
+ chat=types.SimpleNamespace(completions=fake_completions)
+ )
+
+ with (
+ patch.object(llm, "OpenAI", return_value=fake_client) as openai_client,
+ patch.object(llm, "ChatCompletion", types.SimpleNamespace),
+ ):
+ result = llm._generate_response("Say hello")
+
+ openai_client.assert_called_once_with(
+ api_key="iflytek-key",
+ base_url=expected_base_url,
+ )
+ self.assertEqual(
+ fake_completions.kwargs,
+ {
+ "model": "spark-x2.5",
+ "messages": [{"role": "user", "content": "Say hello"}],
+ },
+ )
+ self.assertEqual(result, "hello\niflytek")
def test_openrouter_provider_uses_openai_compatible_client(self):
"""
OpenRouter exposes OpenAI-compatible Chat Completions through one
diff --git a/webui/i18n/en.json b/webui/i18n/en.json
index 1cb86230..4fea8179 100644
--- a/webui/i18n/en.json
+++ b/webui/i18n/en.json
@@ -509,6 +509,7 @@
"llm_provider_tips.groq": "##### Groq Configuration\n- **API Key**: create one in the [Groq Console]({api_key_url})\n- **Base Url**: defaults to `{default_base_url}`\n- **Model Name**: defaults to `{default_model}`; available models can also be loaded from the API",
"llm_provider_tips.deepseek": "##### DeepSeek Configuration\n- **API Key**: create one on the [DeepSeek Platform]({api_key_url})\n- **Base Url**: defaults to `{default_base_url}`\n- **Model Name**: defaults to `{default_model}`; you can also enter another model ID available to your account",
"llm_provider_tips.mimo": "##### Xiaomi MiMo Configuration\n- **API Key**: create one by following the [MiMo documentation]({api_key_url})\n- **Base Url**: defaults to `{default_base_url}`\n- **Model Name**: defaults to `{default_model}`; you can also enter another supported model ID",
+ "llm_provider_tips.iflytek": "##### iFlytek Spark Configuration\n- **API Key**: Create an API key on the [iFlytek Astron MaaS platform]({api_key_url})\n- **Base Url**: Defaults to the pay-as-you-go endpoint `{default_base_url}`. Token Plan keys only work on `https://maas-token-api.cn-huabei-1.xf-yun.com/v2`\n- **Model Name**: Defaults to `{default_model}`; see the [model square]({model_docs_url}) for other model IDs\n\nSpark X2.5 is a reasoning model; the service layer keeps only the final answer.",
"llm_provider_tips.modelscope": "##### ModelScope Configuration\n- **API Key**: create one by following the [ModelScope documentation]({api_key_url})\n- **Base Url**: defaults to `{default_base_url}`\n- **Model Name**: defaults to `{default_model}`; see the [model list](https://modelscope.cn/models?filter=inference_type&page=1)",
"llm_provider_tips.cloudflare": "##### Cloudflare AI Gateway Configuration\n- **API Key**: create a token in the [Cloudflare dashboard]({api_key_url}) with `AI Gateway - Read`, `AI Gateway - Edit`, and `Workers AI - Read` permissions\n- **Account ID**: enter your Cloudflare account ID\n- **Gateway ID**: defaults to `{default_gateway_id}`; you can also enter an existing Gateway ID\n- **Base Url**: not required; the REST API endpoint is generated from the Account ID\n- **Model Name**: defaults to `{default_model}`; use the `provider/model` format for another model supported by AI Gateway",
"llm_provider_tips.minimax": "##### MiniMax Configuration\n- **API Key**: create one on the [China platform](https://platform.minimaxi.com/) or [international platform](https://platform.minimax.io/)\n- **Base Url**: use `https://api.minimaxi.com/v1` for China or `{default_base_url}` for international access (default)\n- **Model Name**: defaults to `{default_model}`; you can also enter another model ID available to your account\n\nMake sure the API Key and Base Url belong to the same platform, or authentication may fail.",
diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json
index 61b845cc..65eb4155 100644
--- a/webui/i18n/zh.json
+++ b/webui/i18n/zh.json
@@ -509,6 +509,7 @@
"llm_provider_tips.groq": "##### Groq 配置说明\n- **API Key**: 在 [Groq Console]({api_key_url}) 创建\n- **Base Url**: 默认 `{default_base_url}`\n- **Model Name**: 默认 `{default_model}`;也可以从接口加载当前账号支持的模型",
"llm_provider_tips.deepseek": "##### DeepSeek 配置说明\n- **API Key**: 在 [DeepSeek Platform]({api_key_url}) 创建\n- **Base Url**: 默认 `{default_base_url}`\n- **Model Name**: 默认 `{default_model}`;也可以填写当前账号支持的其它模型 ID",
"llm_provider_tips.mimo": "##### Xiaomi MiMo 配置说明\n- **API Key**: 按照 [MiMo 官方文档]({api_key_url}) 创建\n- **Base Url**: 默认 `{default_base_url}`\n- **Model Name**: 默认 `{default_model}`;也可以填写官方支持的其它模型 ID",
+ "llm_provider_tips.iflytek": "##### 讯飞星火配置说明\n- **API Key**: 在 [讯飞星辰 MaaS 平台]({api_key_url}) 创建 API Key\n- **Base Url**: 默认按量付费地址 `{default_base_url}`;Token Plan 的 API Key 只能用于 `https://maas-token-api.cn-huabei-1.xf-yun.com/v2`\n- **Model Name**: 默认 `{default_model}`;其它模型 ID 见 [模型广场]({model_docs_url})\n\nSpark X2.5 是推理模型,服务层只保留最终回答。",
"llm_provider_tips.modelscope": "##### ModelScope 配置说明\n- **API Key**: 按照 [ModelScope 文档]({api_key_url}) 创建\n- **Base Url**: 默认 `{default_base_url}`\n- **Model Name**: 默认 `{default_model}`;[查看模型列表](https://modelscope.cn/models?filter=inference_type&page=1)",
"llm_provider_tips.cloudflare": "##### Cloudflare AI Gateway 配置说明\n- **API Key**: 在 [Cloudflare 控制台]({api_key_url}) 创建 API Token,需要 `AI Gateway - Read`、`AI Gateway - Edit` 和 `Workers AI - Read` 权限\n- **Account ID**: 填写 Cloudflare 账号 ID\n- **Gateway ID**: 默认 `{default_gateway_id}`;也可以填写已创建的 Gateway ID\n- **Base Url**: 无需填写,程序会根据 Account ID 自动构造 REST API 地址\n- **Model Name**: 默认 `{default_model}`;使用 `provider/model` 格式填写 AI Gateway 支持的模型 ID",
"llm_provider_tips.minimax": "##### MiniMax 配置说明\n- **API Key**: 在 [中国站](https://platform.minimaxi.com/) 或 [国际站](https://platform.minimax.io/) 创建\n- **Base Url**: 中国站使用 `https://api.minimaxi.com/v1`;国际站使用 `{default_base_url}`(默认)\n- **Model Name**: 默认 `{default_model}`;也可以填写当前账号支持的其它模型 ID\n\n请确保 API Key 与 Base Url 来自同一平台,否则可能出现鉴权失败。",