Repository navigation
Go: implement provider: Moonshot - #14433
Conversation
📝 WalkthroughWalkthroughTwo methods are implemented in the Moonshot model: Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Chat as MoonshotModel.Chat()
participant Config as APIConfig
participant API as Moonshot API
participant Parser as JSON Parser
Caller->>Chat: Chat(message, config)
Chat->>Chat: Validate message
Chat->>Config: Select region (default: "default")
Chat->>Chat: Build POST request to BaseURL[region]/chat/completions
Chat->>Chat: Add optional fields (stream, max_tokens, top_p, stop, thinking)
Chat->>Chat: Attach JSON payload & Bearer auth
Chat->>API: Send HTTP request
API-->>Chat: HTTP response
Chat->>Chat: Verify HTTP 200
Chat->>Parser: Unmarshal response JSON
Parser->>Parser: Extract choices[0].message.content
Parser->>Parser: Extract choices[0].message.reasoning_content
Parser-->>Chat: Parsed data
Chat-->>Caller: ChatResponse (Answer, ReasonContent)
sequenceDiagram
participant Caller
participant Stream as MoonshotModel.ChatStreamlyWithSender()
participant Config as APIConfig
participant API as Moonshot API
participant Parser as SSE Parser
participant Sender as Callback Handler
Caller->>Stream: ChatStreamlyWithSender(messages, config, sender)
Stream->>Config: Select region
Stream->>Stream: Build POST request with stream: true
Stream->>API: Send HTTP request
API-->>Stream: HTTP 200 + streaming body
Stream->>Stream: Read response body line-by-line
loop For each server-sent event
Stream->>Parser: Parse data: line
alt Non-JSON or [DONE]
Parser->>Stream: Skip line
else Valid event JSON
Parser->>Parser: Extract choices[0].delta.reasoning_content
Parser->>Parser: Extract choices[0].delta.content
Parser->>Sender: Forward (nil, reasoning) OR (content, nil)
Sender-->>Caller: Stream callback
end
end
Stream->>Stream: Check finish_reason
Stream->>Sender: Send [DONE] terminal marker
Sender-->>Caller: Stream complete
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 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: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/entity/models/moonshot.go`:
- Around line 268-270: The loop that reads SSE chunks (scanner.Scan() -> line :=
scanner.Text() -> logger.Info(line)) is logging raw payloads; remove the
logger.Info(line) call and instead either log only non-sensitive metadata (e.g.,
chunk length, event type) or emit a debug-only, redacted version of the payload
(gate behind logger.Debug or a debug flag). Update the code around
scanner.Scan(), line, and logger.Info to avoid writing user
content/reasoning_content to info logs and ensure any full content logging is
explicit, redacted, and only at debug level.
- Around line 326-332: The code currently sends the "[DONE]" endOfStream marker
before checking scanner.Err(), which can signal successful completion even if
the scan failed; modify the logic in the function containing endOfStream and
sender so you first capture and check scanner.Err() (e.g., err := scanner.Err())
and only call sender(&endOfStream, nil) when err is nil (clean finish); if
scanner.Err() is non-nil, return that error without emitting the "[DONE]"
marker.
- Line 195: Replace the hardcoded "/chat/completions" when building the
streaming URL with the provider-configured chat suffix symbol so the endpoint
stays consistent; specifically, in the line that currently builds url using
k.BaseURL[region] (the url := fmt.Sprintf("%s/chat/completions",
k.BaseURL[region]) expression), use URLSuffix.Chat appended to k.BaseURL[region]
(e.g., format or join k.BaseURL[region] and URLSuffix.Chat) so the code relies
on the URLSuffix.Chat constant instead of the literal path.
- Around line 72-83: In the Chat method (where reqBody is assembled)
reject/override stream=true: check chatModelConfig.Stream and if it is non-nil
and true return an error informing callers to use ChatStreamlyWithSender instead
(do not set reqBody["stream"]=true), or alternatively always set
reqBody["stream"]=false before sending; update the logic around reqBody and
chatModelConfig.Stream to ensure the synchronous Chat path never requests
streaming (so the subsequent json.Unmarshal will not receive SSE).
- Around line 197-208: The method ChatStreamlyWithSender currently allows
callers to set chatModelConfig.Stream to false but is hard-wired to parse SSE;
change the logic so reqBody always contains "stream": true (i.e., do not copy
chatModelConfig.Stream into reqBody) or alternatively return an error/fail-fast
from ChatStreamlyWithSender if chatModelConfig.Stream is explicitly false;
update the code around reqBody and the chatModelConfig.Stream check so streaming
cannot be disabled at runtime.
- Around line 267-287: The scanner can hit bufio.Scanner's 64KB token limit and
produce ErrTooLong; update the code that creates and uses scanner (the "scanner
:= bufio.NewScanner(resp.Body)" and the "for scanner.Scan()" loop) to handle
large SSE frames by either increasing the buffer via scanner.Buffer(make([]byte,
0, 1024*1024), 10*1024*1024) to allow larger tokens (e.g., 1MB initial, 10MB
max) and check scanner.Err() for errors, or replace the scanner with a
bufio.Reader and iterate with ReadString('\n') / ReadBytes('\n') (or use
json.Decoder on the stream) to safely read arbitrarily large lines; ensure you
detect bufio.ErrTooLong and surface/log the error instead of silently
terminating.
🪄 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: 88a0e9db-b697-4c6b-84e9-d5a032b9a01a
📒 Files selected for processing (1)
internal/entity/models/moonshot.go
| // Build request body | ||
| reqBody := map[string]interface{}{ | ||
| "model": modelName, | ||
| "messages": []map[string]string{ | ||
| {"role": "user", "content": *message}, | ||
| }, | ||
| "stream": false, | ||
| } | ||
|
|
||
| if chatModelConfig.Stream != nil { | ||
| reqBody["stream"] = *chatModelConfig.Stream | ||
| } |
There was a problem hiding this comment.
Reject stream=true in the synchronous Chat path.
This method always parses a single JSON response, but Line 81 lets callers request a streamed response. When that happens, the provider can return SSE and the later json.Unmarshal path will fail. Force stream=false here or return a clear error directing callers to ChatStreamlyWithSender.
Suggested fix
reqBody := map[string]interface{}{
"model": modelName,
"messages": []map[string]string{
{"role": "user", "content": *message},
},
"stream": false,
}
- if chatModelConfig.Stream != nil {
- reqBody["stream"] = *chatModelConfig.Stream
+ if chatModelConfig.Stream != nil && *chatModelConfig.Stream {
+ return nil, fmt.Errorf("stream=true is not supported in Chat; use ChatStreamlyWithSender")
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Build request body | |
| reqBody := map[string]interface{}{ | |
| "model": modelName, | |
| "messages": []map[string]string{ | |
| {"role": "user", "content": *message}, | |
| }, | |
| "stream": false, | |
| } | |
| if chatModelConfig.Stream != nil { | |
| reqBody["stream"] = *chatModelConfig.Stream | |
| } | |
| // Build request body | |
| reqBody := map[string]interface{}{ | |
| "model": modelName, | |
| "messages": []map[string]string{ | |
| {"role": "user", "content": *message}, | |
| }, | |
| "stream": false, | |
| } | |
| if chatModelConfig.Stream != nil && *chatModelConfig.Stream { | |
| return nil, fmt.Errorf("stream=true is not supported in Chat; use ChatStreamlyWithSender") | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/entity/models/moonshot.go` around lines 72 - 83, In the Chat method
(where reqBody is assembled) reject/override stream=true: check
chatModelConfig.Stream and if it is non-nil and true return an error informing
callers to use ChatStreamlyWithSender instead (do not set
reqBody["stream"]=true), or alternatively always set reqBody["stream"]=false
before sending; update the logic around reqBody and chatModelConfig.Stream to
ensure the synchronous Chat path never requests streaming (so the subsequent
json.Unmarshal will not receive SSE).
| region = *apiConfig.Region | ||
| } | ||
|
|
||
| url := fmt.Sprintf("%s/chat/completions", k.BaseURL[region]) |
There was a problem hiding this comment.
Use URLSuffix.Chat instead of hardcoding the streaming path.
Line 195 bypasses the provider’s configured chat suffix and assumes /chat/completions. That makes streaming silently depend on a different endpoint than Chat, and it will break as soon as the configured path/version diverges.
Suggested fix
- url := fmt.Sprintf("%s/chat/completions", k.BaseURL[region])
+ url := fmt.Sprintf("%s/%s", k.BaseURL[region], k.URLSuffix.Chat)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| url := fmt.Sprintf("%s/chat/completions", k.BaseURL[region]) | |
| url := fmt.Sprintf("%s/%s", k.BaseURL[region], k.URLSuffix.Chat) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/entity/models/moonshot.go` at line 195, Replace the hardcoded
"/chat/completions" when building the streaming URL with the provider-configured
chat suffix symbol so the endpoint stays consistent; specifically, in the line
that currently builds url using k.BaseURL[region] (the url :=
fmt.Sprintf("%s/chat/completions", k.BaseURL[region]) expression), use
URLSuffix.Chat appended to k.BaseURL[region] (e.g., format or join
k.BaseURL[region] and URLSuffix.Chat) so the code relies on the URLSuffix.Chat
constant instead of the literal path.
| // Build request body with streaming enabled | ||
| reqBody := map[string]interface{}{ | ||
| "model": modelName, | ||
| "messages": []map[string]string{ | ||
| {"role": "user", "content": *message}, | ||
| }, | ||
| "stream": true, | ||
| } | ||
|
|
||
| if chatModelConfig.Stream != nil { | ||
| reqBody["stream"] = *chatModelConfig.Stream | ||
| } |
There was a problem hiding this comment.
Do not let callers disable streaming in ChatStreamlyWithSender.
This method is hard-wired to parse SSE, but Line 206 allows stream=false. In that case the provider can return a normal JSON payload, this loop emits no content, and the caller still gets a terminal marker. Keep stream=true unconditionally or fail fast when chatModelConfig.Stream is false.
Suggested fix
reqBody := map[string]interface{}{
"model": modelName,
"messages": []map[string]string{
{"role": "user", "content": *message},
},
"stream": true,
}
- if chatModelConfig.Stream != nil {
- reqBody["stream"] = *chatModelConfig.Stream
+ if chatModelConfig.Stream != nil && !*chatModelConfig.Stream {
+ return fmt.Errorf("stream=false is not supported in ChatStreamlyWithSender")
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Build request body with streaming enabled | |
| reqBody := map[string]interface{}{ | |
| "model": modelName, | |
| "messages": []map[string]string{ | |
| {"role": "user", "content": *message}, | |
| }, | |
| "stream": true, | |
| } | |
| if chatModelConfig.Stream != nil { | |
| reqBody["stream"] = *chatModelConfig.Stream | |
| } | |
| // Build request body with streaming enabled | |
| reqBody := map[string]interface{}{ | |
| "model": modelName, | |
| "messages": []map[string]string{ | |
| {"role": "user", "content": *message}, | |
| }, | |
| "stream": true, | |
| } | |
| if chatModelConfig.Stream != nil && !*chatModelConfig.Stream { | |
| return fmt.Errorf("stream=false is not supported in ChatStreamlyWithSender") | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/entity/models/moonshot.go` around lines 197 - 208, The method
ChatStreamlyWithSender currently allows callers to set chatModelConfig.Stream to
false but is hard-wired to parse SSE; change the logic so reqBody always
contains "stream": true (i.e., do not copy chatModelConfig.Stream into reqBody)
or alternatively return an error/fail-fast from ChatStreamlyWithSender if
chatModelConfig.Stream is explicitly false; update the code around reqBody and
the chatModelConfig.Stream check so streaming cannot be disabled at runtime.
| scanner := bufio.NewScanner(resp.Body) | ||
| for scanner.Scan() { | ||
| line := scanner.Text() | ||
| logger.Info(line) | ||
|
|
||
| // SSE data line starts with "data:" | ||
| if !strings.HasPrefix(line, "data:") { | ||
| continue | ||
| } | ||
|
|
||
| // Extract JSON after "data:" | ||
| data := strings.TrimSpace(line[5:]) | ||
|
|
||
| // [DONE] marks the end of stream | ||
| if data == "[DONE]" { | ||
| break | ||
| } | ||
|
|
||
| // Parse the JSON event | ||
| var event map[string]interface{} | ||
| if err = json.Unmarshal([]byte(data), &event); err != nil { |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -type f -name "moonshot.go" | head -5Repository: infiniflow/ragflow
Length of output: 99
🏁 Script executed:
cat -n ./internal/entity/models/moonshot.go | sed -n '250,310p'Repository: infiniflow/ragflow
Length of output: 1904
🏁 Script executed:
cat -n ./internal/entity/models/moonshot.go | sed -n '310,330p'Repository: infiniflow/ragflow
Length of output: 611
🏁 Script executed:
cat -n ./internal/entity/models/moonshot.go | sed -n '324,340p'Repository: infiniflow/ragflow
Length of output: 684
🌐 Web query:
Go bufio.Scanner default maximum token size limit
💡 Result:
The default maximum token size limit for bufio.Scanner in Go is 64 * 1024 bytes (64 KB). This is defined by the constant MaxScanTokenSize in the bufio package. By default, bufio.NewScanner sets the scanner's maxTokenSize to this value. The actual maximum token size may be slightly smaller because the buffer must accommodate additional data like newlines. If a token exceeds this limit, scanning stops and returns the error bufio.ErrTooLong (via s.Err). This limit can be increased by calling scanner.Buffer(buf, max) before scanning, where max > MaxScanTokenSize, but for very large or unbounded tokens, bufio.Reader is recommended instead.
Citations:
- 1: https://go.dev/src/bufio/scan.go
- 2: https://pkg.go.dev/bufio
- 3: https://pkg.go.dev/[email protected]
🏁 Script executed:
# Check if there are tests or other uses of this moonshot model
grep -r "MoonshotModel" --include="*.go" | head -20Repository: infiniflow/ragflow
Length of output: 2180
Increase the scanner buffer for large SSE frames.
bufio.Scanner has a default token size limit of 64 KB. Since this code parses Moonshot reasoning model responses (which include reasoning_content fields), large frames will cause the scanner to fail with ErrTooLong, silently terminating the stream. Increase the buffer size or use a reader-based parser.
Suggested fix
// SSE parsing: read line by line
scanner := bufio.NewScanner(resp.Body)
+ scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
for scanner.Scan() {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/entity/models/moonshot.go` around lines 267 - 287, The scanner can
hit bufio.Scanner's 64KB token limit and produce ErrTooLong; update the code
that creates and uses scanner (the "scanner := bufio.NewScanner(resp.Body)" and
the "for scanner.Scan()" loop) to handle large SSE frames by either increasing
the buffer via scanner.Buffer(make([]byte, 0, 1024*1024), 10*1024*1024) to allow
larger tokens (e.g., 1MB initial, 10MB max) and check scanner.Err() for errors,
or replace the scanner with a bufio.Reader and iterate with ReadString('\n') /
ReadBytes('\n') (or use json.Decoder on the stream) to safely read arbitrarily
large lines; ensure you detect bufio.ErrTooLong and surface/log the error
instead of silently terminating.
| for scanner.Scan() { | ||
| line := scanner.Text() | ||
| logger.Info(line) |
There was a problem hiding this comment.
Remove raw SSE payload logging from the hot path.
logger.Info(line) will write every streamed chunk, including user content and reasoning_content, into normal logs. That is both a privacy risk and a log-volume problem for long generations. Keep this out of info logs or gate a redacted form behind debug-only instrumentation.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/entity/models/moonshot.go` around lines 268 - 270, The loop that
reads SSE chunks (scanner.Scan() -> line := scanner.Text() -> logger.Info(line))
is logging raw payloads; remove the logger.Info(line) call and instead either
log only non-sensitive metadata (e.g., chunk length, event type) or emit a
debug-only, redacted version of the payload (gate behind logger.Debug or a debug
flag). Update the code around scanner.Scan(), line, and logger.Info to avoid
writing user content/reasoning_content to info logs and ensure any full content
logging is explicit, redacted, and only at debug level.
| // Send [DONE] marker for OpenAI compatibility | ||
| endOfStream := "[DONE]" | ||
| if err = sender(&endOfStream, nil); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return scanner.Err() |
There was a problem hiding this comment.
Only emit [DONE] after the scan ends cleanly.
Right now the terminal marker is sent before scanner.Err() is checked. If the connection dies mid-stream, downstream sees a successful terminator and may finalize partial output as complete. Check the scan error first, then send [DONE] only on a clean finish.
Suggested fix
- // Send [DONE] marker for OpenAI compatibility
- endOfStream := "[DONE]"
- if err = sender(&endOfStream, nil); err != nil {
- return err
- }
-
- return scanner.Err()
+ if err = scanner.Err(); err != nil {
+ return err
+ }
+
+ // Send [DONE] marker for OpenAI compatibility
+ endOfStream := "[DONE]"
+ return sender(&endOfStream, nil)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Send [DONE] marker for OpenAI compatibility | |
| endOfStream := "[DONE]" | |
| if err = sender(&endOfStream, nil); err != nil { | |
| return err | |
| } | |
| return scanner.Err() | |
| if err = scanner.Err(); err != nil { | |
| return err | |
| } | |
| // Send [DONE] marker for OpenAI compatibility | |
| endOfStream := "[DONE]" | |
| return sender(&endOfStream, nil) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/entity/models/moonshot.go` around lines 326 - 332, The code
currently sends the "[DONE]" endOfStream marker before checking scanner.Err(),
which can signal successful completion even if the scan failed; modify the logic
in the function containing endOfStream and sender so you first capture and check
scanner.Err() (e.g., err := scanner.Err()) and only call sender(&endOfStream,
nil) when err is nil (clean finish); if scanner.Err() is non-nil, return that
error without emitting the "[DONE]" marker.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14433 +/- ##
=======================================
Coverage 95.30% 95.30%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 670 670
Misses 16 16
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Closes #14552 ### What problem does this PR solve? Add a Go driver for xAI (Grok models). The config file conf/models/xai.json has been in the repo since the early Go provider work, but internal/entity/models/factory.go had no case for "xai". So any xAI request fell through to the dummy driver and never reached the API. This PR adds the missing driver and wires it up. ### What this PR includes - New file internal/entity/models/xai.go with an XAIModel that implements the ModelDriver interface. - factory.go: route the "xai" provider name to NewXAIModel. ### How the driver works - xAI exposes an OpenAI-compatible API at https://api.x.ai/v1. - ChatWithMessages and ChatStreamlyWithSender post to /chat/completions in the same shape the moonshot and deepseek drivers use. - ListModels and CheckConnection call /models to confirm the API key works and to list available model ids. - reasoning_content is passed through for grok-3-mini and other xAI reasoning models, both in the non-stream and stream paths. - Encode, Rerank, and Balance are not part of the public xAI API at the moment, so they return a clear "not implemented" or "no such method" error. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - go build ./internal/entity/models/... in a clean go 1.25 image (the go.mod minimum) returns exit 0 with no errors. - Method set of XAIModel matches the ModelDriver interface: NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank, ListModels, Balance, CheckConnection. - Pattern parity with the merged moonshot (#14433), volcengine (#14460), minimax (#14478), and vllm (#14532) PRs. --------- Co-authored-by: Jin Hai <[email protected]>
### What problem does this PR solve? Add a Go driver for OpenAI (GPT models). The config file conf/models/openai.json has been in the repo for a while with the full GPT-5 model list, but internal/entity/models/factory.go had no case for "openai". So any tenant that configured OpenAI as a model provider in the Go layer fell through to the default branch and got the dummy driver. Chat, list models, and check connection all returned dummy responses instead of reaching the API. OpenAI is the most commonly requested provider and the JSON config already ships with the repo, so this gap is high impact even though the JSON has been there for some time. ### What this PR includes - New file internal/entity/models/openai.go with an OpenAIModel that implements the ModelDriver interface. - factory.go: route the "openai" provider name to NewOpenAIModel. - conf/models/openai.json: add "models": "models" under url_suffix so ListModels can hit /v1/models with no hardcoded fallback. ### How the driver works - OpenAI exposes the canonical OpenAI-compatible API at https://api.openai.com/v1. - ChatWithMessages and ChatStreamlyWithSender post to /chat/completions in the same shape the moonshot, vllm, and xai drivers use. - ListModels and CheckConnection call /models to list available ids and confirm the API key works. - reasoning_content is passed through for the o-series and other reasoning models, in both the non-stream and stream paths. - Encode (embeddings) is left as "not implemented" for now, the same way the other recent provider drivers do it. Rerank and Balance are not part of OpenAI's public API surface in this layer and return a clear "not implemented" or "no such method" error. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - go build ./internal/entity/models/... in a clean go 1.25 image (the go.mod minimum) returns exit 0 with no errors. - Method set of OpenAIModel matches the ModelDriver interface: NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank, ListModels, Balance, CheckConnection. - Pattern parity with the merged moonshot (#14433), volcengine (#14460), minimax (#14478), vllm (#14532), xai (#14550), and lm-studio (#14586) PRs. Closes #14604
### 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 `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 (#14433) and OpenAI driver (#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 (#14433), openai (#14605), openrouter (#14652), and xai (#14550) drivers. Closes #14814 Tracking: #14736
### What problem does this PR solve? Add a Go driver for OpenAI (GPT models). The config file conf/models/openai.json has been in the repo for a while with the full GPT-5 model list, but internal/entity/models/factory.go had no case for "openai". So any tenant that configured OpenAI as a model provider in the Go layer fell through to the default branch and got the dummy driver. Chat, list models, and check connection all returned dummy responses instead of reaching the API. OpenAI is the most commonly requested provider and the JSON config already ships with the repo, so this gap is high impact even though the JSON has been there for some time. ### What this PR includes - New file internal/entity/models/openai.go with an OpenAIModel that implements the ModelDriver interface. - factory.go: route the "openai" provider name to NewOpenAIModel. - conf/models/openai.json: add "models": "models" under url_suffix so ListModels can hit /v1/models with no hardcoded fallback. ### How the driver works - OpenAI exposes the canonical OpenAI-compatible API at https://api.openai.com/v1. - ChatWithMessages and ChatStreamlyWithSender post to /chat/completions in the same shape the moonshot, vllm, and xai drivers use. - ListModels and CheckConnection call /models to list available ids and confirm the API key works. - reasoning_content is passed through for the o-series and other reasoning models, in both the non-stream and stream paths. - Encode (embeddings) is left as "not implemented" for now, the same way the other recent provider drivers do it. Rerank and Balance are not part of OpenAI's public API surface in this layer and return a clear "not implemented" or "no such method" error. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - go build ./internal/entity/models/... in a clean go 1.25 image (the go.mod minimum) returns exit 0 with no errors. - Method set of OpenAIModel matches the ModelDriver interface: NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank, ListModels, Balance, CheckConnection. - Pattern parity with the merged moonshot (infiniflow#14433), volcengine (infiniflow#14460), minimax (infiniflow#14478), vllm (infiniflow#14532), xai (infiniflow#14550), and lm-studio (infiniflow#14586) PRs. Closes infiniflow#14604
### 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?
implement
MoonshotproviderType of change