Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl FormatCodec for OpenAiResponsesCodec {
})
.sum::<usize>();
content.extend(output.content);
if output.stop_reason.is_some() {
if output.stop_reason.is_some() && stop_reason != Some(StopReason::ToolUse) {
stop_reason = output.stop_reason;
}
}
Expand Down
18 changes: 17 additions & 1 deletion crates/switchyard-translation/tests/response_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ fn openai_chat_response_with_text_and_tool_call_translates_both_to_responses() -
"usage": {"prompt_tokens": 4, "completion_tokens": 3, "total_tokens": 7}
});

let output = engine
let mut output = engine
.translate_response(
WireFormat::OpenAiChat,
WireFormat::OpenAiResponses,
Expand All @@ -1069,6 +1069,22 @@ fn openai_chat_response_with_text_and_tool_call_translates_both_to_responses() -
assert_eq!(output["output"][0]["content"][0]["text"], "Let me check.");
assert_eq!(output["output"][1]["type"], "function_call");
assert_eq!(output["output"][1]["call_id"], "call_1");

// Check text before the tool call, then reverse the items to check text after it.
for _ in 0..2 {
let decoded = engine
.decode_response(
WireFormat::OpenAiResponses,
&output,
&TranslationPolicy::default(),
)?
.response;
assert_eq!(decoded.outputs[0].stop_reason, Some(StopReason::ToolUse));
output["output"]
.as_array_mut()
.ok_or("output should be an array")?
.reverse();
}
Ok(())
}

Expand Down
Loading