-
Notifications
You must be signed in to change notification settings - Fork 219
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
Changes from all commits
4f6e434
737adc1
7770f9e
2580378
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ pub mod common; | |
| use pretty_assertions::assert_eq; | ||
| use serde_json::{Value, json}; | ||
| use switchyard_translation::{ | ||
| FormatId, LossyConversionPolicy, TranslationEngine, TranslationPolicy, WireFormat, | ||
| prepare_request_for_target, | ||
| FormatId, LossyConversionPolicy, PreservationPolicy, TranslationEngine, TranslationPolicy, | ||
| WireFormat, prepare_request_for_target, | ||
| }; | ||
|
|
||
| use common::{REASONING_MODEL, normalized_policy, shell_tool_call}; | ||
|
|
@@ -1212,6 +1212,58 @@ fn responses_reasoning_items_attach_to_tool_call_turn_for_openai_chat() -> TestR | |
| Ok(()) | ||
| } | ||
|
|
||
| // Both spellings carry replayed reasoning, and a turn without reasoning gains neither. | ||
| #[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
Contributor
Author
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. Done — the two cases are one test now ( |
||
| 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"}, | ||
| {"role": "assistant", "content": "It is 4."} | ||
| ] | ||
| }); | ||
|
|
||
| let output = engine | ||
| .translate_request( | ||
| WireFormat::OpenAiChat, | ||
| WireFormat::OpenAiChat, | ||
| &body, | ||
| &TranslationPolicy { | ||
| preservation: PreservationPolicy::Disabled, | ||
| ..TranslationPolicy::default() | ||
| }, | ||
| )? | ||
| .body; | ||
|
|
||
| let reasoned = &output["messages"][1]; | ||
| assert_eq!( | ||
| reasoned["reasoning_content"], | ||
| "The user wants 2+2. Call the calculator." | ||
| ); | ||
| assert_eq!(reasoned["reasoning"], reasoned["reasoning_content"]); | ||
| assert_eq!(reasoned["content"], "I'll call the tool."); | ||
| assert_eq!(reasoned["tool_calls"][0]["id"], "call_abc123"); | ||
| assert_eq!(output["messages"][2]["role"], "tool"); | ||
| assert_eq!(output["messages"][2]["tool_call_id"], "call_abc123"); | ||
|
|
||
| let without_reasoning = &output["messages"][3]; | ||
| assert!(without_reasoning.get("reasoning").is_none()); | ||
| assert!(without_reasoning.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 { | ||
|
|
@@ -1245,6 +1297,7 @@ fn responses_reasoning_item_merges_into_next_assistant_message_for_openai_chat() | |
| { | ||
| "role": "assistant", | ||
| "content": "Let me check.", | ||
| "reasoning_content": "Reading.", | ||
| "reasoning": "Reading." | ||
| } | ||
| ]) | ||
|
|
@@ -1335,6 +1388,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(()) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.