统一缺省图片模型的归一化结果

normalize_image_model 的空白模型回退改为 GPT_IMAGE_2_5_GENERATION_MODEL,与 build_image_request_body 默认值一致

补充单测断言空白模型与默认生成模型产出同一请求体
This commit is contained in:
2026-09-19 13:48:11 +08:00
parent 42fdb57efe
commit 939c35a9b9
2 changed files with 15 additions and 1 deletions
@@ -87,9 +87,14 @@ pub fn build_nanobanana_generate_content_request_body(
})
}
/// 归一化调用方传入的模型字符串。
///
/// 只处理缺省场景:空/空白输入落到当前默认生成模型 `GPT_IMAGE_2_5_GENERATION_MODEL`
/// 与 `build_image_request_body` 的默认值保持一致;显式传入的模型(含历史
/// `gpt-image-2` 等旧值)原样保留,交给 `resolve_image_provider` 做路由。
pub fn normalize_image_model(model: &str) -> &str {
match model.trim() {
"" => GPT_IMAGE_2_MODEL,
"" => GPT_IMAGE_2_5_GENERATION_MODEL,
value => value,
}
}
@@ -59,6 +59,15 @@ fn image_provider_clamps_gpt_image_2_explicit_pixel_sizes_to_its_supported_pixel
assert_eq!(poster["size"], "1280x720");
}
#[test]
fn image_provider_blank_model_falls_back_to_default_generation_model() {
let blank = build_image_request_body_with_model(" ", "空模型", None, "1024x1024", 1, &[]);
let default = build_image_request_body("空模型", None, "1024x1024", 1, &[]);
assert_eq!(blank["model"], GPT_IMAGE_2_5_GENERATION_MODEL);
assert_eq!(blank["model"], default["model"]);
}
#[test]
fn image_provider_normalizes_2k_landscape_spec_size() {
let body = build_image_request_body("生成规范图", None, "2048x1152", 1, &[]);