Repository navigation
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 (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis 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. ChangesUnsupported Model Methods Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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. 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.
🧹 Nitpick comments (3)
internal/entity/models/mistral.go (1)
613-629: ⚡ Quick winReuse the shared unsupported-method helper here.
These two methods still hand-format the same
"provider, no such method"string thatUnsupportedModelDriveralready 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 winAlso verify the XunFei provider name is preserved in these errors.
Because this test goes through
NewInstance, it is the right place to catch a lostProviderName. 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 winAssert the provider prefix in the new unsupported-default test.
Right now this only proves the methods fail generically. It would still pass if
NewMistralModelstopped populatingProviderName, 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
📒 Files selected for processing (7)
internal/entity/models/huaweicloud.gointernal/entity/models/mistral.gointernal/entity/models/mistral_test.gointernal/entity/models/unsupported_model_driver.gointernal/entity/models/unsupported_model_driver_test.gointernal/entity/models/xunfei.gointernal/entity/models/xunfei_test.go
💤 Files with no reviewable changes (1)
- internal/entity/models/huaweicloud.go
|
@JinHai-CN Ready for review! |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Hi @wangq8, @JinHai-CN, @KevinHuSh, @yingfeng, @xugangqiang, would you please review my PR and give me your feedback? |
Done, its none of my PR. |
|
@bitloi would u fix the conflict? |
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
ModelDriverinterface requires providers to implement many capability methods even when the provider does not support them. XunFei had unsupported capability methods implemented aspanic("implement me"), Mistral still had a panic inParseFile, and HuaweiCloud carried an unreachablepanic("implement me")after a normal chat return.This PR:
UnsupportedModelDriverfor unsupported non-chat capability methods.Name,NewInstance, chat, stream chat, and model listing explicit.Balance/Rerankerror formatting.ChatWithMessages.Closes #15430
Validation:
git diff --check $(git merge-base HEAD upstream/main)..HEADgit grep -n 'panic("implement me")' -- internal/entity/modelsreturned no matchesgo test ./internal/entity/modelswas not run in this local environment because thegocommand is unavailableType of change