Skip to content

feat(go): implement provider Astraflow (#15062) - #15064

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
dripsmvcp:fix/15062-go-astraflow-driver
May 21, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
dripsmvcp:fix/15062-go-astraflow-driver

Conversation

@dripsmvcp

Copy link
Copy Markdown
Contributor
  • Adds an Astraflow Go driver so the new API server can route Astraflow (UCloud ModelVerse) chat instances, matching the existing Python AstraflowChat (rag/llm/chat_model.py:1237). Follows the same SaaS-driver shape used for Avian, Novita, TogetherAI, Replicate, DeepInfra, Upstage, and LongCat.

Root Cause

conf/llm_factories.json:6234 already registers the Astraflow factory with 18 chat models and the default base URL https://api-us-ca.umodelverse.ai/v1, but internal/entity/models/ had no astraflow.go driver and conf/models/ had no astraflow.json, so the Go API server fell back to the dummy driver for Astraflow instances.

Fix

  • internal/entity/models/astraflow.go — OpenAI-compatible driver implementing ChatWithMessages, ChatStreamlyWithSender, ListModels, and CheckConnection (delegates to ListModels). Forwards documented fields only (model, messages, stream, max_tokens, temperature, top_p, stop). Reasoning models surface reasoning_content separately from content. SSE handling rejects malformed frames, surfaces upstream {"error": …} frames, and requires a [DONE]/finish_reason terminator.
  • conf/models/astraflow.json — base URL https://api-us-ca.umodelverse.ai/v1 + the 18 chat models from the factory entry (claude-opus-4-7/4-6, claude-sonnet-4-5, claude-haiku-4-5, gpt-5.4/-mini/-nano, gpt-4o-mini, Qwen3-Max/-Coder/-32B/-VL, kimi-k2.6, glm-5.1, MiniMax-M2.7/M2, gemini-2.5-pro/-flash).
  • internal/entity/models/factory.go — registers the astraflow case.
  • internal/entity/models/astraflow_test.go — 21 hermetic tests using httptest.Server (no network).

Follow-on issues will add Embed (factory tags include TEXT EMBEDDING) and the China-region sibling Astraflow-CN (Python chat_model.py:1246, base https://api.modelverse.cn/v1), in line with how Novita / NVIDIA / TogetherAI landed method-by-method.

Test Plan

  • Regression tests added: internal/entity/models/astraflow_test.go
  • All tests pass: go test ./internal/entity/models/ -run Astraflow -count=1 -vet=off
  • Output:

Closes #15062

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label May 20, 2026
@coderabbitai

coderabbitai Bot commented May 20, 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: 4bea8e8b-0d7d-4b69-a796-0b85e11d04ca

📥 Commits

Reviewing files that changed from the base of the PR and between 4899e11 and db8394d.

📒 Files selected for processing (1)
  • internal/entity/models/factory.go

📝 Walkthrough

Walkthrough

Adds an Astraflow provider: configuration, Go driver (sync + SSE streaming chat), ListModels/CheckConnection, factory wiring, unsupported-method stubs, and comprehensive tests validating sync and streaming behavior.

Changes

Astraflow Provider Implementation

Layer / File(s) Summary
Configuration and type foundation
conf/models/astraflow.json, internal/entity/models/astraflow.go
JSON config defines base URLs, endpoint suffixes, and chat models; Go type, constructor, and region-aware base URL resolver initialize the driver and HTTP client tuned for streaming.
Test helpers and initialization
internal/entity/models/astraflow_test.go (helpers, name/factory tests)
Adds HTTP and SSE test servers; tests verify driver Name and factory construction.
Chat request and streaming implementation
internal/entity/models/astraflow.go (ChatWithMessages, ChatStreamlyWithSender)
Non-streaming chat posts to /v1/chat/completions and maps message.content → Answer and message.reasoning_content → ReasonContent; streaming posts with stream: true, parses SSE data: frames, dispatches reasoning/content deltas via sender, handles upstream errors and terminal signals.
Chat API tests (streaming & non-streaming)
internal/entity/models/astraflow_test.go (chat tests)
Tests validate request/response mapping, reasoning extraction, input guards, SSE assembly, reasoning vs content splitting, malformed frame handling, incomplete stream detection, and upstream error propagation.
Model discovery and connection validation
internal/entity/models/astraflow.go, internal/entity/models/astraflow_test.go
ListModels GETs /v1/models and returns model IDs; CheckConnection delegates to ListModels; tests cover missing API key, upstream 401, and unknown-region base URL error.
Stub methods and factory registration
internal/entity/models/astraflow.go, internal/entity/models/factory.go, internal/entity/models/astraflow_test.go
Factory registers astraflow; non-chat APIs implemented as stubs returning consistent “no such method” errors; tests assert those errors for embeddings, audio, and OCR APIs.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AstraflowModel
  participant AstraflowAPI
  Client->>AstraflowModel: ChatWithMessages(...)
  AstraflowModel->>AstraflowAPI: POST /v1/chat/completions (JSON)
  AstraflowAPI-->>AstraflowModel: JSON reply (choices[0].message)
  AstraflowModel-->>Client: ChatResponse{Answer, ReasonContent}

  Client->>AstraflowModel: ChatStreamlyWithSender(..., sender)
  AstraflowModel->>AstraflowAPI: POST /v1/chat/completions (stream=true)
  AstraflowAPI-->>AstraflowModel: SSE stream (data: events)
  loop per SSE event
    AstraflowModel->>Client: sender(reasoningDelta?, contentDelta?)
  end
  AstraflowAPI-->>AstraflowModel: [DONE]
  AstraflowModel->>Client: sender("[DONE]")
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

  • infiniflow/ragflow#14813: Similar factory dispatch change registering a new provider constructor.
  • infiniflow/ragflow#15024: Adds an OpenAI-compatible chat provider with SSE streaming and reasoning/content delta handling, sharing implementation patterns.
  • infiniflow/ragflow#14957: Adds an OpenAI-compatible chat driver with SSE streaming and reasoning/content delta handling.

Suggested labels

💞 feature, size:XXL

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped into the code today,
streams of words in bright array.
Reason then text in tidy streams,
tests to match the dev's bright dreams.
Hooray — Astraflow joined the play!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.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 PR title clearly and specifically identifies the main change: implementing the Astraflow provider in the Go driver.
Description check ✅ Passed The PR description comprehensively covers the problem, root cause, fix details, test plan, and includes the required type of change (New Feature).
Linked Issues check ✅ Passed The PR fully implements all requirements from #15062: Astraflow Go driver with ChatWithMessages, ChatStreamlyWithSender, ListModels, CheckConnection, configuration file with 18 models and default base URL, factory registration, and 21 comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are directly related to the Astraflow provider implementation. No out-of-scope modifications detected.

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

Actionable comments posted: 1

🤖 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/astraflow.go`:
- Around line 333-360: When processing SSE choice chunks, the code currently
ignores a terminal event if firstChoice contains "finish_reason" but no "delta";
update the logic in the chunk-processing loop that handles firstChoice/delta
(references: firstChoice, delta, sender, sawTerminal) to check for a
"finish_reason" on firstChoice even when delta is nil or not a map, set
sawTerminal = true and break out of the loop (honoring the terminal event)
before returning the "stream ended" error; ensure existing sender calls for
reasoning_content/content only run when delta is present and valid.
🪄 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: 00097e0a-6ab1-4478-af33-c580ae15486d

📥 Commits

Reviewing files that changed from the base of the PR and between dc01e0e and c7d3441.

📒 Files selected for processing (4)
  • conf/models/astraflow.json
  • internal/entity/models/astraflow.go
  • internal/entity/models/astraflow_test.go
  • internal/entity/models/factory.go

Comment thread internal/entity/models/astraflow.go Resolved
… review)

Astraflow can emit a terminal stream frame that carries finish_reason
without a delta object. The previous loop bailed early when delta was
absent, so the terminator was never observed and the method returned
'stream ended before [DONE] or finish_reason'. Guard the delta block
so finish_reason is honored independently.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels May 20, 2026
@Haruko386

Copy link
Copy Markdown
Member

Hi @dripsmvcp, before I review your code, as far as I know, AstraFlow use dynamic API-KEY, would you please tell me how you handle it.

@dripsmvcp

Copy link
Copy Markdown
Contributor Author

Hey @Haruko386, thanks for jumping on this!

Quick question back at you — what do you mean by "dynamic API-KEY"? I matched what the Python side already does in AstraflowChat (rag/llm/chat_model.py:1237): it just takes whatever key the user pastes into Add-Provider and sends it as Authorization: Bearer on every call, same as any OpenAI-compatible provider. No token refresh, no exchange step. So the Go driver does the exact same thing.

But if Astraflow actually expects something fancier — like a short-lived token you have to mint from a client_id/secret, or a key that rotates and needs refreshing — that's news to me, and the Python driver wouldn't be handling it either. Got a doc link or an existing driver I can crib from? Happy to wire it up properly here (and probably patch the Python side too in a follow-up) rather than guess at the shape.

@Haruko386

Copy link
Copy Markdown
Member

@dripsmvcp According to this Docs, AstraFlow need a public Key and a private key to generate API-KEY. Have you test it?
At least I cannot get a response from astraflow by using the public key or private key alone. If I've misunderstood anything, please let me know.

@dripsmvcp

Copy link
Copy Markdown
Contributor Author

Just ran it against a live key, @Haruko386 — bearer-token auth works as-is, no public/private signing involved.

GET https://api-us-ca.umodelverse.ai/v1/models
Authorization: Bearer
→ HTTP/1.1 200 OK
{"data":[{"id":"claude-opus-4-7",...}, ...155 models...],"object":"list"}

POST https://api-us-ca.umodelverse.ai/v1/chat/completions
Authorization: Bearer
Content-Type: application/json
{"model":"claude-haiku-4-5-20251001","messages":[{"role":"user","content":"ping"}],"max_tokens":32}
→ HTTP/1.1 200 OK
X-Modelverse-Request-Id: 42e0cf35-b86a-464b-aaa1-7d3430853270
{"choices":[{"finish_reason":"stop","index":0,
"message":{"role":"assistant","content":"Pong! 👋 ..."}}],
"model":"claude-haiku-4-5-20251001","object":"chat.completion",...}
I think the confusion is that there are two separate consoles on the UCloud account:

UAPI (console.ucloud.cn/uapi/apikey) — issues a PublicKey + PrivateKey pair used to SHA1-sign requests against api.ucloud.cn (compute/storage/networking control plane). These are not inputs to a ModelVerse key — there's no derivation step, which is why using either one alone got you no response.
ModelVerse (console.ucloud.cn → ModelVerse / 模型服务 panel → API Keys) — issues a single OpenAI-style bearer string. That's the one Add-Provider expects, and the one the Python AstraflowChat at rag/llm/chat_model.py:1237 already uses.
If you want me to make this less easy to trip over, I can add a one-line description to conf/llm_factories.json's RAGcon/Astraflow entry pointing users at the ModelVerse panel specifically — happy to push that in this PR if useful.

@Haruko386

Copy link
Copy Markdown
Member

wow, thank you :) @dripsmvcp
I just find it here.
I will review you code soon

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

@dripsmvcp thank you for your contribution
LGTM

@Haruko386 Haruko386 added the ci Continue Integration label May 21, 2026
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (fec0b96) to head (db8394d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15064   +/-   ##
=======================================
  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.
📢 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.

@JinHai-CN
JinHai-CN merged commit bcef1fa into infiniflow:main May 21, 2026
1 check passed
JinHai-CN added a commit that referenced this pull request May 21, 2026
- Adds an `Astraflow` Go driver so the new API server can route
Astraflow (UCloud ModelVerse) chat instances, matching the existing
Python `AstraflowChat` (`rag/llm/chat_model.py:1237`). Follows the same
SaaS-driver shape used for Avian, Novita, TogetherAI, Replicate,
DeepInfra, Upstage, and LongCat.

Closes #15062

---------

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 size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement provider: Astraflow in Go driver

3 participants