feat: 新增 Xiaomi 和 Xiaomi Token Plan LLM 提供商 by HosisoraLing · Pull Request #7744 · AstrBotDevs/AstrBot · GitHub
Skip to content

feat: 新增 Xiaomi 和 Xiaomi Token Plan LLM 提供商#7744

Open
HosisoraLing wants to merge 1 commit intoAstrBotDevs:masterfrom
HosisoraLing:feat/xiaomi-provider
Open

feat: 新增 Xiaomi 和 Xiaomi Token Plan LLM 提供商#7744
HosisoraLing wants to merge 1 commit intoAstrBotDevs:masterfrom
HosisoraLing:feat/xiaomi-provider

Conversation

@HosisoraLing
Copy link
Copy Markdown

@HosisoraLing HosisoraLing commented Apr 23, 2026

概述

  • 新增 Xiaomi provider(OpenAI 兼容)
  • 新增 Xiaomi Token Plan provider(Anthropic 兼容)
  • 支持全模态(图片理解)
  • 内置 MiMo v2.5 系列模型

Summary by Sourcery

Add Xiaomi and Xiaomi Token Plan as new chat completion providers with support for MiMo v2.x models.

New Features:

  • Introduce a Xiaomi provider using an OpenAI-compatible chat completion API with multimodal support.
  • Introduce a Xiaomi Token Plan provider using an Anthropic-compatible API for MiMo v2.x models.

Enhancements:

  • Register Xiaomi providers in the dynamic provider manager and update the dashboard to show Xiaomi-specific icons for the new providers and existing MiMo provider.

@auto-assign auto-assign Bot requested review from LIghtJUNction and Soulter April 23, 2026 08:50
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 23, 2026
- 新增 Xiaomi provider(OpenAI 兼容)
- 新增 Xiaomi Token Plan provider(Anthropic 兼容)
- 支持全模态(图片理解)
- 内置 MiMo v2.5 系列模型
@dosubot dosubot Bot added the area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. label Apr 23, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In ProviderXiaomiTokenPlan.__init__, accessing key[0] will raise an IndexError when key is an empty list, so add a guard (e.g., check for a non-empty list or falsy value) before deriving actual_key.
  • The Xiaomi model list is duplicated in both xiaomi_source.py and xiaomi_token_plan_source.py; consider centralizing this constant in a shared module to keep the supported models in sync.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ProviderXiaomiTokenPlan.__init__`, accessing `key[0]` will raise an IndexError when `key` is an empty list, so add a guard (e.g., check for a non-empty list or falsy value) before deriving `actual_key`.
- The Xiaomi model list is duplicated in both `xiaomi_source.py` and `xiaomi_token_plan_source.py`; consider centralizing this constant in a shared module to keep the supported models in sync.

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/xiaomi_token_plan_source.py" line_range="49-51" />
<code_context>
+        provider_config["api_base"] = "https://token-plan-cn.xiaomimimo.com/anthropic"
+
+        # Xiaomi Token Plan requires the Authorization: Bearer <token> header.
+        key = provider_config.get("key", "")
+        actual_key = key[0] if isinstance(key, list) else key
+        provider_config.setdefault("custom_headers", {})["Authorization"] = (
+            f"Bearer {actual_key}"
+        )
</code_context>
<issue_to_address>
**issue:** Guard against empty or missing Xiaomi Token Plan keys before setting the Authorization header.

If `key` is `[]` (default or from user config), `actual_key` becomes an empty string and you still send `Authorization: Bearer `. That hides configuration issues and leads to confusing 401s. Please handle empty/missing keys explicitly (e.g., raise a configuration error or skip the header and log a clear warning) so misconfigurations are surfaced early and invalid headers aren’t sent.
</issue_to_address>

### Comment 2
<location path="astrbot/core/provider/sources/xiaomi_token_plan_source.py" line_range="6-12" />
<code_context>
+
+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",
+]
+
+
</code_context>
<issue_to_address>
**suggestion:** Avoid duplication of Xiaomi model lists across providers to reduce drift risk.

The Xiaomi Token Plan and standard Xiaomi provider each maintain their own, nearly identical model lists. To avoid them drifting out of sync when models change, centralize this list (e.g., in a shared module/constant) and reuse it in both providers, or derive one from the other so updates happen in only one place.

Suggested implementation:

```python
from astrbot import logger
from astrbot.core.provider.sources.anthropic_source import ProviderAnthropic

