Repository navigation
fix: add legacy chat/completions mode - #16014
Conversation
📝 WalkthroughWalkthrough
ChangesLegacy SSE streaming mode with answer field handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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.
🧹 Nitpick comments (1)
api/apps/restful_apis/chat_api.py (1)
1232-1236: ⚡ Quick winAdd logging when legacy mode is activated.
Per coding guidelines, new flows should include logging. When
legacy=Trueis requested, log this at info/debug level to aid debugging and monitoring of legacy mode usage.legacy = _get_bool_request_flag( req, "legacy", default=False, ) + if legacy: + logging.debug("Legacy streaming mode enabled for chat completion") stream_mode = req.pop("stream", 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 `@api/apps/restful_apis/chat_api.py` around lines 1232 - 1236, After the legacy variable is assigned by the _get_bool_request_flag call, add a logging statement that checks if legacy is True and logs an info or debug level message indicating that legacy mode has been activated. This will provide visibility into when legacy mode is being used for debugging and monitoring purposes.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@api/apps/restful_apis/chat_api.py`:
- Around line 1232-1236: After the legacy variable is assigned by the
_get_bool_request_flag call, add a logging statement that checks if legacy is
True and logs an info or debug level message indicating that legacy mode has
been activated. This will provide visibility into when legacy mode is being used
for debugging and monitoring purposes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fcc376f6-684c-41a5-b709-ac0b0abea57c
📒 Files selected for processing (1)
api/apps/restful_apis/chat_api.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16014 +/- ##
=======================================
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 Harness. 🚀 New features to boost your workflow:
|
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 `@api/db/services/dialog_service.py`:
- Line 903: The clearing of the answer field (setting `final["answer"] = ""`) in
the shared service layer of `async_ask` in dialog_service.py affects all
streaming consumers, not just the legacy endpoint, causing non-legacy clients to
receive empty answers. Remove the `final["answer"] = ""` assignment from the
shared service layer in dialog_service.py at line 903, and also at line 1719
where it similarly applies. Then move this clearing/fallback logic into the
legacy endpoint branch in the restful API layer (the
`/chat/completions?legacy=true` endpoint), and have that legacy branch
explicitly emit `legacy_answer` for its final chunk instead of depending on the
shared service to blank the answer.
🪄 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: c3c5b0ae-f96c-4ed5-8ff0-64edab27312e
📒 Files selected for processing (1)
api/db/services/dialog_service.py
| final = await decorate_answer(_extract_visible_answer(thought + full_answer)) | ||
| final["final"] = True | ||
| final["audio_binary"] = None | ||
| final["answer"] = "" |
There was a problem hiding this comment.
Keep legacy response shaping out of the shared service layer.
Both changes discard the fully decorated final answer for every streaming consumer, not just /chat/completions?legacy=true. async_ask is forwarded directly by api/apps/restful_apis/bot_api.py and api/apps/restful_apis/search_api.py, and non-legacy session_completion also streams formatted chunks unchanged, so clients that rely on the final event now receive answer: "".
Move the clearing/fallback behavior into the legacy endpoint branch instead, and keep these service payloads complete.
Suggested service-side rollback
final = await decorate_answer(_extract_visible_answer(thought + full_answer))
final["final"] = True
final["audio_binary"] = None
-final["answer"] = ""
yield final final = await decorate_answer(_extract_visible_answer(full_answer))
final["final"] = True
-final["answer"] = ""
yield finalThen have the legacy /chat/completions branch emit legacy_answer explicitly for its final chunk rather than depending on shared services to blank the answer.
Also applies to: 1719-1719
🤖 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 `@api/db/services/dialog_service.py` at line 903, The clearing of the answer
field (setting `final["answer"] = ""`) in the shared service layer of
`async_ask` in dialog_service.py affects all streaming consumers, not just the
legacy endpoint, causing non-legacy clients to receive empty answers. Remove the
`final["answer"] = ""` assignment from the shared service layer in
dialog_service.py at line 903, and also at line 1719 where it similarly applies.
Then move this clearing/fallback logic into the legacy endpoint branch in the
restful API layer (the `/chat/completions?legacy=true` endpoint), and have that
legacy branch explicitly emit `legacy_answer` for its final chunk instead of
depending on the shared service to blank the answer.
### What problem does this PR solve? Adds a legacy mode for /chat/completions that restores v0.23.0-style output by converting start_to_think/end_to_think back into raw <think></think> markers and streaming cumulative answer text. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
What problem does this PR solve?
Adds a legacy mode for /chat/completions that restores v0.23.0-style output by converting start_to_think/end_to_think back into raw markers and streaming cumulative answer text.
Type of change