Skip to content

refactor(go-models): add unsupported model driver defaults - #15431

Merged
JinHai-CN merged 14 commits into
infiniflow:mainfrom
bitloi:refactor/15430-model-driver-unsupported-defaults
Jun 3, 2026
Merged

JinHai-CN merged 14 commits into
infiniflow:mainfrom
bitloi:refactor/15430-model-driver-unsupported-defaults

Conversation

@bitloi

@bitloi bitloi commented May 29, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Adds a shared safe default implementation for unsupported Go model-driver capability methods and migrates the confirmed panic-stub providers to use it.

The Go ModelDriver interface requires providers to implement many capability methods even when the provider does not support them. XunFei had unsupported capability methods implemented as panic("implement me"), Mistral still had a panic in ParseFile, and HuaweiCloud carried an unreachable panic("implement me") after a normal chat return.

This PR:

  • Adds UnsupportedModelDriver for unsupported non-chat capability methods.
  • Embeds it in XunFei and Mistral while keeping provider-specific Name, NewInstance, chat, stream chat, and model listing explicit.
  • Removes XunFei unsupported-method panic stubs.
  • Lets Mistral unsupported audio/file/task fallbacks use the shared default and aligns Balance/Rerank error formatting.
  • Removes HuaweiCloud's unreachable dead panic after ChatWithMessages.
  • Adds focused regression tests for the shared defaults, XunFei unsupported methods, and Mistral defaulted methods.

Closes #15430

Validation:

  • git diff --check $(git merge-base HEAD upstream/main)..HEAD
  • git grep -n 'panic("implement me")' -- internal/entity/models returned no matches
  • go test ./internal/entity/models was not run in this local environment because the go command is unavailable

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):

@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

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: 97661607-d7ab-47f5-8a17-c4867b78414a

📥 Commits

Reviewing files that changed from the base of the PR and between 980bb5a and 3e04689.

📒 Files selected for processing (3)
  • internal/entity/models/huaweicloud.go
  • internal/entity/models/mistral.go
  • internal/entity/models/xunfei.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/entity/models/mistral.go
  • internal/entity/models/xunfei.go
  • internal/entity/models/huaweicloud.go

📝 Walkthrough

Walkthrough

This PR replaces panic stubs with provider-aware "no such method" errors for Mistral and XunFei drivers, adds a shared test helper and table-driven tests, delegates XunFei instance creation to its constructor, and fixes HuaweiCloud's ChatWithMessages to return a parsed ChatResponse instead of panicking.

Changes

Unsupported Model Methods Refactor

Layer / File(s) Summary
Shared Unsupported Method Test Helper
internal/entity/models/model_test_helpers_test.go
New requireNoSuchMethod helper asserts errors contain "no such method".
Mistral Unsupported Methods Migration
internal/entity/models/mistral.go, internal/entity/models/mistral_test.go
Balance, Rerank, and ParseFile now return provider-aware "no such method" errors formatted with m.Name(). Added table-driven test TestMistralUnsupportedDefaultsReturnNoSuchMethod.
XunFei Unsupported Methods Migration
internal/entity/models/xunfei.go, internal/entity/models/xunfei_test.go
NewInstance delegates to NewXunFeiModel; previously panicking stubs (Embed, Rerank, TranscribeAudio*, AudioSpeech*, OCRFile, ParseFile, Balance, CheckConnection, ListTasks, ShowTask) now return fmt.Errorf("%s, no such method", x.Name()). Added table-driven test TestXunFeiUnsupportedMethodsReturnNoSuchMethod.
HuaweiCloud ChatWithMessages Implementation
internal/entity/models/huaweicloud.go
Removed unreachable panic("implement me"); ChatWithMessages now returns ChatResponse with Answer and optional trimmed ReasonContent after parsing the API response.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#14978: Both PRs modify XunFei provider unimplemented methods to return formatted “%s, no such method” errors and add tests.
  • infiniflow/ragflow#15092: Adds/standardizes the “no such method” behavior plus the shared requireNoSuchMethod test helper used by related driver tests.
  • infiniflow/ragflow#14836: Similar updates to Mistral/XunFei provider stubs and removal of panics in driver implementations.

Suggested reviewers

  • Haruko386

Poem

