Repository navigation
fix(go-models): harden JieKouAI driver requests - #15337
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughCentralized API-key and model-name validation across JieKouAI methods; updated chat (streaming and non-streaming), embed, rerank, and ListModels to use validated values in headers and bodies, removed per-line SSE logging and config-level stream overrides, and added comprehensive integration and validation tests. ChangesJieKouAI Provider Input Validation and Request Hardening
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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/jiekouai.go`:
- Around line 468-478: The current code always serializes "top_n": topN even
when rerankConfig is nil or TopN==0, sending an unintended 0; change
construction of reqBody so you only add the "top_n" key when rerankConfig != nil
&& rerankConfig.TopN != 0 (i.e., compute topN as you do, build reqBody with
model/query/documents first, then conditionally set reqBody["top_n"] = topN) so
the key is omitted unless explicitly provided.
🪄 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: 33092582-29f0-4146-be7d-08137eb36a88
📒 Files selected for processing (2)
internal/entity/models/jiekouai.gointernal/entity/models/jiekouai_test.go
|
@Haruko386 @JinHai-CN ready for review when you have a moment - thank you |
Thank you @Haruko386 - I think my other PR was marked approved but never merged from 2 days ago as well, very similar focus (driver improvements) - mind taking a look? #15249 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15337 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ot dropped (#15382) ### Summary Closes #15381 Every provider in `internal/entity/models/` reads its streaming response with `bufio.NewScanner(resp.Body)` and iterates over `scanner.Scan()`. The default `bufio.Scanner` maximum token size is 64KB, so when an upstream sends a single SSE `data:` line larger than 64KB (long content deltas, large tool or function call argument blobs, bundled `reasoning_content`, or providers that emit a whole message in one event) `scanner.Scan()` returns `false` and `scanner.Err()` returns `bufio.ErrTooLong`. Streaming chat then ends with an error partway through the response. This change adds `scanner.Buffer(make([]byte, 64*1024), 1024*1024)` immediately after every SSE scanner that was still bare, raising the cap to 1MB. 1MB is the value already used for streaming chat in `openai.go`, `modelscope.go`, `groq.go`, `mistral.go`, `xai.go` and the other already patched providers (the 8MB cap in the repo is reserved for TTS and embedding paths), so this simply converges the remaining providers onto the established pattern. Nothing else changes: line parsing, `data:` prefix handling, `[DONE]` detection, JSON unmarshalling, error handling, and the existing `scanner.Err()` checks all stay the same. Providers covered (23 scanners across 22 files): 302ai, aliyun, baichuan, baidu, cohere, deepinfra, deepseek, gitee, huggingface, lmstudio, minimax (the chat scanner, whose TTS scanner was already bumped), moonshot, nvidia, ollama, openrouter, orcarouter, paddleocr, siliconflow, tokenhub, vllm, volcengine, xunfei, zhipu-ai. `jiekouai.go` is excluded because it is covered by the in flight #15337. A table driven regression test (`sse_scanner_buffer_test.go`) streams a single 128KB `data:` content delta followed by `data: [DONE]` through an `httptest` server and asserts that `ChatStreamlyWithSender` delivers the full content with no error across a representative subset of providers. Without the buffer fix the test fails with `bufio.Scanner: token too long`. This PR also removes three duplicate declarations of the package level `roundTripperFunc` test helper that several recently merged provider PRs each added independently, which had left the `internal/entity/models` test package unable to compile. The helper now lives in a single place and is shared. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
Summary
What changed
ListModelsresponse assertions with typed parsing and validationWhy
JieKouAI follows the same OpenAI-compatible request shape as the related 302.AI provider, but its Go driver still accepted invalid local inputs, allowed callers to flip stream mode on the wrong method, sent a body with
GET /models, logged raw SSE payloads, and could panic on malformed model-list responses.Closes #14736
Validation
go test ./internal/entity/models -run TestJieKouAI -count=1git diff --checkNotes
go test ./internal/entity/models -count=1is currently blocked by an unrelated upstream Astraflow test panic inTestAstraflowEmbedReturnsNoSuchMethod.