-
Notifications
You must be signed in to change notification settings - Fork 674
fix: multi-turn bug in should_add_generation_prompt #4168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ryan Lempka <[email protected]>
WalkthroughModified the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/llm/src/preprocessor/prompt/template/oai.rs (1)
726-748: LGTM! Comprehensive test coverage for the bug fix.The tests clearly validate the new behavior, particularly
add_after_toolwhich directly addresses the bug where Tool messages need a generation prompt.Consider adding tests for additional edge cases to further strengthen coverage:
- System message as the last message
- Multi-turn scenarios (e.g.,
vec![user(), asst(), tool()])Example:
#[test] fn add_after_system() { let sys = Msg::System(Default::default()); let s = dummy_state(vec![sys]); assert!(s.should_add_generation_prompt()); } #[test] fn add_after_multiturn_with_tool() { let s = dummy_state(vec![user(), asst(), tool()]); assert!(s.should_add_generation_prompt()); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/llm/src/preprocessor/prompt/template/oai.rs(3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: nachiketb-nvidia
Repo: ai-dynamo/dynamo PR: 2700
File: lib/llm/src/protocols/openai/chat_completions/delta.rs:19-28
Timestamp: 2025-08-25T22:04:45.205Z
Learning: The response_generator() method exists on multiple request types in the codebase: NvCreateChatCompletionRequest (for chat completions) and NvCreateCompletionRequest (for text completions). When making signature changes, it's important to distinguish between these different object types as they have separate implementations and call sites.
🧬 Code graph analysis (1)
lib/llm/src/preprocessor/prompt/template/oai.rs (1)
lib/llm/src/preprocessor/prompt.rs (2)
messages(51-51)should_add_generation_prompt(59-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: trtllm (amd64)
- GitHub Check: sglang (arm64)
- GitHub Check: sglang (amd64)
- GitHub Check: operator (amd64)
- GitHub Check: vllm (amd64)
- GitHub Check: Build and Test - dynamo
- GitHub Check: tests (lib/runtime/examples)
- GitHub Check: clippy (launch/dynamo-run)
- GitHub Check: tests (launch/dynamo-run)
- GitHub Check: clippy (lib/bindings/python)
- GitHub Check: tests (lib/bindings/python)
- GitHub Check: tests (.)
- GitHub Check: clippy (.)
🔇 Additional comments (3)
lib/llm/src/preprocessor/prompt/template/oai.rs (3)
165-177: LGTM! Fix correctly addresses the Tool message bug.The new logic properly handles the case where a Tool message is last—previously the generation prompt was only added for User messages, causing the model to leak header IDs when processing tool results. Now the prompt is added for any non-Assistant final message.
300-300: LGTM! Type alias improves test readability.
708-724: LGTM! Well-designed test helpers.The helper functions appropriately use
Default::default()sinceshould_add_generation_promptonly examines message type, not content.
Overview:
Add generation prompt unless the last message was
Assistant(_)(defaults to
truewhen no messages exist).Added unit tests and local test results here after change applied:
Details:
Change the behavior of
should_add_generation_promptto not simply check if the last message wasUser(_)but to check if the last message was notAssistant(_)and then return true in that case. This fixes issues such as those found in bug #4013 where the last message beingTool(_)caused the model to leak header ids into the return content.Where should the reviewer start?
lib/llm/src/preprocessor/prompt/template/oai.rs`#### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit
Bug Fixes
Tests