mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-01 18:20:16 +08:00
Compare commits
5 Commits
codex/fix-
...
feat/xiaom
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
123342235d | ||
|
|
0455c1c9c3 | ||
|
|
52dbfcbd84 | ||
|
|
3ffcb2c616 | ||
|
|
e7024786b2 |
@@ -1250,6 +1250,31 @@ CONFIG_METADATA_2 = {
|
||||
"custom_headers": {"User-Agent": "claude-code/0.1.0"},
|
||||
"anth_thinking_config": {"type": "", "budget": 0, "effort": ""},
|
||||
},
|
||||
"Xiaomi": {
|
||||
"id": "xiaomi",
|
||||
"provider": "xiaomi",
|
||||
"type": "xiaomi_chat_completion",
|
||||
"provider_type": "chat_completion",
|
||||
"enable": True,
|
||||
"key": [],
|
||||
"api_base": "https://api.xiaomimimo.com/v1",
|
||||
"timeout": 120,
|
||||
"proxy": "",
|
||||
"custom_headers": {},
|
||||
},
|
||||
"Xiaomi Token Plan": {
|
||||
"id": "xiaomi-token-plan",
|
||||
"provider": "xiaomi-token-plan",
|
||||
"type": "xiaomi_token_plan",
|
||||
"provider_type": "chat_completion",
|
||||
"enable": True,
|
||||
"key": [],
|
||||
"api_base": "https://token-plan-cn.xiaomimimo.com/anthropic",
|
||||
"timeout": 120,
|
||||
"proxy": "",
|
||||
"custom_headers": {"User-Agent": "claude-code/0.1.0"},
|
||||
"anth_thinking_config": {"type": "", "budget": 0, "effort": ""},
|
||||
},
|
||||
"xAI": {
|
||||
"id": "xai",
|
||||
"provider": "xai",
|
||||
|
||||
@@ -367,6 +367,12 @@ class ProviderManager:
|
||||
from .sources.minimax_token_plan_source import (
|
||||
ProviderMiniMaxTokenPlan as ProviderMiniMaxTokenPlan,
|
||||
)
|
||||
case "xiaomi_chat_completion":
|
||||
from .sources.xiaomi_source import ProviderXiaomi as ProviderXiaomi
|
||||
case "xiaomi_token_plan":
|
||||
from .sources.xiaomi_token_plan_source import (
|
||||
ProviderXiaomiTokenPlan as ProviderXiaomiTokenPlan,
|
||||
)
|
||||
case "zhipu_chat_completion":
|
||||
from .sources.zhipu_source import ProviderZhipu as ProviderZhipu
|
||||
case "groq_chat_completion":
|
||||
|
||||
56
astrbot/core/provider/sources/xiaomi_source.py
Normal file
56
astrbot/core/provider/sources/xiaomi_source.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from astrbot import logger
|
||||
from astrbot.core.provider.sources.openai_source import ProviderOpenAIOfficial
|
||||
|
||||
from ..register import register_provider_adapter
|
||||
|
||||
XIAOMI_MODELS = [
|
||||
"mimo-v2.5-pro",
|
||||
"mimo-v2.5",
|
||||
"mimo-v2-pro",
|
||||
"mimo-v2-omni",
|
||||
"mimo-v2-flash",
|
||||
]
|
||||
|
||||
|
||||
@register_provider_adapter(
|
||||
"xiaomi_chat_completion", "Xiaomi API 提供商适配器 (OpenAI 兼容)"
|
||||
)
|
||||
class ProviderXiaomi(ProviderOpenAIOfficial):
|
||||
"""Xiaomi provider using OpenAI-compatible API.
|
||||
|
||||
Supports both standard API and multimodal capabilities.
|
||||
See https://platform.xiaomimimo.com/docs/api/chat/openai-api
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
provider_config,
|
||||
provider_settings,
|
||||
) -> None:
|
||||
# Ensure api_base is set to Xiaomi endpoint if not provided
|
||||
if not provider_config.get("api_base"):
|
||||
provider_config["api_base"] = "https://api.xiaomimimo.com/v1"
|
||||
|
||||
super().__init__(
|
||||
provider_config,
|
||||
provider_settings,
|
||||
)
|
||||
|
||||
configured_model = provider_config.get("model", "mimo-v2.5")
|
||||
self.set_model(configured_model)
|
||||
|
||||
logger.debug(f"Xiaomi provider initialized with model: {self.get_model()}")
|
||||
|
||||
async def get_models(self) -> list[str]:
|
||||
"""Return the list of known Xiaomi models.
|
||||
|
||||
Tries to fetch from API first, falls back to hard-coded list if unavailable.
|
||||
"""
|
||||
try:
|
||||
models = await super().get_models()
|
||||
if models:
|
||||
return models
|
||||
except Exception as e:
|
||||
logger.debug(f"Failed to fetch models from Xiaomi API: {e}")
|
||||
|
||||
return XIAOMI_MODELS.copy()
|
||||
59
astrbot/core/provider/sources/xiaomi_token_plan_source.py
Normal file
59
astrbot/core/provider/sources/xiaomi_token_plan_source.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from astrbot import logger
|
||||
from astrbot.core.provider.sources.anthropic_source import ProviderAnthropic
|
||||
|
||||
from ..register import register_provider_adapter
|
||||
|
||||
XIAOMI_TOKEN_PLAN_MODELS = [
|
||||
"mimo-v2.5-pro",
|
||||
"mimo-v2.5",
|
||||
"mimo-v2-pro",
|
||||
"mimo-v2-omni",
|
||||
"mimo-v2-flash",
|
||||
]
|
||||
|
||||
|
||||
@register_provider_adapter("xiaomi_token_plan", "Xiaomi Token Plan 提供商适配器")
|
||||
class ProviderXiaomiTokenPlan(ProviderAnthropic):
|
||||
"""Xiaomi Token Plan provider.
|
||||
|
||||
The Token Plan API uses Anthropic-compatible endpoint with Bearer token auth.
|
||||
See https://platform.xiaomimimo.com/docs/tokenplan/quick-access
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
provider_config,
|
||||
provider_settings,
|
||||
) -> None:
|
||||
# Keep api_base fixed; Token Plan users do not need to configure it.
|
||||
provider_config["api_base"] = "https://token-plan-cn.xiaomimimo.com/anthropic"
|
||||
|
||||
# Xiaomi Token Plan requires the Authorization: Bearer <token> header.
|
||||
keys = provider_config.get("key", [])
|
||||
actual_key = keys[0] if isinstance(keys, list) and keys else keys
|
||||
if actual_key:
|
||||
provider_config.setdefault("custom_headers", {})["Authorization"] = (
|
||||
f"Bearer {actual_key}"
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
provider_config,
|
||||
provider_settings,
|
||||
)
|
||||
|
||||
configured_model = provider_config.get("model", "mimo-v2.5")
|
||||
if configured_model not in XIAOMI_TOKEN_PLAN_MODELS:
|
||||
logger.warning(
|
||||
f"Configured model {configured_model!r} is not in the known "
|
||||
f"Token Plan model list "
|
||||
f"({', '.join(XIAOMI_TOKEN_PLAN_MODELS)}). "
|
||||
f"The model may still work if your plan supports it. "
|
||||
f"If you encounter errors, please check your plan's "
|
||||
f"model availability."
|
||||
)
|
||||
|
||||
self.set_model(configured_model)
|
||||
|
||||
async def get_models(self) -> list[str]:
|
||||
"""Return the hard-coded known model list because Token Plan cannot fetch it dynamically."""
|
||||
return XIAOMI_TOKEN_PLAN_MODELS.copy()
|
||||
@@ -34,7 +34,9 @@ export function getProviderIcon(type) {
|
||||
'fishaudio': 'https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@latest/icons/fishaudio.svg',
|
||||
'minimax': 'https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@latest/icons/minimax.svg',
|
||||
'minimax-token-plan': 'https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@latest/icons/minimax.svg',
|
||||
'mimo': 'https://platform.xiaomimimo.com/favicon.874c9507.png',
|
||||
'mimo': 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/xiaomi.svg',
|
||||
'xiaomi': 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/xiaomi.svg',
|
||||
'xiaomi-token-plan': 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/xiaomi.svg',
|
||||
'302ai': 'https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@1.53.0/icons/ai302-color.svg',
|
||||
'microsoft': 'https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@latest/icons/microsoft.svg',
|
||||
'vllm': 'https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@latest/icons/vllm.svg',
|
||||
|
||||
Reference in New Issue
Block a user