mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 16:37:46 +08:00
修复 ChatGPT Web 生图 usage 估算
This commit is contained in:
+54
-2
@@ -1073,22 +1073,42 @@ fn build_chatgpt_web_image_provider_body_from_openai_responses_body(
|
||||
.unwrap_or("gpt-5-5-thinking");
|
||||
let image_urls = openai_image_inputs_as_urls(&images);
|
||||
|
||||
let body = json!({
|
||||
let mut body = json!({
|
||||
"operation": operation,
|
||||
"model": if model.is_empty() { "gpt-image-2" } else { model },
|
||||
"web_model": web_model,
|
||||
"prompt": prompt,
|
||||
"size": size,
|
||||
"ratio": chatgpt_web_ratio_for_size(size),
|
||||
"quality": quality,
|
||||
"output_format": output_format,
|
||||
"images": image_urls,
|
||||
});
|
||||
let summary = json!({
|
||||
if let Some(partial_images) = tool
|
||||
.as_ref()
|
||||
.and_then(|tool| tool.get("partial_images"))
|
||||
.or_else(|| object.get("partial_images"))
|
||||
.cloned()
|
||||
{
|
||||
body.as_object_mut()?
|
||||
.insert("partial_images".to_string(), partial_images);
|
||||
}
|
||||
let mut summary = json!({
|
||||
"operation": operation,
|
||||
"output_format": output_format,
|
||||
"size": size,
|
||||
"quality": quality,
|
||||
});
|
||||
if let Some(partial_images) = tool
|
||||
.as_ref()
|
||||
.and_then(|tool| tool.get("partial_images"))
|
||||
.or_else(|| object.get("partial_images"))
|
||||
.cloned()
|
||||
{
|
||||
summary
|
||||
.as_object_mut()?
|
||||
.insert("partial_images".to_string(), partial_images);
|
||||
}
|
||||
Some((body, summary))
|
||||
}
|
||||
|
||||
@@ -1426,4 +1446,36 @@ mod tests {
|
||||
assert_eq!(summary["operation"], "generate");
|
||||
assert_eq!(summary["output_format"], "png");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chatgpt_web_responses_image_body_preserves_usage_options() {
|
||||
let body_json = json!({
|
||||
"model": "gpt-image-2",
|
||||
"input": "Draw a glass city",
|
||||
"tools": [
|
||||
{
|
||||
"type": "image_generation",
|
||||
"size": "1024x1024",
|
||||
"quality": "high",
|
||||
"output_format": "png",
|
||||
"partial_images": 2
|
||||
}
|
||||
],
|
||||
"tool_choice": {
|
||||
"type": "image_generation"
|
||||
}
|
||||
});
|
||||
|
||||
let (provider_body, summary) =
|
||||
build_chatgpt_web_image_provider_body_from_openai_responses_body(
|
||||
&body_json,
|
||||
"gpt-image-2",
|
||||
)
|
||||
.expect("responses image body should convert");
|
||||
|
||||
assert_eq!(provider_body["quality"], "high");
|
||||
assert_eq!(provider_body["partial_images"], 2);
|
||||
assert_eq!(summary["quality"], "high");
|
||||
assert_eq!(summary["partial_images"], 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user