fix(provider): clamp reasoning effort and filter chat extensions

This commit is contained in:
zhefox
2026-06-03 10:52:26 +08:00
parent 5ac153a0bb
commit 5e39801bba
4 changed files with 99 additions and 8 deletions
@@ -165,6 +165,7 @@ mod tests {
convert_openai_chat_request_to_claude_request,
convert_openai_chat_request_to_openai_responses_request,
normalize_claude_request_to_openai_chat_request,
normalize_gemini_request_to_openai_chat_request,
normalize_openai_responses_request_to_openai_chat_request,
};
@@ -219,6 +220,43 @@ mod tests {
assert_eq!(converted["messages"][0]["content"], "hello");
}
#[test]
fn claude_request_to_chat_clamps_max_reasoning_effort_to_high() {
let body = json!({
"model": "claude-sonnet",
"messages": [{"role": "user", "content": "hello"}],
"thinking": {"type": "enabled", "budget_tokens": 1024},
"output_config": {"effort": "max"},
"max_tokens": 128,
});
let converted =
normalize_claude_request_to_openai_chat_request(&body).expect("openai chat request");
assert_eq!(converted["reasoning_effort"], "high");
}
#[test]
fn gemini_request_to_chat_clamps_xhigh_reasoning_effort_to_high() {
let body = json!({
"contents": [{
"role": "user",
"parts": [{"text": "hello"}]
}],
"generationConfig": {
"thinkingConfig": {"thinkingBudget": 8192}
}
});
let converted = normalize_gemini_request_to_openai_chat_request(
&body,
"/v1beta/models/gemini-2.5-pro:generateContent",
)
.expect("openai chat request");
assert_eq!(converted["reasoning_effort"], "high");
}
#[test]
fn responses_request_normalizer_keeps_tool_history_chat_safe() {
let call_id_one = "call_weather_123";
@@ -333,6 +371,34 @@ mod tests {
assert_eq!(messages[0]["content"], "");
}
#[test]
fn responses_request_normalizer_clamps_chat_reasoning_effort_and_filters_extensions() {
let body = json!({
"model": "gpt-5.1",
"input": "hello",
"reasoning": {"effort": "xhigh"},
"text": {"verbosity": "high"},
"include": ["reasoning.encrypted_content"],
"store": false,
"service_tier": "priority",
"prompt_cache_key": "cache_123",
"safety_identifier": "user_123"
});
let converted = normalize_openai_responses_request_to_openai_chat_request(&body)
.expect("openai chat request");
assert_eq!(converted["reasoning_effort"], "high");
assert_eq!(converted["verbosity"], "high");
assert_eq!(converted["service_tier"], "priority");
assert_eq!(converted["prompt_cache_key"], "cache_123");
assert_eq!(converted["safety_identifier"], "user_123");
assert!(converted.get("include").is_none());
assert!(converted.get("store").is_none());
assert!(converted.get("text").is_none());
assert!(converted.get("reasoning").is_none());
}
#[test]
fn request_normalizer_preserves_multiple_claude_tool_results() {
let body = json!({