-
Notifications
You must be signed in to change notification settings - Fork 195
fix(translation): replay assistant reasoning as reasoning_content too #460
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
Open
ting-hong-shieh
wants to merge
2
commits into
NVIDIA-NeMo:main
Choose a base branch
from
ting-hong-shieh:fix/openai-chat-reasoning-content-alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ pub mod common; | |
| use pretty_assertions::assert_eq; | ||
| use serde_json::{Value, json}; | ||
| use switchyard_translation::{ | ||
| LossyConversionPolicy, TranslationEngine, TranslationPolicy, WireFormat, | ||
| LossyConversionPolicy, PreservationPolicy, TranslationEngine, TranslationPolicy, WireFormat, | ||
| }; | ||
|
|
||
| use common::{REASONING_MODEL, normalized_policy, shell_tool_call}; | ||
|
|
@@ -1010,6 +1010,85 @@ fn responses_reasoning_items_attach_to_tool_call_turn_for_openai_chat() -> TestR | |
| Ok(()) | ||
| } | ||
|
|
||
| // Reasoning-required upstreams look for `reasoning_content` and treat it as | ||
| // present-or-absent, so replaying only `reasoning` fails the next turn. Both | ||
| // spellings carry the same text, and tool calls stay alongside them. | ||
| #[test] | ||
| fn openai_chat_replays_reasoning_under_both_spellings() -> TestResult { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets combine 2 tests into one, and make the comments one line |
||
| let engine = TranslationEngine::default(); | ||
| let body = json!({ | ||
| "model": "deepseek-reasoner", | ||
| "messages": [ | ||
| {"role": "user", "content": "What is 2+2? Use the calculator."}, | ||
| { | ||
| "role": "assistant", | ||
| "content": "I'll call the tool.", | ||
| "reasoning_content": "The user wants 2+2. Call the calculator.", | ||
| "tool_calls": [{ | ||
| "id": "call_abc123", | ||
| "type": "function", | ||
| "function": {"name": "calculator", "arguments": "{\"a\": 2, \"b\": 2}"} | ||
| }] | ||
| }, | ||
| {"role": "tool", "tool_call_id": "call_abc123", "content": "4"} | ||
| ] | ||
| }); | ||
|
|
||
| let output = engine | ||
| .translate_request( | ||
| WireFormat::OpenAiChat, | ||
| WireFormat::OpenAiChat, | ||
| &body, | ||
| &TranslationPolicy { | ||
| preservation: PreservationPolicy::Disabled, | ||
| ..TranslationPolicy::default() | ||
| }, | ||
| )? | ||
| .body; | ||
|
|
||
| let assistant = &output["messages"][1]; | ||
| assert_eq!( | ||
| assistant["reasoning_content"], | ||
| "The user wants 2+2. Call the calculator." | ||
| ); | ||
| assert_eq!(assistant["reasoning"], assistant["reasoning_content"]); | ||
| assert_eq!(assistant["content"], "I'll call the tool."); | ||
| assert_eq!(assistant["tool_calls"][0]["id"], "call_abc123"); | ||
| assert_eq!(output["messages"][2]["role"], "tool"); | ||
| assert_eq!(output["messages"][2]["tool_call_id"], "call_abc123"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| // A turn carrying no reasoning must not gain either spelling. | ||
| #[test] | ||
| fn openai_chat_without_reasoning_sends_neither_spelling() -> TestResult { | ||
| let engine = TranslationEngine::default(); | ||
| let body = json!({ | ||
| "model": "deepseek-reasoner", | ||
| "messages": [ | ||
| {"role": "user", "content": "hi"}, | ||
| {"role": "assistant", "content": "hello"}, | ||
| {"role": "user", "content": "continue"} | ||
| ] | ||
| }); | ||
|
|
||
| let output = engine | ||
| .translate_request( | ||
| WireFormat::OpenAiChat, | ||
| WireFormat::OpenAiChat, | ||
| &body, | ||
| &TranslationPolicy { | ||
| preservation: PreservationPolicy::Disabled, | ||
| ..TranslationPolicy::default() | ||
| }, | ||
| )? | ||
| .body; | ||
|
|
||
| assert!(output["messages"][1].get("reasoning").is_none()); | ||
| assert!(output["messages"][1].get("reasoning_content").is_none()); | ||
| Ok(()) | ||
| } | ||
|
|
||
| // Verifies a reasoning item merges into the assistant message that follows it. | ||
| #[test] | ||
| fn responses_reasoning_item_merges_into_next_assistant_message_for_openai_chat() -> TestResult { | ||
|
|
@@ -1043,6 +1122,7 @@ fn responses_reasoning_item_merges_into_next_assistant_message_for_openai_chat() | |
| { | ||
| "role": "assistant", | ||
| "content": "Let me check.", | ||
| "reasoning_content": "Reading.", | ||
| "reasoning": "Reading." | ||
| } | ||
| ]) | ||
|
|
@@ -1133,6 +1213,7 @@ fn openai_chat_encrypted_reasoning_details_retain_fallback() -> TestResult { | |
|
|
||
| assert_eq!(output["messages"][0]["reasoning_details"], details); | ||
| assert_eq!(output["messages"][0]["reasoning"], "fallback text"); | ||
| assert_eq!(output["messages"][0]["reasoning_content"], "fallback text"); | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
lets reduce the comments here to one line as well