from ..register import register_provider_adapter
from .xiaomi_models import XIAOMI_MODELS

XIAOMI_TOKEN_PLAN_MODELS = XIAOMI_MODELS

```

To fully avoid duplication and drift, you should also:
1. Create a new module `astrbot/core/provider/sources/xiaomi_models.py` that defines the single source of truth, for example:
   - `XIAOMI_MODELS = ["mimo-v2.5-pro", "mimo-v2.5", "mimo-v2-pro", "mimo-v2-omni", "mimo-v2-flash"]`
2. Update the standard Xiaomi provider file (likely `astrbot/core/provider/sources/xiaomi_source.py`) to:
   - Remove its local Xiaomi model list.
   - Import and use `XIAOMI_MODELS` from `.xiaomi_models` instead.
3. If the token plan provider needs a subset/superset in the future, derive `XIAOMI_TOKEN_PLAN_MODELS` from `XIAOMI_MODELS` (e.g., filtering) rather than hardcoding a separate list.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +49 to +51
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Guard against empty or missing Xiaomi Token Plan keys before setting the Authorization header.

If key is [] (default or from user config), actual_key becomes an empty string and you still send Authorization: Bearer . That hides configuration issues and leads to confusing 401s. Please handle empty/missing keys explicitly (e.g., raise a configuration error or skip the header and log a clear warning) so misconfigurations are surfaced early and invalid headers aren’t sent.

Comment on lines +6 to +12
XIAOMI_TOKEN_PLAN_MODELS = [
"mimo-v2.5-pro",
"mimo-v2.5",
"mimo-v2-pro",
"mimo-v2-omni",
"mimo-v2-flash",
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Avoid duplication of Xiaomi model lists across providers to reduce drift risk.

The Xiaomi Token Plan and standard Xiaomi provider each maintain their own, nearly identical model lists. To avoid them drifting out of sync when models change, centralize this list (e.g., in a shared module/constant) and reuse it in both providers, or derive one from the other so updates happen in only one place.

Suggested implementation:

from astrbot import logger
from astrbot.core.provider.sources.anthropic_source import ProviderAnthropic

from ..register import register_provider_adapter
from .xiaomi_models import XIAOMI_MODELS

XIAOMI_TOKEN_PLAN_MODELS = XIAOMI_MODELS

To fully avoid duplication and drift, you should also:

  1. Create a new module astrbot/core/provider/sources/xiaomi_models.py that defines the single source of truth, for example:
    • XIAOMI_MODELS = ["mimo-v2.5-pro", "mimo-v2.5", "mimo-v2-pro", "mimo-v2-omni", "mimo-v2-flash"]
  2. Update the standard Xiaomi provider file (likely astrbot/core/provider/sources/xiaomi_source.py) to:
    • Remove its local Xiaomi model list.
    • Import and use XIAOMI_MODELS from .xiaomi_models instead.
  3. If the token plan provider needs a subset/superset in the future, derive XIAOMI_TOKEN_PLAN_MODELS from XIAOMI_MODELS (e.g., filtering) rather than hardcoding a separate list.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for Xiaomi and Xiaomi Token Plan chat providers by implementing new provider adapters and updating the configuration defaults and dashboard icons. A critical issue was identified in the Xiaomi Token Plan implementation where an empty key list could cause an IndexError during initialization; a suggestion was provided to handle this more robustly.

Comment on lines +49 to +53
key = provider_config.get("key", "")
actual_key = key[0] if isinstance(key, list) else key
provider_config.setdefault("custom_headers", {})["Authorization"] = (
f"Bearer {actual_key}"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

此处获取 actual_key 的逻辑存在潜在的 IndexError。如果 key 是一个空列表 [](这是 default.py 中的默认值),key[0] 将会导致程序崩溃。建议在访问索引前检查列表是否为空。此外,建议使用更健壮的方式来处理 key 可能为字符串或列表的情况。

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant