Skip to content

Go: implement Xiaomi chat provider - #15626

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
tmimmanuel:go/xiaomi-chat-provider
Jun 8, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
tmimmanuel:go/xiaomi-chat-provider

Conversation

@tmimmanuel

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Implements the Xiaomi MiMo chat provider for the Go model provider layer.

Reference issue: #14736

Official docs used:

This PR adds:

  • XiaomiModel with non-streaming and streaming chat completions.
  • Xiaomi-specific request shape using api-key auth and max_completion_tokens.
  • reasoning_content passthrough for thinking responses and streaming deltas.
  • Provider registration in the Go model factory.
  • Xiaomi model catalog entries for documented text generation models: mimo-v2.5-pro, mimo-v2.5, and mimo-v2-flash.
  • Focused unit tests for request shape, streaming, error handling, factory registration, and unsupported interfaces.

Unsupported methods return the standard no such method sentinel for embedding, rerank, audio, OCR, balance, tasks, and model listing because this PR is scoped to the chat provider surface.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

Tests:

$ go test ./internal/entity/models -run 'TestXiaomi'
ok  	ragflow/internal/entity/models	0.023s

$ python3 -m json.tool conf/models/xiaomi.json >/dev/null && python3 -m json.tool conf/llm_factories.json >/dev/null
# passed

$ git diff --check
# passed

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Complex PR? Review this PR in Change Stack to move by importance, not file order.

Review Change Stack

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: fc3a8630-9801-4ead-8698-51a312a8ea36

📥 Commits

Reviewing files that changed from the base of the PR and between 6c075dd and cad7295.

📒 Files selected for processing (5)
  • conf/llm_factories.json
  • conf/models/xiaomi.json
  • internal/entity/models/factory.go
  • internal/entity/models/xiaomi.go
  • internal/entity/models/xiaomi_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • conf/models/xiaomi.json
  • internal/entity/models/factory.go
  • conf/llm_factories.json
  • internal/entity/models/xiaomi_test.go
  • internal/entity/models/xiaomi.go

📝 Walkthrough

Walkthrough

Adds Xiaomi provider entries and model config, registers xiaomi in the model factory, implements XiaomiModel with non‑streaming and streaming chat, provides unsupported-method stubs, and adds comprehensive unit tests.

Changes

Xiaomi model integration

Layer / File(s) Summary
Factory registration and configs
internal/entity/models/factory.go, conf/llm_factories.json, conf/models/xiaomi.json
Register xiaomi in CreateModelDriver and add provider + model configuration entries for Xiaomi and its models.
Constructor and transport setup
internal/entity/models/xiaomi.go
XiaomiModel type and NewXiaomiModel constructor create an http.Client with cloned/fallback transport and base-URL routing helpers.
Request/response shapes and request builder
internal/entity/models/xiaomi.go
API key retrieval, buildXiaomiChatRequest mapping (uses max_completion_tokens), Xiaomi JSON types, and newXiaomiJSONRequest helper.
Non-streaming chat
internal/entity/models/xiaomi.go
ChatWithMessages POSTs JSON, checks status/error, unmarshals response, and returns ChatResponse with answer and optional reasoning.
Streaming chat (SSE)
internal/entity/models/xiaomi.go
ChatStreamlyWithSender posts with streaming=true, parses SSE-like data: frames, dispatches incremental content/reasoning via sender, and handles finish/premature termination.
Unsupported-method stubs
internal/entity/models/xiaomi.go
Embeddings, Rerank, Transcribe, TTS, OCR, task APIs implemented as stubs returning “no such method”.
Tests and helpers
internal/entity/models/xiaomi_test.go
Test HTTP server helper and unit tests covering factory/name, transport override, chat request/response parsing, base-URL overrides, input validation, HTTP error propagation, streaming happy/malformed paths, and unsupported-method checks.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

💞 feature

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped in code to add a friend,
Xiaomi models join the trend.
Streams that sing and tests that pass,
Small hops of code across the grass.
Here’s a carrot for the reviewer’s hand.

