Repository navigation
Go: implement provider: StepFun - #14815
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 due to trivial changes (1)
📝 WalkthroughWalkthroughAdds StepFun provider config, registers "stepfun" in the model factory, and implements StepFunModel with sync chat, SSE streaming chat, model listing, and connection verification; embeds/rerank/balance are stubbed. ChangesStepFun Model Provider Integration
Sequence DiagramsequenceDiagram
participant Client
participant StepFun as StepFunModel
participant API as StepFun API
Client->>StepFun: ChatWithMessages(modelName, messages, config)
StepFun->>StepFun: Validate API key
StepFun->>StepFun: Select region URL
StepFun->>API: POST /v1/chat/completions
API-->>StepFun: 200 OK with choices
StepFun->>Client: ChatResponse
Client->>StepFun: ChatStreamlyWithSender(modelName, messages, sender)
StepFun->>StepFun: Validate and set stream true
StepFun->>API: POST /v1/chat/completions
API-->>StepFun: 200 OK SSE stream
loop Each event
API-->>StepFun: data: {"delta": {"content": "..."}}
StepFun->>Client: forward via sender
end
API-->>StepFun: data: [DONE]
StepFun->>Client: send DONE sentinel
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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.
Actionable comments posted: 2
🤖 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/stepfun.go`:
- Around line 101-104: The code currently treats an empty string as an explicit
region which breaks lookups; update the region selection in both
ChatWithMessages and ListModels to use "default" when apiConfig.Region is nil or
when the pointer references an empty string (i.e., set region := "default"; if
apiConfig.Region != nil && *apiConfig.Region != "" { region = *apiConfig.Region
}), and apply the identical change in the other occurrence to ensure
empty-string regions fall back to "default".
- Line 210: The ChatStreamlyWithSender method currently calls the sender
callback unconditionally; add a defensive nil check at the start of
ChatStreamlyWithSender (alongside the existing checks for messages and
apiConfig) and return an error if sender == nil to avoid a runtime panic when
sender is invoked later in the function; reference the ChatStreamlyWithSender
function and ensure the guard uses the same error-reporting style/pattern as the
other parameter checks in this file.
🪄 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: c3d20466-1e23-4024-82b0-45170c26490c
📒 Files selected for processing (3)
conf/models/stepfun.jsoninternal/entity/models/factory.gointernal/entity/models/stepfun.go
CodeRabbit review on infiniflow#14815 flagged two issues: - ChatWithMessages and ListModels treated a non-nil but empty Region pointer as an explicit region, which then failed baseURLForRegion lookup despite a valid "default" entry. Match the guard already used in ChatStreamlyWithSender: only override "default" when the region string is non-empty. - ChatStreamlyWithSender did not validate that sender was non-nil before invoking it inside the scan loop, which would panic on a nil callback. Add the guard alongside the existing messages and api-key checks.
CodeRabbit review on this PR flagged two issues that match the ones also addressed in the Mistral driver (infiniflow#14805) and StepFun (infiniflow#14815). - ChatWithMessages and ListModels treated a non-nil but empty Region pointer as an explicit region, which then failed baseURLForRegion lookup despite a valid "default" entry. Match the guard already used in ChatStreamlyWithSender: only override "default" when the region string is non-empty. - ChatStreamlyWithSender did not validate that sender was non-nil before invoking it inside the scan loop, which would panic on a nil callback. Add the guard alongside the existing messages and api-key checks.
CodeRabbit caught that conf/models/stepfun.json shipped with https://api.stepfun.com/v1, which resolves to StepFun's domestic deployment behind the VolcEngine WAF (Chinese ByteDance infra). The canonical international endpoint is https://api.stepfun.ai/v1, which resolves to the Aliyun international ALB in us-east-1. Both backends serve the same OpenAI-compatible surface, but keys issued by the .ai side are rejected by the .com side with the same generic "Incorrect API key provided" error, which masks the mismatch. Confirmed live: the same test API key returns HTTP 401 against api.stepfun.com/v1/models and HTTP 200 with the account's real model list against api.stepfun.ai/v1/models. Chat completion then returns 402 quota_exceeded against .ai, which proves the auth path works end to end and the only remaining gate is account credit. Also add step-3.5-flash and step-3.5-flash-paid to the model list. Those are the current flagship chat models on the .ai deployment (visible in /v1/models for accounts that exist today), so a tenant who opens the model picker after this lands sees a working pick by default. Keep the step-1 and step-1v entries for accounts that still have access to the older lineup.
Live integration test against
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14815 +/- ##
==========================================
- Coverage 95.59% 94.16% -1.43%
==========================================
Files 10 10
Lines 703 703
Branches 112 112
==========================================
- Hits 672 662 -10
- Misses 21 25 +4
- Partials 10 16 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The That test waits for the document-parsing pipeline (OCR + chunker) to finish within a fixed timeout. When the CI runner is under load the parser overruns the wait window and the test fails with the generic "Document parsing timeout" assertion. Nothing in this PR touches:
The 741 passed / 1 failed / 37 skipped split is consistent with a one-off timeout, not a regression. Could a maintainer re-run the failed job? I tried |
Haruko386
left a comment
There was a problem hiding this comment.
Hi @tmimmanuel LGTM
Thank you for your contribution.
LongCat (Meituan, https://longcat.chat) is one of the unchecked providers on the umbrella tracking issue infiniflow#14736. Its API is OpenAI-compatible at https://api.longcat.chat/openai/v1 with three public chat models: LongCat-Flash-Chat, LongCat-Flash-Lite, and LongCat-Flash-Thinking (a reasoning model). What this PR includes: - internal/entity/models/longcat.go: full driver implementing the ModelDriver interface - conf/models/longcat.json: base URL + url_suffix + the 3 public models - factory.go: route "longcat" provider name to NewLongCatModel - internal/entity/models/longcat_test.go: 21 unit tests Methods: - ChatWithMessages non-stream chat - ChatStreamlyWithSender SSE streaming chat - ListModels / CheckConnection - reasoning_content extraction on both stream and non-stream paths (LongCat-Flash-Thinking returns the chain-of-thought in message.reasoning_content / delta.reasoning_content, OpenAI o-series shape; live-probed before writing tests) - reasoning_effort propagation from ChatConfig.Effort - Embed / Rerank / Balance / TranscribeAudio / AudioSpeech / OCRFile return the "no such method" sentinel (LongCat does not expose any of these surfaces) Pattern parity with the merged Mistral (infiniflow#14807), Upstage (infiniflow#14819), and StepFun (infiniflow#14815) drivers. No interface change. Verified live against api.longcat.chat: - ListModels: 5 ids (Flash-Lite, Flash-Chat, Flash-Thinking-2601, Flash-Omni-2603, 2.0-Preview) - Chat (Flash-Chat) non-stream: "Got it! Let me know if you..." - Chat (Flash-Thinking) non-stream: 443-char answer + 557-char reasoning trace extracted into ChatResponse.ReasonContent - Stream (Flash-Thinking): 78 content chunks (351 chars) + 107 reasoning chunks (537 chars) — the delta.reasoning_content extraction works end to end against real wire data - Sentinels all return "no such method" 21 unit tests pass on go 1.25; build clean. Note on PR history: this branch was previously named for LocalAI work which has since been consolidated into PR infiniflow#14813. The branch was reset to upstream/main and rebuilt for LongCat — diff is a clean +1052 lines on top of current main.
CodeRabbit review on infiniflow#14815 flagged two issues: - ChatWithMessages and ListModels treated a non-nil but empty Region pointer as an explicit region, which then failed baseURLForRegion lookup despite a valid "default" entry. Match the guard already used in ChatStreamlyWithSender: only override "default" when the region string is non-empty. - ChatStreamlyWithSender did not validate that sender was non-nil before invoking it inside the scan loop, which would panic on a nil callback. Add the guard alongside the existing messages and api-key checks.
LongCat (Meituan, https://longcat.chat) is one of the unchecked providers on the umbrella tracking issue infiniflow#14736. Its API is OpenAI-compatible at https://api.longcat.chat/openai/v1 with three public chat models: LongCat-Flash-Chat, LongCat-Flash-Lite, and LongCat-Flash-Thinking (a reasoning model). What this PR includes: - internal/entity/models/longcat.go: full driver implementing the ModelDriver interface - conf/models/longcat.json: base URL + url_suffix + the 3 public models - factory.go: route "longcat" provider name to NewLongCatModel - internal/entity/models/longcat_test.go: 21 unit tests Methods: - ChatWithMessages non-stream chat - ChatStreamlyWithSender SSE streaming chat - ListModels / CheckConnection - reasoning_content extraction on both stream and non-stream paths (LongCat-Flash-Thinking returns the chain-of-thought in message.reasoning_content / delta.reasoning_content, OpenAI o-series shape; live-probed before writing tests) - reasoning_effort propagation from ChatConfig.Effort - Embed / Rerank / Balance / TranscribeAudio / AudioSpeech / OCRFile return the "no such method" sentinel (LongCat does not expose any of these surfaces) Pattern parity with the merged Mistral (infiniflow#14807), Upstage (infiniflow#14819), and StepFun (infiniflow#14815) drivers. No interface change. Verified live against api.longcat.chat: - ListModels: 5 ids (Flash-Lite, Flash-Chat, Flash-Thinking-2601, Flash-Omni-2603, 2.0-Preview) - Chat (Flash-Chat) non-stream: "Got it! Let me know if you..." - Chat (Flash-Thinking) non-stream: 443-char answer + 557-char reasoning trace extracted into ChatResponse.ReasonContent - Stream (Flash-Thinking): 78 content chunks (351 chars) + 107 reasoning chunks (537 chars) — the delta.reasoning_content extraction works end to end against real wire data - Sentinels all return "no such method" 21 unit tests pass on go 1.25; build clean. Note on PR history: this branch was previously named for LocalAI work which has since been consolidated into PR infiniflow#14813. The branch was reset to upstream/main and rebuilt for LongCat — diff is a clean +1052 lines on top of current main.
CodeRabbit review on this PR flagged two issues that match the ones also addressed in the Mistral driver (infiniflow#14805) and StepFun (infiniflow#14815). - ChatWithMessages and ListModels treated a non-nil but empty Region pointer as an explicit region, which then failed baseURLForRegion lookup despite a valid "default" entry. Match the guard already used in ChatStreamlyWithSender: only override "default" when the region string is non-empty. - ChatStreamlyWithSender did not validate that sender was non-nil before invoking it inside the scan loop, which would panic on a nil callback. Add the guard alongside the existing messages and api-key checks.
### What problem does this PR solve? Add a Go driver for StepFun (阶跃星辰), one of the unchecked providers on the umbrella tracking issue infiniflow#14736. Until this PR, a tenant who configured `stepfun` as a model provider in the Go layer fell through to the default branch of `internal/entity/models/factory.go` and got the dummy driver. Chat, list models, and check connection all returned `"not implemented"` instead of reaching the StepFun API. The Python side has had StepFun registered in `rag/llm/__init__.py` as a `SupportedLiteLLMProvider` with base URL `https://api.stepfun.com/v1`, plus `StepFunCV` for vision and `StepFunSeq2txt` for ASR, but no Go path. StepFun's chat API is OpenAI-compatible, so the implementation pattern is the same as the merged Moonshot driver (infiniflow#14433) and OpenAI driver (infiniflow#14605). ### What this PR includes - New file `internal/entity/models/stepfun.go` with a `StepFunModel` that implements the `ModelDriver` interface. - `factory.go`: route the `"stepfun"` provider name to `NewStepFunModel`. - New `conf/models/stepfun.json` with the public StepFun chat models (step-2-16k, step-1 family in 8k/32k/128k/256k context lengths, step-1-flash, and the step-1v / step-1o vision models) and `url_suffix` entries for `chat` and `models`. ### How the driver works - StepFun exposes the OpenAI-compatible API at `https://api.stepfun.com/v1`. - `ChatWithMessages` and `ChatStreamlyWithSender` post to `/chat/completions` in the same shape as the merged moonshot, openrouter, and openai drivers. - `ListModels` and `CheckConnection` call `/models` to list available ids and confirm the API key works. - `Embed` is left as `"not implemented"`. StepFun has not advertised a public embeddings endpoint in the API reference linked from the umbrella issue (`https://platform.stepfun.com/docs/en/api-reference/chat/chat-completion-create` is the chat endpoint), so any real implementation belongs in a separate follow-up only after the endpoint is verified. - `Rerank` and `Balance` return `"no such method"` because StepFun does not expose either. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - `go build ./internal/entity/models/...` returns exit 0 with no errors on go 1.25 (the `go.mod` minimum). - Method set of `StepFunModel` matches the `ModelDriver` interface: `NewInstance`, `Name`, `ChatWithMessages`, `ChatStreamlyWithSender`, `Embed`, `Rerank`, `ListModels`, `Balance`, `CheckConnection`. - Pattern parity with the merged moonshot (infiniflow#14433), openai (infiniflow#14605), openrouter (infiniflow#14652), and xai (infiniflow#14550) drivers. Closes infiniflow#14814 Tracking: infiniflow#14736
What problem does this PR solve?
Add a Go driver for StepFun (阶跃星辰), one of the unchecked providers on the umbrella tracking issue #14736.
Until this PR, a tenant who configured
stepfunas a model provider in the Go layer fell through to the default branch ofinternal/entity/models/factory.goand got the dummy driver. Chat, list models, and check connection all returned"not implemented"instead of reaching the StepFun API.The Python side has had StepFun registered in
rag/llm/__init__.pyas aSupportedLiteLLMProviderwith base URLhttps://api.stepfun.com/v1, plusStepFunCVfor vision andStepFunSeq2txtfor ASR, but no Go path. StepFun's chat API is OpenAI-compatible, so the implementation pattern is the same as the merged Moonshot driver (#14433) and OpenAI driver (#14605).What this PR includes
internal/entity/models/stepfun.gowith aStepFunModelthat implements theModelDriverinterface.factory.go: route the"stepfun"provider name toNewStepFunModel.conf/models/stepfun.jsonwith the public StepFun chat models (step-2-16k, step-1 family in 8k/32k/128k/256k context lengths, step-1-flash, and the step-1v / step-1o vision models) andurl_suffixentries forchatandmodels.How the driver works
https://api.stepfun.com/v1.ChatWithMessagesandChatStreamlyWithSenderpost to/chat/completionsin the same shape as the merged moonshot, openrouter, and openai drivers.ListModelsandCheckConnectioncall/modelsto list available ids and confirm the API key works.Embedis left as"not implemented". StepFun has not advertised a public embeddings endpoint in the API reference linked from the umbrella issue (https://platform.stepfun.com/docs/en/api-reference/chat/chat-completion-createis the chat endpoint), so any real implementation belongs in a separate follow-up only after the endpoint is verified.RerankandBalancereturn"no such method"because StepFun does not expose either.Type of change
How was this tested?
go build ./internal/entity/models/...returns exit 0 with no errors on go 1.25 (thego.modminimum).StepFunModelmatches theModelDriverinterface:NewInstance,Name,ChatWithMessages,ChatStreamlyWithSender,Embed,Rerank,ListModels,Balance,CheckConnection.Closes #14814
Tracking: #14736