Skip to content

feat: Add Xiaomi channel support and enhance TTS functionality#3479

Open
HynoR wants to merge 6 commits intoQuantumNous:mainfrom
HynoR:feat/xm
Open

feat: Add Xiaomi channel support and enhance TTS functionality#3479
HynoR wants to merge 6 commits intoQuantumNous:mainfrom
HynoR:feat/xm

Conversation

@HynoR
Copy link
Copy Markdown
Contributor

@HynoR HynoR commented Mar 28, 2026

添加小米渠道支持,并支持小米 tts 从 chat completion 接口到 openai tts 接口 的转换
fix #3353

测试结果 tts -> xiaomi tts chat
image

测试结构 chat -> xiaomi tts chat
image

计费
image

喜闻乐见
image
image
image

This pull request adds support for the Xiaomi MiMo channel throughout the codebase, enabling Xiaomi MiMo as a new AI provider. The changes include defining new constants and configuration for Xiaomi, implementing the channel adaptor and response handling, updating pricing and model ratios, and exposing the channel in the frontend options.

Xiaomi MiMo Channel Integration:

  • Added new channel and API type constants for Xiaomi MiMo, including ChannelTypeXiaomi and APITypeXiaomi, and updated mappings for names and base URLs. [1] [2] [3] [4] [5]
  • Implemented Xiaomi MiMo channel adaptor (adaptor.go) and TTS response handler (tts.go), supporting audio requests and response decoding. [1] [2]
  • Added Xiaomi MiMo model list and channel name constants.
  • Registered Xiaomi MiMo as a supported channel in the relay adaptor and enabled streaming support. [1] [2] [3]

Pricing and Model Configuration:

  • Added Xiaomi MiMo vendor and model pricing information to default vendor rules and model ratio settings. [1] [2]

Frontend Exposure:

  • Added Xiaomi MiMo as an option in the frontend channel selection list.

Summary by CodeRabbit

  • New Features

    • Added Xiaomi MiMo provider with four model variants (mimo-v2-pro, mimo-v2-flash, mimo-v2-omni, mimo-v2-tts)
    • Enabled chat completions and on-device audio speech synthesis (TTS) for Xiaomi
    • UI updated to show Xiaomi channel option
  • Configuration

    • Default vendor/model mapping and pricing ratios added for Xiaomi models
  • Bug Fixes

    • Fixed provider routing so Xiaomi channels are properly recognized and used

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 632d0591-dbdb-4a47-840f-89ce8f522598

📥 Commits

Reviewing files that changed from the base of the PR and between 49d2a99 and a1f7de6.

📒 Files selected for processing (1)
  • relay/channel/xiaomi/tts.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • relay/channel/xiaomi/tts.go

Walkthrough

Adds Xiaomi MiMo as a new relay channel: new constants and mappings, a Xiaomi adaptor implementing chat completions and TTS conversion/handling, vendor/pricing defaults for mimo models, frontend channel option, and wiring into the adaptor factory and relay metadata.

Changes