🐇 I hopped through code with gentle paws,
Replaced the panics with soft applause,
Mistral and XunFei now politely say,
"no such method" and send crash away,
Huawei chats return—calm as clover.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.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 accurately summarizes the main change: adding a shared default implementation for unsupported model driver methods and refactoring providers to use it.
Description check ✅ Passed The description covers the problem statement, explains the solution clearly, specifies the type of change (Refactoring), and includes validation steps; it fully matches the repository template requirements.
Linked Issues check ✅ Passed The PR fully addresses all objectives from issue #15430: adds UnsupportedModelDriver, migrates XunFei and Mistral panic stubs, removes unreachable HuaweiCloud panic, and includes focused regression tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue objectives: implementing unsupported method defaults and migrating identified panic stubs with supporting tests.

✏️ 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.

@bitloi
bitloi marked this pull request as ready for review May 29, 2026 20:59
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels May 29, 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.

🧹 Nitpick comments (3)
internal/entity/models/mistral.go (1)

613-629: ⚡ Quick win

Reuse the shared unsupported-method helper here.

These two methods still hand-format the same "provider, no such method" string that UnsupportedModelDriver already owns. That leaves the error contract duplicated in the one file this PR is trying to centralize.

♻️ Proposed cleanup
 func (m *MistralModel) Balance(apiConfig *APIConfig) (map[string]interface{}, error) {
-	return nil, fmt.Errorf("%s, no such method", m.Name())
+	return nil, m.noSuchMethod()
 }
@@
 func (m *MistralModel) Rerank(modelName *string, query string, documents []string, apiConfig *APIConfig, rerankConfig *RerankConfig) (*RerankResponse, error) {
-	return nil, fmt.Errorf("%s, no such method", m.Name())
+	return nil, m.noSuchMethod()
 }
🤖 Prompt for 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.

In `@internal/entity/models/mistral.go` around lines 613 - 629, Replace the
hand-rolled error strings in MistralModel.Balance and MistralModel.Rerank with
the shared helper so the centralized error contract is used; specifically, in
Balance(...) return UnsupportedModelDriver(m.Name()) instead of fmt.Errorf("%s,
no such method", m.Name()) and do the same in Rerank(...) (return
UnsupportedModelDriver(m.Name())), referencing the existing
UnsupportedModelDriver helper to locate the implementation.
internal/entity/models/xunfei_test.go (1)

5-67: ⚡ Quick win

Also verify the XunFei provider name is preserved in these errors.

Because this test goes through NewInstance, it is the right place to catch a lost ProviderName. At the moment it only checks for the generic substring, so that regression would still pass.

✅ Small test hardening
+import (
+	"strings"
+	"testing"
+)
-
-import "testing"
@@
 	for _, check := range checks {
 		t.Run(check.name, func(t *testing.T) {
-			requireNoSuchMethod(t, check.name, check.call())
+			err := check.call()
+			requireNoSuchMethod(t, check.name, err)
+			if !strings.Contains(err.Error(), "xunfei") {
+				t.Fatalf("%s: expected provider name in error, got %v", check.name, err)
+			}
 		})
 	}
 }
🤖 Prompt for 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.

In `@internal/entity/models/xunfei_test.go` around lines 5 - 67, The test must
assert the XunFei provider name is present in the returned errors; update the
test (or the helper requireNoSuchMethod) so after calling
NewXunFeiModel(...).NewInstance(...) and each check.call(), the returned error
message contains the provider identifier (e.g. driver.ProviderName or the
literal "xunfei") in addition to the existing "no such method" check; locate
TestXunFeiUnsupportedMethodsReturnNoSuchMethod and/or requireNoSuchMethod and
add an assertion that the error string includes the provider name to ensure
NewInstance preserves ProviderName.
internal/entity/models/mistral_test.go (1)

393-434: ⚡ Quick win

Assert the provider prefix in the new unsupported-default test.

Right now this only proves the methods fail generically. It would still pass if NewMistralModel stopped populating ProviderName, which is the migration risk introduced in this PR.

