Repository navigation
Go: implement provider: Avian - #15045
Conversation
Closes infiniflow#15044. Avian was listed unchecked in the Go-rewrite tracker infiniflow#14736 and already had an llm_factories.json entry with 4 preconfigured chat models (deepseek-v3.2, kimi-k2.5, glm-5, minimax-m2.5), but the Go API server had no driver to route them. The Python side has supported Avian at rag/llm/chat_model.py:1220 (AvianChat) via the LiteLLM openai/ provider with default base https://api.avian.io/v1. This adds: - internal/entity/models/avian.go: SaaS OpenAI-compatible driver with chat (sync + SSE stream with avianStreamTimeout=10m), list_models, and check_connection. Always-on Bearer auth (validated up front). Reasoning extraction prefers reasoning_content and falls back to reasoning. Mirrors the TogetherAI pattern (infiniflow#14957). - internal/entity/models/avian_test.go: 13 tests covering name, factory routing, chat happy path / reasoning fallback / API-key required / messages required / upstream-error status propagation, stream happy path / stream=false rejection / sender required, list_models + check_connection, missing-base-URL clear error, and the no-such-method sentinels. - conf/models/avian.json: shipped config (class: "avian", default URL https://api.avian.io, suffixes v1/chat/completions and v1/models, and the 4 chat models from llm_factories.json:6733). - internal/entity/models/factory.go: case "avian" -> AvianModel. No change to selfDeployed map: Avian is SaaS, not self-hosted, so availability gates on the user supplying an API key (matches Novita, TogetherAI, Replicate, etc.). Follow-on issues will add Embed and Rerank, in line with how Novita, NVIDIA, TogetherAI, and other providers landed method-by-method.
|
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 Avian provider JSON config and a new Go AvianModel driver implementing synchronous chat, SSE streaming, ListModels/CheckConnection, factory registration, and comprehensive unit tests. ChangesAvian Chat Provider Integration
Sequence DiagramsequenceDiagram
participant Client
participant AvianModel
participant AvianAPI
Client->>AvianModel: ChatWithMessages / ChatStreamlyWithSender (model, messages, stream)
AvianModel->>AvianAPI: HTTP POST /v1/chat/completions (Authorization: Bearer key)
AvianAPI-->>AvianModel: JSON response (choices) OR text/event-stream (data: JSON chunks, [DONE])
AvianModel-->>Client: ChatResponse (sync) OR sender callbacks with content/reasoning deltas (stream)
Client->>AvianModel: ListModels / CheckConnection (GET /v1/models)
AvianModel->>AvianAPI: HTTP GET /v1/models (Authorization)
AvianAPI-->>AvianModel: JSON model list
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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: 3
🧹 Nitpick comments (1)
internal/entity/models/avian_test.go (1)
78-126: ⚡ Quick winConsider validating all request parameters in test handler.
The test passes
topP: 0.9andstop: []string{"END"}(lines 109-110) but the handler only validatesmax_tokensandtemperature(lines 89-94). For more comprehensive validation, consider checking thattop_pandstopare correctly included in the request body.Suggested enhancement
if body["temperature"] != 0.3 { t.Errorf("temperature=%v, want 0.3", body["temperature"]) } + if body["top_p"] != 0.9 { + t.Errorf("top_p=%v, want 0.9", body["top_p"]) + } + if stopSlice, ok := body["stop"].([]interface{}); !ok || len(stopSlice) != 1 || stopSlice[0] != "END" { + t.Errorf("stop=%v, want [END]", body["stop"]) + } _ = json.NewEncoder(w).Encode(map[string]interface{}{🤖 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/avian_test.go` around lines 78 - 126, The test handler inside newAvianServer (the anonymous func used in TestAvianChatHappyPath) currently verifies model, stream, max_tokens and temperature but not top_p or stop; update that handler to also assert body["top_p"] == 0.9 (float64) and that body["stop"] is a slice containing the string "END" (body["stop"] will be a []interface{} so check its length and element string value) so the request built by ChatWithMessages (called below with TopP and Stop) is fully validated.
🤖 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/avian_test.go`:
- Around line 35-38: Add a brief inline comment above the Content-Type check
(the r.Header.Get("Content-Type") validation in the test helper) explaining that
the Avian API intentionally sets "Content-Type: application/json" on GET
requests (see avian.go line 363) so this non-standard requirement applies even
for requests without a body; update the test helper comment near the
Content-Type assertion to state this intent so future maintainers understand why
the GET is validated for a JSON Content-Type.
In `@internal/entity/models/avian.go`:
- Around line 305-314: The streaming branch currently forwards both
choice.Delta.ReasoningContent and choice.Delta.Reasoning which duplicates
chunks; change the logic to mirror ChatWithMessages by preferring
reasoning_content and only falling back to reasoning when reasoning_content is
empty—i.e., inside the streaming handler where sender is called, send
choice.Delta.ReasoningContent if non-empty, else send choice.Delta.Reasoning,
and remove the second unconditional send; reference the symbols
choice.Delta.ReasoningContent, choice.Delta.Reasoning, sender and the
ChatWithMessages fallback behavior when making the change.
- Around line 81-90: The baseURLForRegion method should also normalize and
remove a trailing "/v1" (and any trailing slash) from tenant-supplied BaseURL
entries to avoid duplicating the API version in constructed paths; update
AvianModel.baseURLForRegion to trim an optional "/v1" suffix (e.g., remove "/v1"
or "/v1/") and then trim any remaining trailing "/" before returning the base so
callers that append "v1/..." won't produce "/v1/v1/...".
---
Nitpick comments:
In `@internal/entity/models/avian_test.go`:
- Around line 78-126: The test handler inside newAvianServer (the anonymous func
used in TestAvianChatHappyPath) currently verifies model, stream, max_tokens and
temperature but not top_p or stop; update that handler to also assert
body["top_p"] == 0.9 (float64) and that body["stop"] is a slice containing the
string "END" (body["stop"] will be a []interface{} so check its length and
element string value) so the request built by ChatWithMessages (called below
with TopP and Stop) is fully validated.
🪄 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: 6c55e1da-5791-4d40-82aa-f8d15a39b016
📒 Files selected for processing (4)
conf/models/avian.jsoninternal/entity/models/avian.gointernal/entity/models/avian_test.gointernal/entity/models/factory.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/entity/models/avian.go (1)
380-383:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix ListModels response parsing to handle OpenAI-compatible wrapper format.
The code unmarshals directly to
[]avianModelInfo, but Avian's/v1/modelsendpoint returns{"object": "list", "data": [...]}(matching OpenAI's format). This causes json.Unmarshal to fail at runtime because the response is an object, not an array.Add a wrapper struct and update the unmarshaling target:
Fix
+type avianModelsResponse struct { + Data []avianModelInfo `json:"data"` +} + func (a *AvianModel) ListModels(apiConfig *APIConfig) ([]string, error) { // ... existing code ... - var result []avianModelInfo + var result avianModelsResponse if err = json.Unmarshal(body, &result); err != nil { return nil, fmt.Errorf("failed to parse response: %w", err) } - models := make([]string, 0, len(result)) - for _, model := range result { + models := make([]string, 0, len(result.Data)) + for _, model := range result.Data { if model.ID != "" { models = append(models, model.ID) } }🤖 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/avian.go` around lines 380 - 383, The code currently unmarshals the /v1/models response directly into []avianModelInfo (variable result) but the API returns an OpenAI-style wrapper object {"object":"list","data":[...]} causing json.Unmarshal to fail; add a small wrapper type (e.g., type avianModelsList struct { Object string `json:"object"`; Data []avianModelInfo `json:"data"` }) and unmarshal into that in the ListModels flow, then set result = wrapper.Data (or return wrapper.Data) instead of unmarshaling directly into []avianModelInfo.
🤖 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.
Outside diff comments:
In `@internal/entity/models/avian.go`:
- Around line 380-383: The code currently unmarshals the /v1/models response
directly into []avianModelInfo (variable result) but the API returns an
OpenAI-style wrapper object {"object":"list","data":[...]} causing
json.Unmarshal to fail; add a small wrapper type (e.g., type avianModelsList
struct { Object string `json:"object"`; Data []avianModelInfo `json:"data"` })
and unmarshal into that in the ListModels flow, then set result = wrapper.Data
(or return wrapper.Data) instead of unmarshaling directly into []avianModelInfo.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c6bbbbc4-2775-4263-b5a6-1ec0f3262a6e
📒 Files selected for processing (2)
internal/entity/models/avian.gointernal/entity/models/avian_test.go
|
@dosu review this PR |
|
Hi @dripsmvcp! I'm Dosu and I’m helping the ragflow team. I appreciate the mention, but I don't perform traditional code reviews (assessing PRs for bugs, design, style, performance, or security). However, I can help in other ways:
Let me know if any of those would be useful! To reply, just mention @dosu. Share context across your team and agents. Try Dosu. |
|
PR #15045 adds the Avian LLM provider to RAGFlow's Go API server [1]. It's currently open and addresses issue #15044 (an item from the Go-rewrite tracker #14736). What it does: Implements an OpenAI-compatible SaaS driver for Avian (base URL Files added/modified:
Pattern: Mirrors the TogetherAI provider structure. Avian is SaaS (not self-deployed), so access is gated by the user supplying an API key [1]. As noted in my earlier comment, I don't perform traditional code reviews (assessing for bugs, design, style, or security). But I can research how other providers were implemented for comparison, answer specific questions about the codebase, or help with documentation if needed. To reply, just mention @dosu. Share context across your team and agents. Try Dosu. |
Haruko386
left a comment
There was a problem hiding this comment.
Hi @dripsmvcp, thank you for your contribution.
Two small changes will be ok.
| } | ||
| req.Header.Set("Content-Type", "application/json") | ||
| req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey)) | ||
| req.Header.Set("Accept", "text/event-stream") |
There was a problem hiding this comment.
no req.Header.Set("Accept", "text/event-stream")
delete it plz
| @@ -0,0 +1,41 @@ | |||
| { | |||
There was a problem hiding this comment.
would you mind add deekseek-v4-flash/pro ?
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15045 +/- ##
=======================================
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:
|
Closes #15044. Avian was listed unchecked in the Go-rewrite tracker #14736 and already had an llm_factories.json entry with 4 preconfigured chat models (deepseek-v3.2, kimi-k2.5, glm-5, minimax-m2.5), but the Go API server had no driver to route them. The Python side has supported Avian at rag/llm/chat_model.py:1220 (AvianChat) via the LiteLLM openai/ provider with default base https://api.avian.io/v1. Co-authored-by: Jin Hai <[email protected]>
Closes #15044.
Avian was listed unchecked in the Go-rewrite tracker #14736 and already had an llm_factories.json entry with 4 preconfigured chat models (deepseek-v3.2, kimi-k2.5, glm-5, minimax-m2.5), but the Go API server had no driver to route them. The Python side has supported Avian at rag/llm/chat_model.py:1220 (AvianChat) via the LiteLLM openai/ provider with default base https://api.avian.io/v1.
This adds:
No change to selfDeployed map: Avian is SaaS, not self-hosted, so availability gates on the user supplying an API key (matches Novita, TogetherAI, Replicate, etc.).
Follow-on issues will add Embed and Rerank, in line with how Novita, NVIDIA, TogetherAI, and other providers landed method-by-method.
What problem does this PR solve?
Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR.
Type of change