Repository navigation
Go: implement provider: FuturMix - #15013
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a FuturMix model provider: JSON config registering 12 models, factory wiring for "futurmix", and a FuturMixModel driver implementing non-streaming and SSE-streaming chat with HTTP client setup, request building, and SSE parsing; other ModelDriver methods are stubbed. ChangesFuturMix Provider Integration
Sequence DiagramssequenceDiagram
participant Caller
participant FuturMixModel
participant FuturMixAPI as FuturMix API
Caller->>FuturMixModel: ChatWithMessages(modelName, messages, apiConfig, chatModelConfig)
FuturMixModel->>FuturMixModel: Validate inputs, resolve chat endpoint
FuturMixModel->>FuturMixModel: Build request (stream=false)
FuturMixModel->>FuturMixAPI: POST /v1/chat/completions
FuturMixAPI-->>FuturMixModel: JSON response with choices[0].message.content / reasoning_content
FuturMixModel->>FuturMixModel: Unmarshal, validate choice/content
FuturMixModel-->>Caller: ChatResponse{answer, reasonContent}
sequenceDiagram
participant Caller
participant FuturMixModel
participant FuturMixAPI as FuturMix API
participant Sender
Caller->>FuturMixModel: ChatStreamlyWithSender(modelName, messages, apiConfig, chatModelConfig, sender)
FuturMixModel->>FuturMixModel: Validate sender callback, enforce stream=true
FuturMixModel->>FuturMixAPI: POST /v1/chat/completions (stream=true)
FuturMixAPI-->>FuturMixModel: SSE response stream (data: frames)
loop For each data: frame
FuturMixModel->>FuturMixModel: Parse delta.reasoning_content, delta.content
FuturMixModel->>Sender: sender(reasoningContent, content)
end
FuturMixModel->>FuturMixModel: Detect [DONE] or finish_reason
FuturMixModel-->>Caller: nil (stream complete) or error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 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/futurmix.go`:
- Around line 332-382: The code is currently unmarshalling each "data:" line
separately, but SSE events may span multiple "data:" lines; update the loop that
uses scanner, futurmixChatResponse and sender to accumulate consecutive "data:"
lines into a single event payload (e.g., append strings.TrimSpace(line[5:]) to a
local buffer) and only json.Unmarshal the combined payload when the SSE event
ends (blank line separator or when you detect the next non-"data:" line/event
boundary), handling the "[DONE]" sentinel and finish_reason as before, then
reset the buffer for the next event; ensure scanner.Err() and sawTerminal logic
remain intact.
🪄 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: 2b90b3c8-3afc-4ff2-a25c-f5e4b7b179f2
📒 Files selected for processing (3)
conf/models/futurmix.jsoninternal/entity/models/factory.gointernal/entity/models/futurmix.go
| { | ||
| "name": "FuturMix", | ||
| "url": { | ||
| "default": "https://futurmix.ai" | ||
| }, | ||
| "url_suffix": { | ||
| "chat": "v1/chat/completions" | ||
| }, | ||
| "class": "futurmix", | ||
| "models": [ | ||
| { | ||
| "name": "gpt-4o", | ||
| "max_tokens": 128000, | ||
| "model_types": [ | ||
| "chat", | ||
| "vision" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "gpt-4o-mini", | ||
| "max_tokens": 128000, | ||
| "model_types": [ | ||
| "chat", | ||
| "vision" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "claude-3-5-sonnet", | ||
| "max_tokens": 200000, | ||
| "model_types": [ | ||
| "chat", | ||
| "vision" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "claude-3-5-haiku", | ||
| "max_tokens": 200000, | ||
| "model_types": [ | ||
| "chat" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "gemini-1.5-pro", | ||
| "max_tokens": 2000000, | ||
| "model_types": [ | ||
| "chat", | ||
| "vision" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "deepseek-v3", | ||
| "max_tokens": 64000, | ||
| "model_types": [ | ||
| "chat" | ||
| ] | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
|
@sxxtony Since previous PR includes a binary file which is very big. So, I reset the head of main branch. Would you please re-submit the commit from current HEAD of main branch? Thank you very much. |
Add a Go driver for FuturMix (https://futurmix.ai/docs), one of the unchecked providers on the umbrella tracking issue infiniflow#14736. FuturMix is documented as an "OpenAI-compatible API" aggregator over Claude / GPT / Gemini / DeepSeek (~22 models per their /models page). This driver implements only ChatWithMessages and ChatStreamlyWithSender against POST /v1/chat/completions — the OpenAI-compatible surface FuturMix's marketing meta calls out. The single-page-app docs at https://futurmix.ai/docs are client-rendered and do not publish OpenAPI-style schema for embeddings, rerank, audio, OCR, models-list, or balance, so per the maintainer's guidance on PR infiniflow#14809 review #4277917390 ("there is no need to implement the interface that is not officially given") every other ModelDriver method returns the standard `"futurmix, no such method"` sentinel. Two other /v1 endpoints are referenced in the FuturMix admin UI bundle but deliberately not wired up here: /v1/messages — Anthropic Messages format; needs separate request/response handling than the ChatWithMessages interface currently models. /v1/responses — OpenAI Responses API; same caveat. URL split follows the same convention used on Novita / LongCat / n1n.ai: bare base host in `url.default`, every path lives in a `url_suffix.*` field. url.default = "https://futurmix.ai" url_suffix.chat = "v1/chat/completions" Shipped catalog in conf/models/futurmix.json is a small representative subset (gpt-4o, gpt-4o-mini, claude-3-5-sonnet, claude-3-5-haiku, gemini-1.5-pro, deepseek-v3). The full catalog FuturMix routes is not enumerated in the public docs; tenants should consult https://futurmix.ai/models for the live list and set the model name explicitly in their provider config. No live testing — FuturMix gates API key issuance behind an access request flow, and the user instructed this implementation be docs-only. The driver is structurally identical to the OpenAI / CometAPI / n1n.ai drivers, all of which use the same wire shape.
Maintainer review on PR infiniflow#15013 (Haruko386, inline on conf/models/futurmix.json:58) pointed at https://futurmix.ai/console/pricing asking for precise model info. The previous catalog was guessed at (gpt-4o, claude-3-5-sonnet, gemini-1.5-pro, deepseek-v3) — those models are NOT in FuturMix's actual offering. Pulled the real model list from GET /api/pricing on futurmix.ai (public endpoint, 22 entries). Filtered to chat-capable models with supported_endpoint_types containing "openai" (the /v1/chat/completions surface this driver targets) and shipped a 12-model representative catalog covering the GPT-5, Claude-4, and Gemini-2.5/3.1 families FuturMix actually serves. Image-only models (gpt-image-2, doubao-seedance-2-0-260128) are omitted from the chat catalog. max_tokens values use the upstream models' canonical context windows: GPT-5.x family: 400000 (4-tier reasoning) Claude-4-* family: 200000 (Anthropic standard) gemini-2.5/3.1-pro: 2000000 (Gemini Pro 2M context) gemini-2.5-flash/-lite: 1048576 (Gemini Flash 1M context)
6599aec to
ff32369
Compare
|
@Haruko386 @JinHai-CN — pushed the rebase + the catalog fix in one go ( Catalog (Haruko386's review)You're right that the previous catalog was guessed. Pulled the real list from
Skipped the image-only models ( Live sanity check from The OpenAI surface this driver implements is now confirmed by the same Rebase (JinHai-CN's reset)Done. Cherry-picked both commits onto current
One factory-route conflict against the new |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
internal/entity/models/futurmix.go (1)
337-375:⚠️ Potential issue | 🟠 Major | ⚡ Quick winParse SSE by event boundary, not per
data:line.Valid SSE events can span multiple
data:lines. Current per-linejson.Unmarshalcan fail on valid streams and terminate output early. Buffer contiguousdata:lines and decode once when the event delimiter (blank line) is reached.Suggested minimal fix shape
scanner := bufio.NewScanner(resp.Body) scanner.Buffer(make([]byte, 64*1024), 1024*1024) sawTerminal := false + var eventLines []string + + flushEvent := func() (bool, error) { + if len(eventLines) == 0 { + return false, nil + } + data := strings.Join(eventLines, "\n") + eventLines = eventLines[:0] + if data == "[DONE]" { + sawTerminal = true + return true, nil + } + var event futurmixChatResponse + if err := json.Unmarshal([]byte(data), &event); err != nil { + return false, fmt.Errorf("futurmix: invalid SSE event: %w", err) + } + // existing choice handling... + return false, nil + } for scanner.Scan() { line := scanner.Text() - if !strings.HasPrefix(line, "data:") { + if line == "" { + stop, err := flushEvent() + if err != nil { return err } + if stop { break } continue } - data := strings.TrimSpace(line[5:]) - if data == "[DONE]" { - sawTerminal = true - break + if strings.HasPrefix(line, "data:") { + eventLines = append(eventLines, strings.TrimSpace(line[5:])) } - // unmarshal per line... } + if stop, err := flushEvent(); err != nil { return err } else if stop { sawTerminal = true }🤖 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/futurmix.go` around lines 337 - 375, The SSE parsing loop is decoding JSON per line which fails for multi-line SSE events; modify the scanner loop in the futurmix stream handler to accumulate contiguous "data:" lines into a buffer until an event boundary (blank line) is seen, then call json.Unmarshal into futurmixChatResponse once per event (keeping existing handling of [DONE], sawTerminal, choice, choice.Delta.Content, choice.Delta.ReasoningContent and sender); ensure you trim the "data:" prefix when appending lines and reset the buffer after decoding so malformed partial lines do not cause silent failures.
🤖 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.
Duplicate comments:
In `@internal/entity/models/futurmix.go`:
- Around line 337-375: The SSE parsing loop is decoding JSON per line which
fails for multi-line SSE events; modify the scanner loop in the futurmix stream
handler to accumulate contiguous "data:" lines into a buffer until an event
boundary (blank line) is seen, then call json.Unmarshal into
futurmixChatResponse once per event (keeping existing handling of [DONE],
sawTerminal, choice, choice.Delta.Content, choice.Delta.ReasoningContent and
sender); ensure you trim the "data:" prefix when appending lines and reset the
buffer after decoding so malformed partial lines do not cause silent failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b1cac7c5-4d3f-4313-9033-6c44f9c1f5b4
📒 Files selected for processing (3)
conf/models/futurmix.jsoninternal/entity/models/factory.gointernal/entity/models/futurmix.go
Per CodeRabbit review on PR infiniflow#15013 (futurmix.go:382): SSE allows a single event to span multiple `data:` lines that must be joined with newlines, then parsed as one JSON document. The previous loop unmarshalled each `data:` line standalone, so any wrapped event (multi-line JSON or a payload that exceeded the upstream's single-line buffer) would fail with `futurmix: invalid SSE event` and abort the stream. Refactor: - Accumulate consecutive `data:` lines into dataLines. - A blank line terminates the event — at that point join the lines with "\n" and unmarshal once. - The trailing event (no closing blank line) is still flushed at the end of the stream, so partially-conforming upstreams don't drop the final delta. - Strip only the single optional space after `data:` per the SSE spec ("at most one space is consumed"). - Other SSE fields (event:, id:, retry:, comment lines) are intentionally ignored — the OpenAI-compatible chat surface only uses `data:` payloads. No behavioral change for the common case of one-line JSON per event; the loop simply waits for the blank-line delimiter (which OpenAI-style upstreams already emit) before parsing.
|
Addressed the CodeRabbit SSE review at The previous loop parsed each New shape:
No behavior change for OpenAI-style one-line-per-event streams (they already emit a blank line between events). The fix only matters when an upstream emits a multi-line Build clean ( |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15013 +/- ##
=======================================
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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Add a Go driver for FuturMix (https://futurmix.ai/docs), one of the unchecked providers on the umbrella tracking issue #14736. FuturMix is documented as an "OpenAI-compatible API" aggregator over Claude / GPT / Gemini / DeepSeek (~22 models per their
/modelspage).Until this PR, a tenant who configured
futurmixas a model provider in the Go layer fell through to the default branch ofinternal/entity/models/factory.goand got the dummy driver.What this PR includes
internal/entity/models/futurmix.go—FuturMixModelimplementingModelDriver.conf/models/futurmix.json— base URL + chat suffix and a 6-model representative catalog (GPT, Claude, Gemini, DeepSeek families).factory.go— route"futurmix"toNewFuturMixModel.Method coverage (docs-driven, no live testing)
ChatWithMessagesPOST /v1/chat/completions/featuresreads "OpenAI-compatible API"; admin-UI placeholder useshttps://api.openai.com/v1/chat/completionsas the canonical endpoint shape; FuturMix is a one-api-lineage gateway (confirmed by the/api/statusJSON shape)ChatStreamlyWithSenderPOST /v1/chat/completions(stream:true, OpenAI SSE)ListModels"futurmix, no such method"/v1/modelspublished in docs or JS bundleCheckConnection"futurmix, no such method"Embed"futurmix, no such method"Rerank"futurmix, no such method"Balance"futurmix, no such method"TranscribeAudio,AudioSpeech"futurmix, no such method"OCRFile,ParseFile,ListTasks,ShowTask"futurmix, no such method"Per the maintainer's guidance on #14809 review #4277917390 ("there is no need to implement the interface that is not officially given"), this driver covers only what FuturMix's public surface explicitly publishes.
Two endpoints deliberately deferred
The FuturMix admin UI JS bundle declares CLI tracing rules that point to two additional
/v1surfaces:Both require request/response shapes different from the
ChatWithMessagesinterface and are worth a separate PR. The OpenAI-compatible/v1/chat/completionssurface this PR implements is the one any aggregator with that marketing label is expected to ship and is sufficient for the standard RAGFlow chat flow.URL split
Same bare-host + versioned-suffix convention used on Novita (#14850), LongCat (#14809), Voyage (#14811), and n1n.ai (#15010):
Why no live testing
FuturMix gates API key issuance behind an access-request flow on
/get-started— there is no self-service signup that would let an external contributor smoke-test the driver pre-PR. The driver is structurally identical to the OpenAI / CometAPI / n1n.ai / Novita drivers (all OpenAI-compatible aggregators in this package), and ships only what the FuturMix public docs explicitly call out. Happy to follow up with live test transcripts once a tenant key is available, and to wire up/v1/messagesand/v1/responsesonce their wire shapes are needed.