Repository navigation
Go: implement ListModels in Volcengine driver - #14702
Conversation
|
ℹ️ 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)
📝 WalkthroughWalkthroughThis pull request implements the ChangesVolcEngine ListModels Feature
Sequence Diagram(s)sequenceDiagram
participant Client
participant VolcEngine
participant APIConfig
participant VolcAPI
participant Parser
Client->>VolcEngine: ListModels(apiConfig)
VolcEngine->>APIConfig: resolve base URL (region or default)
APIConfig-->>VolcEngine: baseURL
VolcEngine->>VolcAPI: GET {baseURL}/{url_suffix.models} (Authorization: Bearer token if present)
VolcAPI-->>VolcEngine: HTTP response (JSON)
VolcEngine->>Parser: unmarshal to DSModelList
Parser-->>VolcEngine: model entries
VolcEngine-->>Client: []string (id or id@owned_by)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 (1)
internal/entity/models/aliyun.go (1)
637-649: ⚡ Quick winAPI-level error code (
parsed.Code) is never checked after HTTP 200.DashScope can return HTTP 200 with an error payload such as
{"code":"InvalidApiKey","message":"...","data":{}}. TheCodeandMessagefields are decoded but never inspected: whenDatais empty, the caller receives the opaque"no balance info in response"error instead of the descriptive API message.♻️ Proposed fix — propagate API-level errors
var parsed aliyunBalanceResponse if err = json.Unmarshal(body, &parsed); err != nil { return nil, fmt.Errorf("failed to parse response: %w", err) } +if parsed.Code != "" && parsed.Code != "Success" { + return nil, fmt.Errorf("Aliyun balance API error: code=%s, message=%s", parsed.Code, parsed.Message) +} + candidates := []string{🤖 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/aliyun.go` around lines 637 - 649, The parsing of aliyunBalanceResponse currently ignores API-level errors: after decoding into aliyunBalanceResponse (check parsed/parsedResp/variable named parsed), inspect parsed.Code and if it is non-empty and not a success sentinel return an error combining parsed.Code and parsed.Message; if Data is empty or missing return that API error instead of the generic "no balance info in response". Update wherever the HTTP 200 handling occurs (the function that decodes into aliyunBalanceResponse) to check parsed.Code before using parsed.Data and propagate a clear error containing parsed.Code and parsed.Message.
🤖 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/aliyun.go`:
- Around line 637-649: The parsing of aliyunBalanceResponse currently ignores
API-level errors: after decoding into aliyunBalanceResponse (check
parsed/parsedResp/variable named parsed), inspect parsed.Code and if it is
non-empty and not a success sentinel return an error combining parsed.Code and
parsed.Message; if Data is empty or missing return that API error instead of the
generic "no balance info in response". Update wherever the HTTP 200 handling
occurs (the function that decodes into aliyunBalanceResponse) to check
parsed.Code before using parsed.Data and propagate a clear error containing
parsed.Code and parsed.Message.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e8dc6fad-37ec-4cb8-9d6e-3d541c60ad32
📒 Files selected for processing (2)
conf/models/aliyun.jsoninternal/entity/models/aliyun.go
|
Did you check this endpoint? DashScope's account balance and billing information is managed through the Alibaba Cloud financial platform, which uses a different authentication mechanism (AccessKeyId + HMAC-SHA256 signing) from the standard |
51f8d2e to
4bac47c
Compare
Haruko386
left a comment
There was a problem hiding this comment.
@bittoby LGTM, thank you for your contribution
Thanks. Could you merge this PR? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14702 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@JinHai-CN Any further updates needed for this PR? If everything looks good, plz merge this. Thanks |
### What problem does this PR solve? The VolcEngine Go driver in `internal/entity/models/volcengine.go` shipped with a `ListModels` stub that returned `volcengine, no such method`. `conf/models/volcengine.json` also did not declare a `models` URL suffix, so the model picker had nothing to call even if the method body were filled in. A tenant who configured Volcengine (Doubao / Ark) as a provider could not see the list of available endpoints from the RAGFlow UI. Several other Go drivers already implement `ListModels` against the OpenAI-compatible `/models` endpoint (deepseek, gitee, nvidia, openai, siliconflow), so the interface and pattern are well-established. This PR fills the gap. ### What this PR includes * `conf/models/volcengine.json`: declare the `models` URL suffix alongside the existing `chat`, `files`, and `embedding` entries. The Ark v3 API exposes `https://ark.cn-beijing.volces.com/api/v3/models`, so the suffix is just `models`. * `internal/entity/models/volcengine.go`: replace the `ListModels` stub with a real implementation. Reuses the package-level `DSModelList` / `DSModel` types that DeepSeek, Gitee, and SiliconFlow already use to parse the OpenAI-compatible models response shape. No factory change. No interface change. ### How the driver works * Resolves the region with a default fallback, the same way the other VolcEngine methods in this driver already do. * Builds the URL from `BaseURL[region] + URLSuffix.Models`, with `strings.TrimSuffix` on the base to keep the join robust. * Issues a `GET` with optional `Authorization: Bearer <api_key>` (the header is omitted when no key is configured, mirroring the existing NVIDIA `ListModels`). * Reads the response body once, surfaces a non-200 with the upstream status line plus body, and parses the JSON via the shared `DSModelList` type. * Returns the model id list in input order. When the response includes an `owned_by` field, the entry is rendered as `id@owned_by`, matching the convention used by the other Go drivers. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? * `go build ./internal/entity/models/...` returns exit 0. * `go vet ./internal/entity/models/...` is clean. * `gofmt -l internal/entity/models/volcengine.go` is clean. * The full method set on `VolcEngine` still matches the `ModelDriver` interface. * Endpoint reachability check: `GET https://ark.cn-beijing.volces.com/api/v3/models` returns `401 Unauthorized` without an API key, confirming the path exists and accepts Bearer authentication. * Pattern parity with DeepSeek, Gitee, NVIDIA, and SiliconFlow `ListModels`. Fixes infiniflow#14701 Co-authored-by: Jin Hai <[email protected]>
What problem does this PR solve?
The VolcEngine Go driver in
internal/entity/models/volcengine.goshipped with aListModelsstub that returnedvolcengine, no such method.conf/models/volcengine.jsonalso did not declare a
modelsURL suffix, so the model picker had nothing to call evenif the method body were filled in.
A tenant who configured Volcengine (Doubao / Ark) as a provider could not see the list of
available endpoints from the RAGFlow UI. Several other Go drivers already implement
ListModelsagainst the OpenAI-compatible/modelsendpoint (deepseek, gitee, nvidia,openai, siliconflow), so the interface and pattern are well-established.
This PR fills the gap.
What this PR includes
conf/models/volcengine.json: declare themodelsURL suffix alongside the existingchat,files, andembeddingentries. The Ark v3 API exposeshttps://ark.cn-beijing.volces.com/api/v3/models, so the suffix is justmodels.internal/entity/models/volcengine.go: replace theListModelsstub with a realimplementation. Reuses the package-level
DSModelList/DSModeltypes thatDeepSeek, Gitee, and SiliconFlow already use to parse the OpenAI-compatible models
response shape.
No factory change. No interface change.
How the driver works
in this driver already do.
BaseURL[region] + URLSuffix.Models, withstrings.TrimSuffixonthe base to keep the join robust.
GETwith optionalAuthorization: Bearer <api_key>(the header is omittedwhen no key is configured, mirroring the existing NVIDIA
ListModels).body, and parses the JSON via the shared
DSModelListtype.owned_byfield, the entry is rendered as
id@owned_by, matching the convention used by theother Go drivers.
Type of change
How was this tested?
go build ./internal/entity/models/...returns exit 0.go vet ./internal/entity/models/...is clean.gofmt -l internal/entity/models/volcengine.gois clean.VolcEnginestill matches theModelDriverinterface.GET https://ark.cn-beijing.volces.com/api/v3/modelsreturns
401 Unauthorizedwithout an API key, confirming the path exists and acceptsBearer authentication.
ListModels.Fixes #14701