fix(provider): preserve content-filtered tool call rejection

This commit is contained in:
leokun
2026-09-04 16:08:26 +08:00
parent 56b67aff88
commit aa47152f1f
+10 -5
View File
@@ -365,9 +365,9 @@ fn map_finish(value: &str, has_tools: bool) -> FinishReason {
match value {
"tool_calls" | "function_call" => FinishReason::ToolUse,
"length" => FinishReason::Length,
// Observed tool calls outrank whatever the provider labelled the stop:
// OpenAI-compatible servers routinely report "stop" while streaming tool
// calls, and the run rejects a finish reason that contradicts them.
"content_filter" => FinishReason::Stop,
// Observed tool calls outrank ordinary or unknown stop labels because
// OpenAI-compatible servers commonly emit tools with `stop`.
_ if has_tools => FinishReason::ToolUse,
_ => FinishReason::Stop,
}
@@ -441,12 +441,17 @@ mod tests {
use super::*;
#[test]
fn observed_tool_calls_outrank_a_stop_finish_reason() {
fn observed_tool_calls_outrank_ordinary_stop_reasons() {
assert_eq!(map_finish("stop", true), FinishReason::ToolUse);
assert_eq!(map_finish("content_filter", true), FinishReason::ToolUse);
assert_eq!(map_finish("", true), FinishReason::ToolUse);
}
#[test]
fn content_filter_never_executes_observed_tool_calls() {
assert_eq!(map_finish("content_filter", true), FinishReason::Stop);
assert_eq!(map_finish("content_filter", false), FinishReason::Stop);
}
#[test]
fn finish_reason_mapping_without_tool_calls_is_unchanged() {
assert_eq!(map_finish("stop", false), FinishReason::Stop);