Cohort / File(s) Summary
Constants & Channel Definitions
constant/api_type.go, constant/channel.go, relay/channel/xiaomi/constants.go
Introduce APITypeXiaomi, ChannelTypeXiaomi = 58, Xiaomi base URL and name, and exported ModelList/ChannelName.
Xiaomi Relay Adaptor & TTS
relay/channel/xiaomi/adaptor.go, relay/channel/xiaomi/tts.go
Add Xiaomi adaptor implementing request URL/header mapping, OpenAI→MiMo request conversions (including TTS payload creation), DoRequest/DoResponse, and TTS response base64 decode + MIME handling.
Adaptor Registration & Type Mapping
common/api_type.go, relay/relay_adaptor.go, relay/common/relay_info.go
Map channel type 58→APITypeXiaomi, register Xiaomi adaptor in factory, mark Xiaomi as stream-supported.
Vendor & Pricing Defaults
model/pricing_default.go, setting/ratio_setting/model_ratio.go
Add vendor auto-match rule mapping "mimo""小米" and default pricing ratios for mimo-v2-pro, mimo-v2-flash, mimo-v2-omni.
Frontend
web/src/constants/channel.constants.js
Add channel option for Xiaomi MiMo (value: 58, orange label).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RelaySystem as Relay System
    participant Adaptor as Xiaomi Adaptor
    participant XiaomiAPI as Xiaomi API
    participant Handler as Response Handler

    Client->>RelaySystem: OpenAI-style request (/v1/chat or /v1/audio/speech)
    RelaySystem->>Adaptor: route based on channel/model

    alt Chat completion
        Adaptor->>XiaomiAPI: POST /v1/chat/completions (Bearer token)
        XiaomiAPI-->>Adaptor: JSON response
        Adaptor->>Handler: delegate to OpenAI response handler
        Handler-->>Client: JSON/streamed chat response
    else Audio/TTS (mimo-v2-tts)
        Adaptor->>Adaptor: convert OpenAI audio request → MiMo chat TTS JSON (voice=format)
        Adaptor->>XiaomiAPI: POST /v1/chat/completions (Bearer token)
        XiaomiAPI-->>Adaptor: JSON with base64 audio
        Adaptor->>Handler: handleTTSResponse (decode, set MIME)
        Handler-->>Client: audio/* binary response
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • PR #2081: Modifies APIType/ChannelType enums and mapping logic—closely related to adding APITypeXiaomi and its mapping.
  • PR #1564: Introduced vendor-mapping infrastructure used by the added "mimo""小米" rule in pricing defaults.
  • PR #2190: Similar pattern of registering a new channel/adaptor and updating type mappings, strongly related at the integration level.

Suggested reviewers

  • seefs001
  • creamlike1024

Poem

🐰 I hopped into code with a twitchy nose,
New constants, adapters, and TTS that glows.
MiMo sings in bytes, base64 made small,
Relay routes, responses, I applaud it all! 🎶

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main changes: adding Xiaomi channel support and implementing TTS functionality across the codebase.
Linked Issues check ✅ Passed All core objectives from #3353 are met: Xiaomi channel constants added, MiMo model support with TTS implemented, OpenAI-compatible audio endpoint conversion working, and chat completion integration with audio decoding complete.
Out of Scope Changes check ✅ Passed All changes are directly scoped to Xiaomi integration: constants, channel adaptor, TTS handling, relay setup, pricing/vendor rules, and frontend UI—with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@relay/channel/xiaomi/adaptor.go`:
- Around line 56-57: The ConvertRerankRequest method currently returns (nil,
nil) which silently allows unsupported rerank traffic; update
Adaptor.ConvertRerankRequest to return an explicit error (e.g., using errors.New
or fmt.Errorf) indicating the provider does not support rerank so callers fail
fast; ensure you update imports to include "errors" or "fmt" and keep the
function signature unchanged so callers can handle the error.

In `@relay/channel/xiaomi/tts.go`:
- Around line 41-49: The resp.Body is only deferred closed after io.ReadAll, so
an early return on readErr leaks the body; move the defer resp.Body.Close() to
immediately after obtaining resp (i.e., just after the resp variable is set) or
right before calling io.ReadAll in the Xiaomi TTS handling code so that
resp.Body is closed on all paths including when readErr triggers the
types.NewErrorWithStatusCode return; update code around resp.Body, body, readErr
and the error-returning path accordingly.

In `@setting/ratio_setting/model_ratio.go`:
- Around line 246-248: The Xiaomi model ratio map is missing an explicit entry
for "mimo-v2-tts", causing it to fall back to the large default in
GetModelRatio; add an explicit key "mimo-v2-tts" to the same map that contains
"mimo-v2-pro"/"mimo-v2-flash"/"mimo-v2-omni" and set it to the intended ratio
(e.g., 0.05 or whatever agreed billing rate) so TTS requests are billed
correctly instead of using the 37.5 fallback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 908406da-8855-4174-a987-6b95923119f2

📥 Commits

Reviewing files that changed from the base of the PR and between fbf235d and 49d2a99.

📒 Files selected for processing (11)
  • common/api_type.go
  • constant/api_type.go
  • constant/channel.go
  • model/pricing_default.go
  • relay/channel/xiaomi/adaptor.go
  • relay/channel/xiaomi/constants.go
  • relay/channel/xiaomi/tts.go
  • relay/common/relay_info.go
  • relay/relay_adaptor.go
  • setting/ratio_setting/model_ratio.go
  • web/src/constants/channel.constants.js

Comment thread relay/channel/xiaomi/adaptor.go
Comment thread relay/channel/xiaomi/tts.go Outdated
Comment thread setting/ratio_setting/model_ratio.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Xiaomi MiMo mimo-v2-tts on OpenAI-compatible /v1/audio/speech

1 participant