🚥 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
Title check ✅ Passed The title 'Go: implement Xiaomi chat provider' clearly and concisely describes the main change: adding Xiaomi chat provider support to the Go layer.
Description check ✅ Passed The description follows the template with both required sections filled: 'What problem does this PR solve?' is comprehensive with references and details, and 'Type of change' is completed with 'New Feature' selected. Test results are included.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/xiaomi.go`:
- Around line 76-93: The code currently replaces empty region with "default" in
XiaomiModel.endpointURL which prevents using a configured empty-string override;
restore the raw region value and implement a fallback lookup in baseURLForRegion
so it checks keys in this order: exact region -> "" -> "default". Concretely,
keep the original region string (do not rewrite "" to "default") in endpointURL
and call baseURLForRegion(region); then modify baseURLForRegion to try
m.BaseURL[region], then m.BaseURL[""], then m.BaseURL["default"], returning the
first non-empty result or the existing error if none found.
🪄 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: cf9334b4-6af8-48e0-86fc-f55157e3ce6d

📥 Commits

Reviewing files that changed from the base of the PR and between bbacb31 and 1a9112b.

📒 Files selected for processing (5)
  • conf/llm_factories.json
  • conf/models/xiaomi.json
  • internal/entity/models/factory.go
  • internal/entity/models/xiaomi.go
  • internal/entity/models/xiaomi_test.go

Comment thread internal/entity/models/xiaomi.go Resolved
@yingfeng yingfeng added the ci Continue Integration label Jun 4, 2026
@yingfeng
yingfeng marked this pull request as draft June 4, 2026 02:29
@yingfeng
yingfeng marked this pull request as ready for review June 4, 2026 02:29
@Haruko386

Copy link
Copy Markdown
Member

@tmimmanuel We r refactoring model provider, I shall review code later

@tmimmanuel
tmimmanuel force-pushed the go/xiaomi-chat-provider branch from 1a9112b to 2d7eb6a Compare June 4, 2026 02:57
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 4, 2026
@Haruko386

Copy link
Copy Markdown
Member

@tmimmanuel please refer #15627 for model provider refactor and commit it later

@Haruko386 Haruko386 added invalid This doesn't seem right and removed invalid This doesn't seem right labels Jun 5, 2026
@Haruko386

Copy link
Copy Markdown
Member

@tmimmanuel will you implement Xiaomi provider?
Or I will submit PR tonight

@tmimmanuel

Copy link
Copy Markdown
Contributor Author

I will submit now.

@tmimmanuel
tmimmanuel force-pushed the go/xiaomi-chat-provider branch from 2d7eb6a to 6c075dd Compare June 5, 2026 21:53
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 5, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/xiaomi.go`:
- Around line 350-368: The loop that reads SSE lines via scanner.Scan() treats
only line == "" as an event separator, but CRLF separators produce a line of
"\r" so frames never flush; update the handling in the scanner loop (the block
using variable line, strings.HasPrefix checks, dataLines and dispatchEvent()) to
normalize CRLF by trimming a trailing '\r' (e.g., line =
strings.TrimSuffix(line, "\r") or test strings.TrimSpace(line) == "") before
checking emptiness or "data:" prefix so that "\r" is treated as an empty
separator and data: lines are parsed correctly.
🪄 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: 0ecceeab-7e9a-4a4b-9931-1d9b78324042

📥 Commits

Reviewing files that changed from the base of the PR and between 2d7eb6a and 6c075dd.

📒 Files selected for processing (5)
  • conf/llm_factories.json
  • conf/models/xiaomi.json
  • internal/entity/models/factory.go
  • internal/entity/models/xiaomi.go
  • internal/entity/models/xiaomi_test.go
💤 Files with no reviewable changes (1)
  • internal/entity/models/xiaomi_test.go
✅ Files skipped from review due to trivial changes (1)
  • conf/models/xiaomi.json

Comment thread internal/entity/models/xiaomi.go Resolved
@tmimmanuel
tmimmanuel force-pushed the go/xiaomi-chat-provider branch from 6c075dd to cad7295 Compare June 5, 2026 22:05

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @tmimmanuel
LGTM, but would you provide your test result in RAGflow CLI?

@tmimmanuel

Copy link
Copy Markdown
Contributor Author

Hi @Haruko386, I ran live testing through ragflow_cli with a real Xiaomi MiMo API key. The key is redacted below.

Environment:

  • Branch/commit: go/xiaomi-chat-provider / cad72957a1cbff9de99f8fae9b08515930177c72
  • RAGFlow Go server: v0.25.4-365-gcad72957a
  • Go API: 127.0.0.1:9384
  • Model: mimo-v2-flash
Welcome to RAGFlow CLI
Type \? for help, \q to quit

RAGFlow(user)> Register successfully
RAGFlow(user)> Login user [email protected] successfully
RAGFlow(user)> SUCCESS
RAGFlow(user)> SUCCESS
RAGFlow(user)> +------------+---------------+---------------+--------+
| max_tokens | model_types   | name          | status |
+------------+---------------+---------------+--------+
| 1048576    | [chat]        | mimo-v2.5-pro | active |
| 1048576    | [chat vision] | mimo-v2.5     | active |
| 262144     | [chat]        | mimo-v2-flash | active |
+------------+---------------+---------------+--------+
RAGFlow(user)> Answer: Xiaomi live test OK
Time: 0.610326
RAGFlow(user)> Goodbye!

Commands executed:

register user '[email protected]' as 'Xiaomi Live' password '***';
login user '[email protected]' password '***';
add provider 'xiaomi';
create provider 'xiaomi' instance 'live-test' key '[REDACTED]';
list models from 'xiaomi' 'live-test';
chat with 'mimo-v2-flash@live-test@xiaomi' message 'Reply with exactly: Xiaomi live test OK';

Also re-ran the focused unit tests:

go test ./internal/entity/models -run 'TestXiaomi'
ok  ragflow/internal/entity/models

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tmimmanuel LGTM
Thank you for your contribution

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 8, 2026
@JinHai-CN
JinHai-CN merged commit 5e25e26 into infiniflow:main Jun 8, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants