feat: Add Xiaomi channel support and enhance TTS functionality#3479
feat: Add Xiaomi channel support and enhance TTS functionality#3479HynoR wants to merge 6 commits intoQuantumNous:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (11)
common/api_type.goconstant/api_type.goconstant/channel.gomodel/pricing_default.gorelay/channel/xiaomi/adaptor.gorelay/channel/xiaomi/constants.gorelay/channel/xiaomi/tts.gorelay/common/relay_info.gorelay/relay_adaptor.gosetting/ratio_setting/model_ratio.goweb/src/constants/channel.constants.js
添加小米渠道支持,并支持小米 tts 从 chat completion 接口到 openai tts 接口 的转换
fix #3353
测试结果 tts -> xiaomi tts chat

测试结构 chat -> xiaomi tts chat

计费

喜闻乐见



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:
ChannelTypeXiaomiandAPITypeXiaomi, and updated mappings for names and base URLs. [1] [2] [3] [4] [5]adaptor.go) and TTS response handler (tts.go), supporting audio requests and response decoding. [1] [2]Pricing and Model Configuration:
Frontend Exposure:
Summary by CodeRabbit
New Features
Configuration
Bug Fixes