-
Notifications
You must be signed in to change notification settings - Fork 676
fix: deserialize tool call args #4176
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
Conversation
WalkthroughAdds a new helper function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 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 (2)
lib/llm/src/preprocessor/prompt/template/oai.rs (2)
124-156: LGTM! Clean implementation with solid error handling.The function correctly normalizes JSON string arguments into parsed objects for both current (
tool_calls) and legacy (function_call) formats. The graceful handling of malformed JSON (leaving it unchanged) aligns with the PR objectives.Minor style suggestion: The
Result::Okpattern can be simplified to justOk:- if let Result::Ok(parsed) = serde_json::from_str(s) { + if let Ok(parsed) = serde_json::from_str(s) { *args = parsed; }Apply the same simplification at line 149.
740-847: Good test coverage for the primary scenarios.The tests validate the key behaviors: prevention of double-encoding, support for iteration, legacy format handling, and malformed JSON passthrough. The order-insensitive assertion at line 804 is a nice touch.
Consider adding a few edge-case tests to strengthen coverage:
- Arguments already parsed (not strings): Verify that arguments already in object form are left unchanged.
- Multiple tool_calls per message: Ensure all tool calls in a single message are normalized.
- Array-type arguments: Test with
"arguments": "[1,2,3]"to confirm array deserialization works.Example test for case 1:
#[test] fn test_normalize_tool_arguments_already_object() { let mut messages = serde_json::Value::Array(vec![serde_json::json!({ "role": "assistant", "tool_calls": [{ "type": "function", "function": { "name": "f", "arguments": {"key": "value"} // Already an object } }] })]); normalize_tool_arguments_in_messages(&mut messages); // Should remain unchanged assert_eq!( messages[0]["tool_calls"][0]["function"]["arguments"], serde_json::json!({"key": "value"}) ); }
📜 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(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/llm/src/preprocessor/prompt/template/oai.rs (2)
lib/llm/src/preprocessor/prompt.rs (2)
messages(51-51)model(50-50)lib/llm/src/preprocessor/prompt/template/tokcfg.rs (1)
tojson(114-146)
⏰ 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). (12)
- GitHub Check: sglang (amd64)
- GitHub Check: operator (amd64)
- GitHub Check: vllm (arm64)
- GitHub Check: vllm (amd64)
- GitHub Check: Build and Test - dynamo
- GitHub Check: tests (launch/dynamo-run)
- GitHub Check: clippy (lib/bindings/python)
- GitHub Check: tests (lib/runtime/examples)
- GitHub Check: tests (lib/bindings/python)
- GitHub Check: tests (.)
- GitHub Check: clippy (launch/dynamo-run)
- GitHub Check: clippy (.)
🔇 Additional comments (1)
lib/llm/src/preprocessor/prompt/template/oai.rs (1)
163-180: Integration looks correct.The normalization is properly positioned: after serialization and before template rendering. The unconditional application matches the PR objectives, and the order of operations with
may_be_fix_msg_contentis appropriate since they operate on different message fields.
|
CC @2ez4bz |
3b2196a to
10fedd2
Compare
|
@ryan-lempka thanks for fixing this! based on the source issue:
|
@rmccorm4 yes, this PR aims to fix everything outlined in #4161. Everything is validated with unit tests. The example you give there is the unit test: |
|
Thanks @ryan-lempka , think it just needs a rebase with merge conflicts resolved from your other merged add_generation_prompt PR, and a quick additional input case mentioned by @indrajit96 - nice work! |
2ez4bz
left a 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.
LGTM! Not sure if my approval does anything, but doing it anyway :)
f57788c to
fe8e5a8
Compare
@rmccorm4 rebase done and @indrajit96 test request added |
Signed-off-by: Ryan Lempka <[email protected]>
Signed-off-by: Ryan Lempka <[email protected]>
fe8e5a8 to
40bd379
Compare
|
Pulled in #4198 |
Overview
Parse tool call
argumentsJSON strings into structured JSON before Jinja rendering to fix double-encoding and enable iteration.Details
messages[*].tool_calls[*].function.argumentsmessages[*].function_call.argumentsmessages()and only applied immediately before Jinja renderingWhere to start
oai.rs:normalize_tool_arguments_in_messages()Tests
|tojsonno longer double-encodes.|itemsiteration works.Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit
Improvements
Tests