mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-09 00:16:23 +08:00
fix(provider): preserve content-filtered tool call rejection
This commit is contained in:
@@ -365,9 +365,9 @@ fn map_finish(value: &str, has_tools: bool) -> FinishReason {
|
|||||||
match value {
|
match value {
|
||||||
"tool_calls" | "function_call" => FinishReason::ToolUse,
|
"tool_calls" | "function_call" => FinishReason::ToolUse,
|
||||||
"length" => FinishReason::Length,
|
"length" => FinishReason::Length,
|
||||||
// Observed tool calls outrank whatever the provider labelled the stop:
|
"content_filter" => FinishReason::Stop,
|
||||||
// OpenAI-compatible servers routinely report "stop" while streaming tool
|
// Observed tool calls outrank ordinary or unknown stop labels because
|
||||||
// calls, and the run rejects a finish reason that contradicts them.
|
// OpenAI-compatible servers commonly emit tools with `stop`.
|
||||||
_ if has_tools => FinishReason::ToolUse,
|
_ if has_tools => FinishReason::ToolUse,
|
||||||
_ => FinishReason::Stop,
|
_ => FinishReason::Stop,
|
||||||
}
|
}
|
||||||
@@ -441,12 +441,17 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[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("stop", true), FinishReason::ToolUse);
|
||||||
assert_eq!(map_finish("content_filter", true), FinishReason::ToolUse);
|
|
||||||
assert_eq!(map_finish("", 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]
|
#[test]
|
||||||
fn finish_reason_mapping_without_tool_calls_is_unchanged() {
|
fn finish_reason_mapping_without_tool_calls_is_unchanged() {
|
||||||
assert_eq!(map_finish("stop", false), FinishReason::Stop);
|
assert_eq!(map_finish("stop", false), FinishReason::Stop);
|
||||||
|
|||||||
Reference in New Issue
Block a user