✅ Small test hardening
 	for _, check := range checks {
 		t.Run(check.name, func(t *testing.T) {
-			requireNoSuchMethod(t, check.name, check.call())
+			err := check.call()
+			requireNoSuchMethod(t, check.name, err)
+			if !strings.Contains(err.Error(), "mistral") {
+				t.Fatalf("%s: expected provider name in error, got %v", check.name, err)
+			}
 		})
 	}
🤖 Prompt for 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.

In `@internal/entity/models/mistral_test.go` around lines 393 - 434, The test
TestMistralUnsupportedDefaultsReturnNoSuchMethod should assert that the model
created by newMistralForTest still sets the provider prefix; add an assertion
that m.ProviderName has the expected prefix (e.g. starts with "mistral:") before
running the unsupported-method checks (or inside each t.Run), using the test
helper/assertion used in the file (e.g. require.True/require.HasPrefix) so the
test will fail if NewMistralModel/newMistralForTest stops populating
ProviderName.
🤖 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.

Nitpick comments:
In `@internal/entity/models/mistral_test.go`:
- Around line 393-434: The test TestMistralUnsupportedDefaultsReturnNoSuchMethod
should assert that the model created by newMistralForTest still sets the
provider prefix; add an assertion that m.ProviderName has the expected prefix
(e.g. starts with "mistral:") before running the unsupported-method checks (or
inside each t.Run), using the test helper/assertion used in the file (e.g.
require.True/require.HasPrefix) so the test will fail if
NewMistralModel/newMistralForTest stops populating ProviderName.

In `@internal/entity/models/mistral.go`:
- Around line 613-629: Replace the hand-rolled error strings in
MistralModel.Balance and MistralModel.Rerank with the shared helper so the
centralized error contract is used; specifically, in Balance(...) return
UnsupportedModelDriver(m.Name()) instead of fmt.Errorf("%s, no such method",
m.Name()) and do the same in Rerank(...) (return
UnsupportedModelDriver(m.Name())), referencing the existing
UnsupportedModelDriver helper to locate the implementation.

In `@internal/entity/models/xunfei_test.go`:
- Around line 5-67: The test must assert the XunFei provider name is present in
the returned errors; update the test (or the helper requireNoSuchMethod) so
after calling NewXunFeiModel(...).NewInstance(...) and each check.call(), the
returned error message contains the provider identifier (e.g.
driver.ProviderName or the literal "xunfei") in addition to the existing "no
such method" check; locate TestXunFeiUnsupportedMethodsReturnNoSuchMethod and/or
requireNoSuchMethod and add an assertion that the error string includes the
provider name to ensure NewInstance preserves ProviderName.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 37b149e7-45d9-43cf-a05b-077fda5e45b5

📥 Commits

Reviewing files that changed from the base of the PR and between cd18cfa and fd9df47.

📒 Files selected for processing (7)
  • internal/entity/models/huaweicloud.go
  • internal/entity/models/mistral.go
  • internal/entity/models/mistral_test.go
  • internal/entity/models/unsupported_model_driver.go
  • internal/entity/models/unsupported_model_driver_test.go
  • internal/entity/models/xunfei.go
  • internal/entity/models/xunfei_test.go
💤 Files with no reviewable changes (1)
  • internal/entity/models/huaweicloud.go

@bitloi

bitloi commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

@JinHai-CN Ready for review!

@Haruko386
Haruko386 self-requested a review June 1, 2026 01:57
@Haruko386 Haruko386 added the ci Continue Integration label Jun 1, 2026
@Haruko386
Haruko386 marked this pull request as draft June 1, 2026 01:57
@Haruko386
Haruko386 marked this pull request as ready for review June 1, 2026 01:57
@codecov

codecov Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (ae316b3) to head (3e04689).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15431   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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 @bitloi, do a small change plz

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 1, 2026
@bitloi

bitloi commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Hi @wangq8, @JinHai-CN, @KevinHuSh, @yingfeng, @xugangqiang, would you please review my PR and give me your feedback?

@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.

@bitloi would you fix the CI error?

@bitloi

bitloi commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@bitloi would you fix the CI error?

Done, its none of my PR.

@Haruko386

Copy link
Copy Markdown
Member

@bitloi would u fix the conflict?

@JinHai-CN
JinHai-CN merged commit 2eed0d4 into infiniflow:main Jun 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add safe unsupported-method defaults for Go model drivers

3 participants