Repository navigation
Go: implement provider: Novita.ai - #14850
Conversation
Novita.ai (https://novita.ai) is one of the unchecked providers on the umbrella tracking issue infiniflow#14736. It exposes an OpenAI-compatible REST API at https://api.novita.ai/v3/openai and proxies a large catalog (102+ models live at the time of writing): DeepSeek, Llama, Qwen3, Kimi, Gemma, Mistral, MiniMax, GLM, etc. What this PR includes: - internal/entity/models/novita.go: full driver, ~520 lines - conf/models/novita.json: 7 representative chat models (DeepSeek-V4, Llama-3.3-70B, Qwen3-30B/235B reasoning, Kimi-K2, Gemma-3-27B, Mistral-Nemo) - factory.go: route "novita" to NewNovitaModel - internal/entity/models/novita_test.go: 23 unit tests The notable design point: Novita-routed reasoning models like qwen3-* and deepseek-r1-* embed their chain-of-thought INLINE inside content as <think>...</think> tags rather than in a separate reasoning_content field (verified live against api.novita.ai/v3/openai/chat/completions). The driver detects those tags and routes the inner text to ChatResponse.ReasonContent (non-stream) or the sender's second arg (stream), keeping the visible answer clean of tag clutter. Implementation: - splitNovitaThink: scans a complete content string, returns (visible, reasoning). Handles multiple <think> blocks, unclosed tags, pure-text content. Used by the non-streaming path. - novitaThinkExtractor: stateful streaming version. Buffers trailing bytes that might be the start of a tag (e.g. "<thi" when the next chunk completes "nk>"). Emits segments in routing order so callers can pipe them to a UI. Tested with tag-spanning scenarios including byte-level chunking. Methods: - ChatWithMessages: non-stream, with <think>-tag extraction - ChatStreamlyWithSender: SSE stream, stateful tag extraction across deltas - ListModels / CheckConnection: /v1/models (102 live) - Embed / Rerank / Balance / TranscribeAudio / AudioSpeech / OCRFile return "no such method" (Novita's OpenAI-compatible surface does not expose any of these) 23 unit tests pass on go 1.25; build clean. Test coverage includes: the split helper (5 cases: pure text, single block, leading text, multiple blocks, unclosed tag); the streaming extractor (6 cases: single-chunk, opening tag span, closing tag span, byte-level chunking, no tags, lone "<" not as tag start); the driver methods; and the sentinels. Verified live against api.novita.ai/v3/openai: - ListModels: 102 models - Chat (llama-3.3-70b-instruct): answer="ok", reason="" - Chat (qwen3-30b-a3b-fp8): 1657-char reasoning extracted; visible answer 0 chars because the model spent its 600-token budget on reasoning (verified the <think> tags were stripped, not leaked) - Stream (qwen3-30b-a3b-fp8): 600 reasoning chunks (1667 chars) emitted via sender's 2nd arg across deltas; 0 content chunks (same budget reason); no <think> tag fragments leaked into content - Sentinels: all return "no such method"
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds Novita.ai provider support: provider config, factory registration, NovitaModel implementation (non-streaming and streaming chat with extraction), model listing/checks, unsupported-method stubs, and comprehensive tests. ChangesNovita AI Provider Integration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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
🧹 Nitpick comments (1)
internal/entity/models/novita_test.go (1)
296-312: ⚡ Quick winHarden streaming tests by asserting request contract too.
The two streaming tests bypass
newNovitaServer, so regressions in path/auth/POST JSON headers forChatStreamlyWithSendercan slip through untested.Refactor sketch
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + srv := newNovitaServer(t, "/chat/completions", func(t *testing.T, _ map[string]interface{}, w http.ResponseWriter) { w.Header().Set("Content-Type", "text/event-stream") _, _ = io.WriteString(w, ...) - })) + })Also applies to: 348-356
🤖 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/novita_test.go` around lines 296 - 312, The streaming tests currently bypass newNovitaServer so they don't verify the request contract for ChatStreamlyWithSender; update the httptest.NewServer handler(s) in novita_test.go to validate incoming requests (check r.Method == "POST", r.URL.Path matches the chat stream endpoint used by newNovitaServer, Authorization header presence/value, Content-Type: application/json, and that the POST body parses as the expected JSON payload for ChatStreamlyWithSender) and return a non-200 (e.g. 400) on mismatch before writing the SSE stream; apply the same validation to the other streaming test block around the 348-356 region so both tests exercise the request contract.
🤖 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/novita.go`:
- Around line 244-245: The URL construction can produce double slashes when
baseURL ends with '/' or suffix begins with '/'; update the three places where
you build endpoints (the line with url := fmt.Sprintf("%s/%s", baseURL,
n.URLSuffix.Chat) and the similar constructions around the later occurrences) to
normalize parts first by trimming separators: use strings.TrimRight(baseURL,
"/") and strings.TrimLeft(n.URLSuffix.Chat (and the other n.URLSuffix fields
used at the two other sites), "/") before combining (or use path.Join after
converting suffixes), and add the strings import if missing so endpoint assembly
never yields '//' and works with strict upstream routing.
---
Nitpick comments:
In `@internal/entity/models/novita_test.go`:
- Around line 296-312: The streaming tests currently bypass newNovitaServer so
they don't verify the request contract for ChatStreamlyWithSender; update the
httptest.NewServer handler(s) in novita_test.go to validate incoming requests
(check r.Method == "POST", r.URL.Path matches the chat stream endpoint used by
newNovitaServer, Authorization header presence/value, Content-Type:
application/json, and that the POST body parses as the expected JSON payload for
ChatStreamlyWithSender) and return a non-200 (e.g. 400) on mismatch before
writing the SSE stream; apply the same validation to the other streaming test
block around the 348-356 region so both tests exercise the request contract.
🪄 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: a51eceff-4519-4a21-8b17-327906dd2bcc
📒 Files selected for processing (4)
conf/models/novita.jsoninternal/entity/models/factory.gointernal/entity/models/novita.gointernal/entity/models/novita_test.go
CodeRabbit caught that the three endpoint builders (Chat, Stream,
ListModels) all use fmt.Sprintf("%s/%s", baseURL, suffix). If a
tenant configures baseURL with a trailing slash — e.g., overriding
to "https://api.novita.ai/v3/openai/" — every URL the driver builds
would have "//" in the path, which strict upstream routing can reject
with 404.
Fix in baseURLForRegion: strings.TrimSuffix(base, "/") before
returning. All three call sites benefit at zero touch to the call
sites themselves. The shipped conf/models/novita.json has no
trailing slash; this only matters for tenant overrides.
Test: TestNovitaBaseURLTrimsTrailingSlash configures baseURL with a
trailing "/" and verifies all three endpoints (chat, models, stream
chat) hit the expected clean paths /chat/completions and /models —
not //chat/... or //models. Three sub-tests, one per endpoint.
24 unit tests pass on go 1.25; build clean.
Haruko386
left a comment
There was a problem hiding this comment.
Hi @tmimmanuel, please read the docs before your test or submit your code.
Per infiniflow#14850 (review) maintainer review on commit 3faf24e: Endpoints (conf/models/novita.json): - Provider name "NovitaAI" -> "Novita" (matches the platform name). - baseURL "https://api.novita.ai/v3/openai" -> "https://api.novita.ai". The /v3/openai prefix was a leftover; the canonical OpenAI-style surface is mounted at /openai under api.novita.ai. - url_suffix.chat "chat/completions" -> "openai/v1/chat/completions" (the path listed in https://novita.ai/docs/api-reference/model-apis-llm-create-chat-completion). - url_suffix.models "models" -> "openai/v1/models" (matches the path shown in the docs at platform/docs/.../model-apis-llm-list-models; the maintainer's suggested "v1/models" 404s live, but the docs page itself clearly shows the openai-prefixed form). ListModels (novita.go): - Add the missing `Content-Type: application/json` header on the GET request. The maintainer flagged this on the original line 536. enable_thinking (novita.go): - Map ChatConfig.Thinking *bool -> Novita's documented `enable_thinking` body field on both ChatWithMessages and ChatStreamlyWithSender. Previously there was no way for a tenant to disable thinking mode without editing the user prompt. - Per Novita docs the supported models are zai-org/glm-4.5, deepseek/deepseek-v3.1[-terminus|-exp]; live-confirmed the toggle also flips qwen3-* deployments out of <think> mode. reasoning_content shape (novita.go): - Live audit of api.novita.ai showed that the chain-of-thought arrives in two different wire shapes depending on the model: qwen3-* embeds it inline as <think>...</think> in content, while deepseek-v3.1 / glm-4.5 with thinking on put it in a separate `reasoning_content` field on the message and stream deltas (66 reasoning_content chunks in a single deepseek-v3.1 stream). The driver now handles both: the non-stream path merges reasoning_content into ChatResponse.ReasonContent alongside the inline-tag split, and the stream path emits delta.reasoning_content to the sender's second arg before processing delta.content. Tests (novita_test.go): - newNovitaServer now asserts Content-Type on GET as well as POST so the ListModels header is exercised, and accepts any prefix of "application/json" (e.g. with `; charset=utf-8`). - New newNovitaSSEServer helper applies the same wire-contract assertions (POST + path + auth + Content-Type) to the streaming tests, closing the CodeRabbit gap on `296-312` and `348-356`. - New tests pinning the new behaviour: TestNovitaChatExtractsReasoningContentField TestNovitaStreamExtractsDeltaReasoningContent TestNovitaChatPropagatesEnableThinking (enabled/disabled) TestNovitaChatOmitsEnableThinkingWhenUnset TestNovitaStreamPropagatesEnableThinking
|
@Haruko386 thanks — went back through https://novita.ai/docs/api-reference/model-apis-llm-create-chat-completion and https://novita.ai/docs/api-reference/model-apis-llm-list-models and pushed ee8259e. Same lesson applied here as in #14809: align to the docs first, then live-verify. What changed
|
| Field | Before | After |
|---|---|---|
name |
NovitaAI |
Novita |
url.default |
https://api.novita.ai/v3/openai |
https://api.novita.ai |
url_suffix.chat |
chat/completions |
openai/v1/chat/completions |
url_suffix.models |
models |
openai/v1/models |
Note on v1/models vs openai/v1/models: your inline comment said v1/models. Live-probing https://api.novita.ai/v1/models returned HTTP 404; the docs page you linked clearly lists the path as /openai/v1/models, and that one returns 200 with the full 102-model catalog. I went with the docs-and-live-verified openai/v1/models. If you actually meant a different host or prefix, please flag — happy to change.
internal/entity/models/novita.go
-
ListModelsmissingContent-Typeheader — added. -
enable_thinkingswitch —ChatConfig.Thinking *boolnow maps to Novita's documentedenable_thinkingbody field on bothChatWithMessagesandChatStreamlyWithSender. A tenant chatting withqwen3-30b-a3b-fp8can now flip thinking off at request time:$ curl … -d '{"model":"qwen/qwen3-30b-a3b-fp8","messages":[…],"enable_thinking":false}' {"choices":[{"message":{"role":"assistant","content":"Hello! How can I assist you today? 😊"}…}]}(no
<think>...</think>clutter, just the answer) -
Two reasoning shapes, not one — live audit caught this and the driver now handles both:
Shape Models How the driver routes it <think>...</think>inline insidecontentqwen3-* (default) existing tag splitter routes to ReasonContentSeparate reasoning_contentfield onmessage/deltadeepseek-v3.1, glm-4.5, anything with enable_thinkingonnew code path — merges into ChatResponse.ReasonContentand emits via the stream sender's second argLive test on
deepseek/deepseek-v3.1withenable_thinking=trueconfirmed 66delta.reasoning_contentchunks arrive per stream. The previous code only readdelta.content, so all of that reasoning was being silently dropped on the floor.
Tests
New tests pinning the new behaviour:
TestNovitaChatExtractsReasoningContentFieldTestNovitaStreamExtractsDeltaReasoningContentTestNovitaChatPropagatesEnableThinking(enabled / disabled)TestNovitaChatOmitsEnableThinkingWhenUnsetTestNovitaStreamPropagatesEnableThinking
Existing streaming tests now go through a new newNovitaSSEServer helper that asserts POST + path + Authorization + Content-Type, closing the CodeRabbit gap from the prior review.
Live re-verification against api.novita.ai
POST /openai/v1/chat/completions -> 200 (llama-3.3-70b)
GET /openai/v1/models -> 200, 102 models
POST /openai/v1/chat/completions -> deepseek-v3.1, enable_thinking=true
-> choices[0].message.reasoning_content present
POST /openai/v1/chat/completions -> deepseek-v3.1, enable_thinking=false
-> choices[0].message.reasoning_content absent
POST /openai/v1/chat/completions -> qwen3, enable_thinking=false
-> content has no <think> tags
GET /v1/models -> 404 (your typo-suggestion path)
Not addressed in this commit
The Novita docs also list /openai/v1/embeddings and /openai/v1/rerank for Voyage-style and Cohere-shaped APIs. Those are out of scope for the maintainer's review here — happy to add them in a follow-up PR if useful (this PR is already a chat-only driver, matching what your screenshot tested).
Cross-applying the lessons from the merged infiniflow#14790 sample driver and from the maintainer's reviews on infiniflow#14809 and infiniflow#14850: conf/models/voyage.json: - name: "VoyageAI" -> "Voyage" (the maintainer's "remove AI suffix" guidance from infiniflow#14850). - baseURL: "https://api.voyageai.com/v1" -> "https://api.voyageai.com" (bare URL; version moves into the suffix), matching the pattern used on Novita and the Cohere sample (api.cohere.com + v2/chat, v1/models). - url_suffix.embedding: "embeddings" -> "v1/embeddings". - url_suffix.rerank: "rerank" -> "v1/rerank". internal/entity/models/voyage.go: - Embed: forward EmbeddingConfig.Dimension as Voyage's documented `output_dimension` body field. This is the singular spelling per https://docs.voyageai.com/reference/embeddings-api ; Voyage rejects unknown fields with HTTP 400 (live-verified — sending "dimensions" returns "Argument 'dimensions' is not supported by our API"), so matching the docs spelling exactly is load-bearing. Live test against voyage-3.5 with output_dimension=256 trims the vector from the default 1024 to 256. internal/entity/models/voyage_test.go: - New: TestVoyageEmbedPropagatesOutputDimension pins the wire field name and guards against re-adding "dimensions" / "dimension". - New: TestVoyageEmbedOmitsOutputDimensionWhenUnset — Voyage 400s on output_dimension: 0, so the key must be absent when Dimension is unset rather than sent as zero. - All existing path-asserting tests updated to expect the new versioned suffixes (/v1/embeddings, /v1/rerank).
Per infiniflow#14809 (review): conf/models/longcat.json — move `openai` from base URL into the chat suffix. The platform docs at https://longcat.chat/platform/docs/APIDocs.html#endpoints publish the base host as `https://api.longcat.chat` and the full chat URL as `https://api.longcat.chat/openai/v1/chat/completions`, so the `/openai` prefix belongs in `url_suffix.chat`, not in `url.default`. Matches the same split the maintainer asked for on Novita (infiniflow#14850). internal/entity/models/longcat.go: - Drop the hardcoded `longcatKnownModels` catalog and the `longcatPingModel` constant. Maintainer flagged "no hard code" and noted "there is no need to implement the interface that is not officially given." The LongCat platform does not publish a /models endpoint, so synthesizing a catalog in the driver is wrong; the shipped catalog in conf/models/longcat.json is sufficient. - ListModels returns the documented `"<name>, no such method"` sentinel (the convention every other driver in this package uses for unsupported interface methods, including the merged Cohere sample in infiniflow#14790). - CheckConnection also returns the sentinel. The previous chat-ping implementation would have burned a real completion against a tenant's quota; with no documented /models or /health endpoint there is no cheap way to verify the key, so pretending is worse than declining. internal/entity/models/longcat_test.go: - Update path expectations: `/v1/chat/completions` -> `/openai/v1/chat/completions` in the test helper and in every test using newLongCatServer / newLongCatSSEServer. - Replace TestLongCatListModelsReturnsKnownCatalog, TestLongCatListModelsRequiresAPIKey, TestLongCatListModelsRejectsUnknownRegion, TestLongCatCheckConnectionChatPings, and TestLongCatCheckConnectionPropagatesAuthError with two new tests pinning the "no such method" sentinel for both stubs. Live re-verified end-to-end against api.longcat.chat: chat reply "Pong!" via the new URL split.
Haruko386
left a comment
There was a problem hiding this comment.
@tmimmanuel LGTM
Thank you for your contribution
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14850 +/- ##
==========================================
- 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:
|
Per infiniflow#14850 (review) maintainer review on commit 3faf24e: Endpoints (conf/models/novita.json): - Provider name "NovitaAI" -> "Novita" (matches the platform name). - baseURL "https://api.novita.ai/v3/openai" -> "https://api.novita.ai". The /v3/openai prefix was a leftover; the canonical OpenAI-style surface is mounted at /openai under api.novita.ai. - url_suffix.chat "chat/completions" -> "openai/v1/chat/completions" (the path listed in https://novita.ai/docs/api-reference/model-apis-llm-create-chat-completion). - url_suffix.models "models" -> "openai/v1/models" (matches the path shown in the docs at platform/docs/.../model-apis-llm-list-models; the maintainer's suggested "v1/models" 404s live, but the docs page itself clearly shows the openai-prefixed form). ListModels (novita.go): - Add the missing `Content-Type: application/json` header on the GET request. The maintainer flagged this on the original line 536. enable_thinking (novita.go): - Map ChatConfig.Thinking *bool -> Novita's documented `enable_thinking` body field on both ChatWithMessages and ChatStreamlyWithSender. Previously there was no way for a tenant to disable thinking mode without editing the user prompt. - Per Novita docs the supported models are zai-org/glm-4.5, deepseek/deepseek-v3.1[-terminus|-exp]; live-confirmed the toggle also flips qwen3-* deployments out of <think> mode. reasoning_content shape (novita.go): - Live audit of api.novita.ai showed that the chain-of-thought arrives in two different wire shapes depending on the model: qwen3-* embeds it inline as <think>...</think> in content, while deepseek-v3.1 / glm-4.5 with thinking on put it in a separate `reasoning_content` field on the message and stream deltas (66 reasoning_content chunks in a single deepseek-v3.1 stream). The driver now handles both: the non-stream path merges reasoning_content into ChatResponse.ReasonContent alongside the inline-tag split, and the stream path emits delta.reasoning_content to the sender's second arg before processing delta.content. Tests (novita_test.go): - newNovitaServer now asserts Content-Type on GET as well as POST so the ListModels header is exercised, and accepts any prefix of "application/json" (e.g. with `; charset=utf-8`). - New newNovitaSSEServer helper applies the same wire-contract assertions (POST + path + auth + Content-Type) to the streaming tests, closing the CodeRabbit gap on `296-312` and `348-356`. - New tests pinning the new behaviour: TestNovitaChatExtractsReasoningContentField TestNovitaStreamExtractsDeltaReasoningContent TestNovitaChatPropagatesEnableThinking (enabled/disabled) TestNovitaChatOmitsEnableThinkingWhenUnset TestNovitaStreamPropagatesEnableThinking
Cross-applying the lessons from the merged infiniflow#14790 sample driver and from the maintainer's reviews on infiniflow#14809 and infiniflow#14850: conf/models/voyage.json: - name: "VoyageAI" -> "Voyage" (the maintainer's "remove AI suffix" guidance from infiniflow#14850). - baseURL: "https://api.voyageai.com/v1" -> "https://api.voyageai.com" (bare URL; version moves into the suffix), matching the pattern used on Novita and the Cohere sample (api.cohere.com + v2/chat, v1/models). - url_suffix.embedding: "embeddings" -> "v1/embeddings". - url_suffix.rerank: "rerank" -> "v1/rerank". internal/entity/models/voyage.go: - Embed: forward EmbeddingConfig.Dimension as Voyage's documented `output_dimension` body field. This is the singular spelling per https://docs.voyageai.com/reference/embeddings-api ; Voyage rejects unknown fields with HTTP 400 (live-verified — sending "dimensions" returns "Argument 'dimensions' is not supported by our API"), so matching the docs spelling exactly is load-bearing. Live test against voyage-3.5 with output_dimension=256 trims the vector from the default 1024 to 256. internal/entity/models/voyage_test.go: - New: TestVoyageEmbedPropagatesOutputDimension pins the wire field name and guards against re-adding "dimensions" / "dimension". - New: TestVoyageEmbedOmitsOutputDimensionWhenUnset — Voyage 400s on output_dimension: 0, so the key must be absent when Dimension is unset rather than sent as zero. - All existing path-asserting tests updated to expect the new versioned suffixes (/v1/embeddings, /v1/rerank).
Per infiniflow#14809 (review): conf/models/longcat.json — move `openai` from base URL into the chat suffix. The platform docs at https://longcat.chat/platform/docs/APIDocs.html#endpoints publish the base host as `https://api.longcat.chat` and the full chat URL as `https://api.longcat.chat/openai/v1/chat/completions`, so the `/openai` prefix belongs in `url_suffix.chat`, not in `url.default`. Matches the same split the maintainer asked for on Novita (infiniflow#14850). internal/entity/models/longcat.go: - Drop the hardcoded `longcatKnownModels` catalog and the `longcatPingModel` constant. Maintainer flagged "no hard code" and noted "there is no need to implement the interface that is not officially given." The LongCat platform does not publish a /models endpoint, so synthesizing a catalog in the driver is wrong; the shipped catalog in conf/models/longcat.json is sufficient. - ListModels returns the documented `"<name>, no such method"` sentinel (the convention every other driver in this package uses for unsupported interface methods, including the merged Cohere sample in infiniflow#14790). - CheckConnection also returns the sentinel. The previous chat-ping implementation would have burned a real completion against a tenant's quota; with no documented /models or /health endpoint there is no cheap way to verify the key, so pretending is worse than declining. internal/entity/models/longcat_test.go: - Update path expectations: `/v1/chat/completions` -> `/openai/v1/chat/completions` in the test helper and in every test using newLongCatServer / newLongCatSSEServer. - Replace TestLongCatListModelsReturnsKnownCatalog, TestLongCatListModelsRequiresAPIKey, TestLongCatListModelsRejectsUnknownRegion, TestLongCatCheckConnectionChatPings, and TestLongCatCheckConnectionPropagatesAuthError with two new tests pinning the "no such method" sentinel for both stubs. Live re-verified end-to-end against api.longcat.chat: chat reply "Pong!" via the new URL split.
### What problem does this PR solve? Fixes #14893 The Novita Go driver landed in #14850 and shipped a stub `Embed` method that returned `"novita, no such method"`, so Novita could not be used as an embedding provider in RAGFlow. This PR fills that gap. Novita exposes a public embeddings endpoint at `POST https://api.novita.ai/v3/embeddings` that accepts the standard OpenAI-compatible request shape (`{model, input}`) with `Authorization: Bearer <api_key>`. Two embedding models are documented in Novita's model library: `baai/bge-m3` (multilingual, 8192 tokens) and `baai/bge-large-en-v1.5`. ### Changes - `internal/entity/models/novita.go`: implement `NovitaModel.Embed`. - Validate inputs (api key, model name) and short-circuit on empty texts. - Resolve region with the existing `baseURLForRegion` helper. - Build URL from `URLSuffix.Embedding` (the embeddings path lives under `/v3/`, separate from the chat path under `/openai/v1/`). - Send `{model, input}` POST body, add `dimensions` when `embeddingConfig.Dimension > 0` (matches the pattern in #14735). - Bearer auth + JSON content type, mirroring the chat path. - Parse `{data: [{embedding, index}]}` and reorder by `index`, rejecting out-of-range indices, duplicates, and missing entries so the output always lines up with the input. Same shape as the merged Mistral and Upstage Embed implementations. - `conf/models/novita.json`: - Add `"embedding": "v3/embeddings"` to `url_suffix`. - Add default embedding model entries for `baai/bge-m3` and `baai/bge-large-en-v1.5` so they appear in the model picker. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Jin Hai <[email protected]>
Add a Go driver for n1n.ai (https://docs.n1n.ai), one of the unchecked providers on the umbrella tracking issue infiniflow#14736. n1n.ai is an OpenAI-compatible aggregator that exposes a 450+ model catalog (GPT, Claude, Gemini, DeepSeek, Kimi, Qwen, embedding + reranker families) under https://api.n1n.ai/v1. ModelDriver coverage maps directly to documented endpoints: ChatWithMessages POST /v1/chat/completions ChatStreamlyWithSender POST /v1/chat/completions (SSE, [DONE]) Embed POST /v1/embeddings Rerank POST /v1/rerank ListModels GET /v1/models CheckConnection delegates to ListModels Everything else (Balance, TranscribeAudio, AudioSpeech, OCRFile, ParseFile, ListTasks, ShowTask) returns "n1n, no such method" — the n1n.ai docs list /v1/audio/* and /v1/contents/generations/tasks endpoints but they involve multipart upload / binary response / async job orchestration and are deferred to a follow-up. Per the maintainer's guidance on infiniflow#14809 review #4277917390, the driver only implements interface methods backed by JSON surfaces that the docs publish. URL split follows the same convention the maintainer asked for on Novita (infiniflow#14850) and LongCat (infiniflow#14809): url.default = "https://api.n1n.ai" url_suffix.chat = "v1/chat/completions" etc. Shipped catalog in conf/models/n1n.json is a representative 12-model subset (chat + embedding + rerank); the full live catalog is reachable via ListModels.
### What problem does this PR solve? Fixes #15012 The Novita Go driver landed in #14850 and shipped a stub `Rerank` method that returned `"novita, no such method"`, so Novita could not be used as a rerank provider in RAGFlow. This PR fills that gap, in the same way #14895 filled the Embed gap on the same driver. Novita exposes a public rerank endpoint at `POST https://api.novita.ai/openai/v1/rerank` that accepts the Cohere-compatible request shape (`{model, query, documents, top_n}`) with `Authorization: Bearer <api_key>`. `baai/bge-reranker-v2-m3` is documented in Novita's model library with a 1024-token limit.
### What problem does this PR solve? Add a Go driver for Novita.ai (https://novita.ai), one of the unchecked providers on the umbrella tracking issue infiniflow#14736. Novita exposes an OpenAI-compatible REST API at `https://api.novita.ai/v3/openai` and proxies a large catalog of third-party models (DeepSeek, Llama, Qwen3, Kimi, Gemma, Mistral, MiniMax, GLM, etc.) behind a single OpenAI-shaped surface — 102 models live at the time of writing. Until this PR, a tenant who configured `novita` 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. ### What this PR includes - New `internal/entity/models/novita.go` with a `NovitaModel` implementing the `ModelDriver` interface (~520 lines). - New `conf/models/novita.json` with 7 representative chat models (DeepSeek-V4, Llama-3.3-70B, Qwen3-30B/235B reasoning, Kimi-K2, Gemma-3-27B, Mistral-Nemo). - `factory.go`: route `"novita"` to `NewNovitaModel`. - `internal/entity/models/novita_test.go`: 23 unit tests. ### Notable design point: `<think>...</think>` reasoning extraction Novita-routed reasoning models like `qwen3-*` and `deepseek-r1-*` embed their chain-of-thought **inline inside content as `<think>...</think>` tags**, rather than in a separate `reasoning_content` field. Verified live by probing `api.novita.ai`: ``` content head 200: <think> Okay, let's see. I need to find 15% of 80. Hmm, percentages can sometimes be tricky, but I think content tail 100: h, that works. Alternatively, 0.15 × 80. If I move the decimal two places to the left for </think> ``` Without handling, a tenant picking qwen3 via Novita would see raw `<think>` tags in their UI answer — different from every other reasoning provider in the Go layer. The driver detects those tags and routes the inner text to `ChatResponse.ReasonContent` (non-stream) or the sender's second arg (stream), keeping the visible answer clean of tag clutter: - **`splitNovitaThink`** — scans a complete content string. Used by the non-streaming path. Handles multiple `<think>` blocks, unclosed tags (the model got cut off mid-reasoning), pure-text content with no tags. - **`novitaThinkExtractor`** — stateful streaming version. Buffers trailing bytes that might be the start of a tag (e.g. `<thi` held back when the next chunk completes `nk>`), then emits segments in routing order so callers can pipe them to a UI. Tested with byte-level chunk boundaries and tag-spanning scenarios. ### Method coverage | Method | Behavior | |---|---| | `ChatWithMessages` | `POST /v3/openai/chat/completions`, `<think>` extraction on response | | `ChatStreamlyWithSender` | SSE stream, stateful `<think>` extraction across deltas | | `ListModels` / `CheckConnection` | `GET /v3/openai/models` (102 live) | | `Embed` / `Rerank` / `Balance` / `TranscribeAudio` / `AudioSpeech` / `OCRFile` | `"no such method"` — Novita's OpenAI-compatible surface does not expose any | No interface change. No new dependencies. ### How was this tested? **23 unit tests** in `internal/entity/models/novita_test.go` — all pass: ``` $ go test -vet=off -run "TestNovita|TestSplitNovita" -count=1 ./internal/entity/models/... ok ragflow/internal/entity/models 0.020s ``` Coverage: - `splitNovitaThink` (5 cases: pure text, single block, leading text, multiple blocks, unclosed tag) - `novitaThinkExtractor` (6 cases: single-chunk, opening tag span, closing tag span, byte-level chunking, no tags, lone `<` not as tag start) - `ChatWithMessages`: pure text, with `<think>` tags, missing API key, empty messages, HTTP error - `ChatStreamlyWithSender`: tag-stripping with spanning deltas, pure content, sender-required, stream-true-required - `ListModels` / `CheckConnection` (happy paths) - All sentinel methods `go build ./internal/entity/models/...` exits 0 on go 1.25. **Live integration test** against `api.novita.ai/v3/openai`: ``` === RUN TestNovitaLiveSmoke [OK] Name() = "novita" [OK] CheckConnection [OK] ListModels: 102 models (showing first 6) [deepseek/deepseek-v4-pro deepseek/deepseek-v4-flash deepseek/deepseek-v3.2 xiaomimimo/mimo-v2.5-pro moonshotai/kimi-k2.6 zai-org/glm-5.1] [OK] Chat (llama-3.3) answer="ok" reason="" [OK] Chat (qwen3) answer len=0 head="" ReasonContent len=1657 head="Okay, so I need to figure out what 15% of 80 is. Hmm, percentages can sometimes trip me up, but let ..." [OK] Stream content: 0 chunks, 0 chars; reasoning: 600 chunks, 1667 chars [OK] Embed/Rerank/Balance/TranscribeAudio/AudioSpeech/OCRFile all return "novita, no such method" NOVITA LIVE SMOKE PASSED --- PASS: TestNovitaLiveSmoke (26.18s) ``` What the live run proves on the wire: - Auth (`Bearer <key>`) accepted by `api.novita.ai`. - `/v3/openai/models` parser handles the real 102-model response. - Non-stream chat against `meta-llama/llama-3.3-70b-instruct`: clean string answer, empty ReasonContent (non-reasoning model, pure-text path). - Non-stream chat against `qwen/qwen3-30b-a3b-fp8`: 1657-char reasoning extracted from `<think>...</think>` and routed to `ChatResponse.ReasonContent`. Visible answer is 0 chars in this run because qwen3 spent its 600-token budget entirely on reasoning before reaching the answer phase — that's the model's behavior, not a driver bug. The important thing: **no `<think>` tags leaked into the visible Answer field**. - Streaming against qwen3: 600 reasoning chunks (1667 chars) emitted via the sender's 2nd arg across SSE deltas; **no `<think>` tag fragments leaked into the content channel** despite tag boundaries crossing chunk boundaries on the wire. - All 6 sentinel methods return the documented `"no such method"` strings. ### Type of change - [x] New Feature (non-breaking change which adds functionality) Tracking: infiniflow#14736
What problem does this PR solve?
Add a Go driver for Novita.ai (https://novita.ai), one of the unchecked providers on the umbrella tracking issue #14736. Novita exposes an OpenAI-compatible REST API at
https://api.novita.ai/v3/openaiand proxies a large catalog of third-party models (DeepSeek, Llama, Qwen3, Kimi, Gemma, Mistral, MiniMax, GLM, etc.) behind a single OpenAI-shaped surface — 102 models live at the time of writing.Until this PR, a tenant who configured
novitaas 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/novita.gowith aNovitaModelimplementing theModelDriverinterface (~520 lines).conf/models/novita.jsonwith 7 representative chat models (DeepSeek-V4, Llama-3.3-70B, Qwen3-30B/235B reasoning, Kimi-K2, Gemma-3-27B, Mistral-Nemo).factory.go: route"novita"toNewNovitaModel.internal/entity/models/novita_test.go: 23 unit tests.Notable design point:
<think>...</think>reasoning extractionNovita-routed reasoning models like
qwen3-*anddeepseek-r1-*embed their chain-of-thought inline inside content as<think>...</think>tags, rather than in a separatereasoning_contentfield. Verified live by probingapi.novita.ai:Without handling, a tenant picking qwen3 via Novita would see raw
<think>tags in their UI answer — different from every other reasoning provider in the Go layer.The driver detects those tags and routes the inner text to
ChatResponse.ReasonContent(non-stream) or the sender's second arg (stream), keeping the visible answer clean of tag clutter:splitNovitaThink— scans a complete content string. Used by the non-streaming path. Handles multiple<think>blocks, unclosed tags (the model got cut off mid-reasoning), pure-text content with no tags.novitaThinkExtractor— stateful streaming version. Buffers trailing bytes that might be the start of a tag (e.g.<thiheld back when the next chunk completesnk>), then emits segments in routing order so callers can pipe them to a UI. Tested with byte-level chunk boundaries and tag-spanning scenarios.Method coverage
ChatWithMessagesPOST /v3/openai/chat/completions,<think>extraction on responseChatStreamlyWithSender<think>extraction across deltasListModels/CheckConnectionGET /v3/openai/models(102 live)Embed/Rerank/Balance/TranscribeAudio/AudioSpeech/OCRFile"no such method"— Novita's OpenAI-compatible surface does not expose anyNo interface change. No new dependencies.
How was this tested?
23 unit tests in
internal/entity/models/novita_test.go— all pass:Coverage:
splitNovitaThink(5 cases: pure text, single block, leading text, multiple blocks, unclosed tag)novitaThinkExtractor(6 cases: single-chunk, opening tag span, closing tag span, byte-level chunking, no tags, lone<not as tag start)ChatWithMessages: pure text, with<think>tags, missing API key, empty messages, HTTP errorChatStreamlyWithSender: tag-stripping with spanning deltas, pure content, sender-required, stream-true-requiredListModels/CheckConnection(happy paths)go build ./internal/entity/models/...exits 0 on go 1.25.Live integration test against
api.novita.ai/v3/openai:What the live run proves on the wire:
Bearer <key>) accepted byapi.novita.ai./v3/openai/modelsparser handles the real 102-model response.meta-llama/llama-3.3-70b-instruct: clean string answer, empty ReasonContent (non-reasoning model, pure-text path).qwen/qwen3-30b-a3b-fp8: 1657-char reasoning extracted from<think>...</think>and routed toChatResponse.ReasonContent. Visible answer is 0 chars in this run because qwen3 spent its 600-token budget entirely on reasoning before reaching the answer phase — that's the model's behavior, not a driver bug. The important thing: no<think>tags leaked into the visible Answer field.<think>tag fragments leaked into the content channel despite tag boundaries crossing chunk boundaries on the wire."no such method"strings.Type of change
Tracking: #14736