Skip to content

Go: implement ListModels in Volcengine driver - #14702

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Crystora:feat/go-aliyun-balance
May 11, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
Crystora:feat/go-aliyun-balance

Conversation

@Crystora

@Crystora Crystora commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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 #14701

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels May 8, 2026
@coderabbitai

coderabbitai Bot commented May 8, 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: d10457ad-4250-4960-88fc-1c453f2461ad

📥 Commits

Reviewing files that changed from the base of the PR and between 4bac47c and 22f1038.

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

📝 Walkthrough

Walkthrough

This pull request implements the ListModels method for the VolcEngine model provider. It adds the models endpoint to configuration and replaces the stub with an HTTP-backed retrieval that resolves regional URLs, handles optional authentication, parses the JSON response, and returns flattened model identifiers.

Changes

VolcEngine ListModels Feature

Layer / File(s) Summary
Configuration — Models Endpoint
conf/models/volcengine.json
Adds models URL suffix entry to VolcEngine endpoint configuration.
ListModels Method Implementation
internal/entity/models/volcengine.go
Replaces stub with full implementation: resolves region-based base URL with default fallback, validates configuration, issues optional-auth GET to the models endpoint, unmarshals response into DSModelList, and returns flattened model identifiers with optional @OwnedBy suffix.

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

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#14636: Implements provider-specific ListModels with regional base-URL fallback (NVIDIA); similar pattern and error handling.
  • infiniflow/ragflow#14614: Hardened ListModels implementations across drivers (base-URL selection, auth, error propagation), related changeset style.

Suggested reviewers

  • Haruko386

Poem

🐰 In Ark's bright region I hop and see,
Models listed tidy for you and me.
Tokens donned, JSON parsed with care,
IDs return — some with owner flair.
A tiny hop, a big API tree!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: implementing the ListModels method in the VolcEngine Go driver.
Description check ✅ Passed The description comprehensively covers the problem, solution, implementation details, testing, and type of change, fully adhering to the repository template.
Linked Issues check ✅ Passed The PR implementation fully addresses all coding objectives from issue #14701: adds 'models' url_suffix to volcengine.json, implements ListModels with region resolution, proper error handling, and returns model ids in the expected format.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the objectives in issue #14701; no out-of-scope modifications detected. Configuration and implementation changes are limited to the two files required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

637-649: ⚡ Quick win

API-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":{}}. The Code and Message fields are decoded but never inspected: when Data is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e96c5c and 51f8d2e.

📒 Files selected for processing (2)
  • conf/models/aliyun.json
  • internal/entity/models/aliyun.go

@wdeveloper16

wdeveloper16 commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Did you check this endpoint? https://dashscope.aliyuncs.com/api/v1/recharge/recharge-balance/query

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 Authorization: Bearer <api_key> used for model API calls.
There does not appear to be a documented, public balance endpoint accessible via a DashScope model API key alone.

@Crystora
Crystora force-pushed the feat/go-aliyun-balance branch from 51f8d2e to 4bac47c Compare May 8, 2026 19:37
@Crystora Crystora changed the title Go: implement Balance in Aliyun driver Go: implement ListModels in Volcengine driver May 8, 2026

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

@bittoby LGTM, thank you for your contribution

@Crystora

Crystora commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

@bittoby LGTM, thank you for your contribution

Thanks. Could you merge this PR?

@JinHai-CN JinHai-CN added the ci Continue Integration label May 9, 2026
@codecov

codecov Bot commented May 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (330257b) to head (22f1038).
⚠️ Report is 2 commits behind head on main.

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

@Crystora

Copy link
Copy Markdown
Contributor Author

@JinHai-CN Any further updates needed for this PR? If everything looks good, plz merge this. Thanks

@JinHai-CN
JinHai-CN merged commit 39a1773 into infiniflow:main May 11, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
1 task done
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 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]: Implement ListModels in the VolcEngine Go driver

4 participants