feat: add china operator llm providers

This commit is contained in:
jxxghp
2026-05-24 09:30:41 +08:00
parent 6430b864b4
commit dc73d61682
4 changed files with 261 additions and 2 deletions

View File

@@ -342,6 +342,127 @@ class LlmProviderRegistryTest(unittest.TestCase):
self.assertEqual(models, [])
def test_builtin_provider_includes_china_operator_token_services(self):
"""三大运营商 Token 服务应作为内置 OpenAI-compatible provider 暴露。"""
manager = LLMProviderManager()
unicom = manager.get_provider("china-unicom")
mobile = manager.get_provider("china-mobile")
telecom = manager.get_provider("china-telecom")
self.assertEqual(unicom.name, "中国联通")
self.assertEqual(unicom.default_base_url, "https://aigw-gzgy2.cucloud.cn:8443/v1")
self.assertEqual(
tuple((preset.id, preset.value, preset.runtime) for preset in unicom.base_url_presets),
(
(
"china-unicom-coding-openai",
"https://aigw-gzgy2.cucloud.cn:8443/v1",
None,
),
(
"china-unicom-coding-anthropic",
"https://aigw-gzgy2.cucloud.cn:8443",
"anthropic_compatible",
),
),
)
self.assertTrue(unicom.base_url_editable)
self.assertFalse(unicom.supports_model_refresh)
self.assertEqual(unicom.model_list_strategy, "manual")
self.assertEqual(mobile.name, "中国移动")
self.assertEqual(mobile.default_base_url, "https://ecloud.10086.cn/api")
self.assertEqual(
tuple((preset.id, preset.value) for preset in mobile.base_url_presets),
(
("china-mobile-moma", "https://ecloud.10086.cn/api"),
(
"china-mobile-coding",
"https://zhenze-huhehaote.cmecloud.cn/api/coding/v1",
),
),
)
self.assertTrue(mobile.base_url_editable)
self.assertFalse(mobile.supports_model_refresh)
self.assertEqual(mobile.model_list_strategy, "manual")
self.assertEqual(telecom.name, "中国电信")
self.assertEqual(telecom.default_base_url, "https://wishub-x6.ctyun.cn/v1")
self.assertEqual(telecom.api_key_label, "App Key")
self.assertEqual(
tuple(
(preset.id, preset.value, preset.runtime, preset.model_list_strategy)
for preset in telecom.base_url_presets
),
(
(
"china-telecom-token-service",
"https://wishub-x6.ctyun.cn/v1",
None,
None,
),
(
"china-telecom-coding-openai",
"https://wishub-x6.ctyun.cn/coding/v1",
None,
"manual",
),
(
"china-telecom-coding-anthropic",
"https://wishub-x6.ctyun.cn/coding/v1",
"anthropic_compatible",
"manual",
),
),
)
self.assertTrue(telecom.base_url_editable)
def test_china_operator_manual_model_presets_return_empty_model_list(self):
"""未提供稳定全局模型目录的运营商套餐应回退为手动填写模型。"""
manager = LLMProviderManager()
unicom_models = asyncio.run(manager.list_models(provider_id="china-unicom"))
mobile_models = asyncio.run(manager.list_models(provider_id="china-mobile"))
telecom_coding_models = asyncio.run(
manager.list_models(
provider_id="china-telecom",
base_url_preset_id="china-telecom-coding-openai",
)
)
self.assertEqual(unicom_models, [])
self.assertEqual(mobile_models, [])
self.assertEqual(telecom_coding_models, [])
def test_china_operator_anthropic_presets_resolve_runtime(self):
"""运营商提供 Anthropic 协议地址时应切换到 anthropic_compatible runtime。"""
manager = LLMProviderManager()
unicom_runtime = asyncio.run(
manager.resolve_runtime(
provider_id="china-unicom",
model=None,
api_key="sk-test",
base_url="https://aigw-gzgy2.cucloud.cn:8443",
base_url_preset_id="china-unicom-coding-anthropic",
)
)
telecom_runtime = asyncio.run(
manager.resolve_runtime(
provider_id="china-telecom",
model=None,
api_key="cp-test",
base_url="https://wishub-x6.ctyun.cn/coding/v1",
base_url_preset_id="china-telecom-coding-anthropic",
)
)
self.assertEqual(unicom_runtime["runtime"], "anthropic_compatible")
self.assertEqual(unicom_runtime["base_url"], "https://aigw-gzgy2.cucloud.cn:8443")
self.assertEqual(telecom_runtime["runtime"], "anthropic_compatible")
self.assertEqual(telecom_runtime["base_url"], "https://wishub-x6.ctyun.cn/coding")
def test_builtin_minimax_provider_merges_general_and_coding_presets(self):
manager = LLMProviderManager()

View File

@@ -185,7 +185,8 @@ class LocalSetupLlmProviderPromptTests(unittest.TestCase):
self.assertEqual(provider, "my-provider_01")
def test_fallback_provider_choices_include_baidu_jdcloud_and_wanqing(self):
def test_fallback_provider_choices_include_builtin_domestic_token_providers(self):
"""本地向导兜底列表应覆盖内置国内 Token 套餐 provider。"""
module = load_local_setup_module()
self.assertEqual(
@@ -197,8 +198,21 @@ class LocalSetupLlmProviderPromptTests(unittest.TestCase):
module.LLM_PROVIDER_FALLBACK_CHOICES["kuaishou-wanqing"],
"快手万擎",
)
self.assertEqual(
module.LLM_PROVIDER_FALLBACK_CHOICES["china-unicom"],
"中国联通",
)
self.assertEqual(
module.LLM_PROVIDER_FALLBACK_CHOICES["china-mobile"],
"中国移动",
)
self.assertEqual(
module.LLM_PROVIDER_FALLBACK_CHOICES["china-telecom"],
"中国电信",
)
def test_local_setup_defaults_include_baidu_jdcloud_and_wanqing_base_urls(self):
def test_local_setup_defaults_include_builtin_domestic_token_base_urls(self):
"""本地向导默认 Base URL 应覆盖内置国内 Token 套餐 provider。"""
module = load_local_setup_module()
self.assertEqual(
@@ -217,6 +231,30 @@ class LocalSetupLlmProviderPromptTests(unittest.TestCase):
module.LLM_PROVIDER_DEFAULTS["kuaishou-wanqing"]["base_url_preset"],
"kuaishou-wanqing-usage",
)
self.assertEqual(
module.LLM_PROVIDER_DEFAULTS["china-unicom"]["base_url"],
"https://aigw-gzgy2.cucloud.cn:8443/v1",
)
self.assertEqual(
module.LLM_PROVIDER_DEFAULTS["china-unicom"]["base_url_preset"],
"china-unicom-coding-openai",
)
self.assertEqual(
module.LLM_PROVIDER_DEFAULTS["china-mobile"]["base_url"],
"https://ecloud.10086.cn/api",
)
self.assertEqual(
module.LLM_PROVIDER_DEFAULTS["china-mobile"]["base_url_preset"],
"china-mobile-moma",
)
self.assertEqual(
module.LLM_PROVIDER_DEFAULTS["china-telecom"]["base_url"],
"https://wishub-x6.ctyun.cn/v1",
)
self.assertEqual(
module.LLM_PROVIDER_DEFAULTS["china-telecom"]["base_url_preset"],
"china-telecom-token-service",
)
def test_collect_agent_config_prompts_for_duplicate_base_url_presets(self):
module = load_local_setup_module()