Repository navigation
Go: implement provider: ModelScope - #15041
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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)
📝 WalkthroughWalkthroughAdds ModelScope provider config and factory registration, implements a new ModelScopeModel driver with non-streaming and SSE-streaming chat, model listing and connection check, unsupported-method stubs, unit tests, and marks ModelScope as self-deployed. ChangesModelScope provider
Sequence Diagram(s)sequenceDiagram
participant Client
participant ModelScopeModel
participant HTTPClient
participant ModelScopeAPI
Client->>ModelScopeModel: ChatWithMessages / ChatStreamlyWithSender
ModelScopeModel->>ModelScopeModel: normalizeModelScopeBaseURL
ModelScopeModel->>ModelScopeModel: setModelScopeAuth (if API key)
ModelScopeModel->>ModelScopeModel: buildModelScopeChatBody
ModelScopeModel->>HTTPClient: POST /v1/chat/completions (stream flag)
HTTPClient->>ModelScopeAPI: JSON request
alt Non-Streaming
ModelScopeAPI-->>HTTPClient: 200 OK with choice[0]
HTTPClient-->>ModelScopeModel: response body
ModelScopeModel->>Client: ChatResponse (Answer + ReasonContent)
else Streaming
ModelScopeAPI-->>HTTPClient: 200 OK + SSE stream
loop per data: event
HTTPClient-->>ModelScopeModel: data: JSON delta
ModelScopeModel->>Client: callback with content/reasoning delta
end
ModelScopeModel-->>Client: complete on [DONE] or finish_reason
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/entity/models/modelscope_test.go (1)
177-178: 💤 Low valueConsider checking errors for better test diagnostics.
The handler silently ignores errors from
io.ReadAllandjson.Unmarshal. While unlikely to fail in this simple test, explicitly checking and logging errors would make debugging easier if something unexpected happens.Optional improvement
- raw, _ := io.ReadAll(r.Body) - _ = json.Unmarshal(raw, &seen) + raw, err := io.ReadAll(r.Body) + if err != nil { + t.Errorf("read body: %v", err) + http.Error(w, "read error", http.StatusBadRequest) + return + } + if err := json.Unmarshal(raw, &seen); err != nil { + t.Errorf("unmarshal request: %v", err) + http.Error(w, "unmarshal error", http.StatusBadRequest) + return + }🤖 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/modelscope_test.go` around lines 177 - 178, The test currently ignores errors from io.ReadAll and json.Unmarshal which can obscure failures; update the test in modelscope_test.go to check and fail on those errors (e.g., capture err := io.ReadAll(r.Body) and if err != nil call t.Fatalf or use require.NoError) and likewise check the error returned by json.Unmarshal when decoding into seen so failures surface immediately; locate the read/unmarshal calls around io.ReadAll and json.Unmarshal and replace the ignored-error pattern with explicit error handling.
🤖 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/modelscope_test.go`:
- Around line 91-99: The test HTTP handler currently logs failures when reading
the request body or unmarshalling JSON (the io.ReadAll(r.Body) and
json.Unmarshal(raw, &seen) paths using raw, err, seen and t.Errorf) but returns
without writing an HTTP response; update the handler so after calling t.Errorf
you also write an appropriate HTTP error response (e.g., call w.WriteHeader with
a 400/500 status and write a short error message) for both the read and
unmarshal error branches so the client won't hang and tests get a proper HTTP
failure response.
---
Nitpick comments:
In `@internal/entity/models/modelscope_test.go`:
- Around line 177-178: The test currently ignores errors from io.ReadAll and
json.Unmarshal which can obscure failures; update the test in modelscope_test.go
to check and fail on those errors (e.g., capture err := io.ReadAll(r.Body) and
if err != nil call t.Fatalf or use require.NoError) and likewise check the error
returned by json.Unmarshal when decoding into seen so failures surface
immediately; locate the read/unmarshal calls around io.ReadAll and
json.Unmarshal and replace the ignored-error pattern with explicit error
handling.
🪄 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: a1133c44-2bf5-40fa-98ee-819cb87bc4b0
📒 Files selected for processing (5)
conf/models/modelscope.jsoninternal/entity/models/factory.gointernal/entity/models/modelscope.gointernal/entity/models/modelscope_test.gointernal/service/llm.go
Closes infiniflow#15040. ModelScope was listed unchecked in the Go-rewrite tracker infiniflow#14736 and already had an llm_factories.json entry (tags: LLM) but no Go driver, so the new Go API server could not route ModelScope instances. The Python side has supported it through the OpenAI-compatible base at rag/llm/chat_model.py:618 (ModelScopeChat), which requires a user-supplied base URL and appends /v1. This adds: - internal/entity/models/modelscope.go: self-hosted OpenAI-compatible driver with chat (sync + SSE stream with idle-timeout cancellation), list_models, and check_connection. Auth header is optional, matching the xinference pattern, so deployments without auth and auth-enabled deployments both work. Base URL is normalized so users can configure either the root endpoint or the /v1 endpoint. - internal/entity/models/modelscope_test.go: 12 tests covering name, URL normalization, factory routing, chat happy path / auth header / reasoning_content extraction, stream happy path / stream=false rejection / idle cancellation, list_models + check_connection, missing-base-URL clear error, and the no-such-method sentinels. - conf/models/modelscope.json: shipped config (class: "local", url_suffix v1/chat/completions and v1/models). - internal/entity/models/factory.go: case "modelscope" → ModelScopeModel. - internal/service/llm.go: ModelScope added to the selfDeployed map alongside Ollama, Xinference, LocalAI, LM-Studio, GPUStack — the Python side requires user-supplied URL with no default, so the Go side classifies it the same way. Follow-on issues will add Embed and Rerank, in line with how Novita, NVIDIA, TogetherAI, and other providers landed method-by-method.
895febe to
fbc52f7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15041 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Closes #15040.
ModelScope was listed unchecked in the Go-rewrite tracker #14736 and already had an llm_factories.json entry (tags: LLM) but no Go driver, so the new Go API server could not route ModelScope instances. The Python side has supported it through the OpenAI-compatible base at rag/llm/chat_model.py:618 (ModelScopeChat), which requires a user-supplied base URL and appends /v1.
This adds:
Follow-on issues will add Embed and Rerank, in line with how Novita, NVIDIA, TogetherAI, and other providers landed method-by-method.