sending back imagaegencall response back to responseapi (#14558)

Sending back the ResponseItem::ImageGenerationCall as is, because it is
now supported from the API-side.
This commit is contained in:
Won Park
2026-03-13 17:29:19 +00:00
committed by GitHub
parent 6b3d82daca
commit 958f93f899
7 changed files with 211 additions and 121 deletions
@@ -344,9 +344,6 @@ impl ContextManager {
// all outputs must have a corresponding function/tool call
normalize::remove_orphan_outputs(&mut self.items);
//rewrite image_gen_calls to messages to support stateless input
normalize::rewrite_image_generation_calls_for_stateless_input(&mut self.items);
// strip images when model does not support them
normalize::strip_images_when_unsupported(input_modalities, &mut self.items);
}
@@ -398,7 +398,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
}
#[test]
fn for_prompt_rewrites_image_generation_calls_when_images_are_supported() {
fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
let history = create_history_with_items(vec![
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
@@ -420,25 +420,11 @@ fn for_prompt_rewrites_image_generation_calls_when_images_are_supported() {
assert_eq!(
history.for_prompt(&default_input_modalities()),
vec![
ResponseItem::Message {
id: None,
role: "user".to_string(),
content: vec![
ContentItem::InputText {
text: "Image Generation Call".to_string(),
},
ContentItem::InputText {
text: "Image ID: ig_123".to_string(),
},
ContentItem::InputText {
text: "Prompt: lobster".to_string(),
},
ContentItem::InputImage {
image_url: "data:image/png;base64,Zm9v".to_string(),
},
],
end_turn: None,
phase: None,
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
status: "generating".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
},
ResponseItem::Message {
id: None,
@@ -454,7 +440,7 @@ fn for_prompt_rewrites_image_generation_calls_when_images_are_supported() {
}
#[test]
fn for_prompt_rewrites_image_generation_calls_when_images_are_unsupported() {
fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
let history = create_history_with_items(vec![
ResponseItem::Message {
id: None,
@@ -485,26 +471,11 @@ fn for_prompt_rewrites_image_generation_calls_when_images_are_unsupported() {
end_turn: None,
phase: None,
},
ResponseItem::Message {
id: None,
role: "user".to_string(),
content: vec![
ContentItem::InputText {
text: "Image Generation Call".to_string(),
},
ContentItem::InputText {
text: "Image ID: ig_123".to_string(),
},
ContentItem::InputText {
text: "Prompt: lobster".to_string(),
},
ContentItem::InputText {
text: "image content omitted because you do not support image input"
.to_string(),
},
],
end_turn: None,
phase: None,
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
status: "completed".to_string(),
revised_prompt: Some("lobster".to_string()),
result: String::new(),
},
]
);
+3 -42
View File
@@ -289,48 +289,6 @@ where
}
}
pub(crate) fn rewrite_image_generation_calls_for_stateless_input(items: &mut Vec<ResponseItem>) {
let original_items = std::mem::take(items);
*items = original_items
.into_iter()
.map(|item| match item {
ResponseItem::ImageGenerationCall {
id,
revised_prompt,
result,
..
} => {
let image_url = if result.starts_with("data:") {
result
} else {
format!("data:image/png;base64,{result}")
};
let revised_prompt = revised_prompt.unwrap_or_default();
ResponseItem::Message {
id: None,
role: "user".to_string(),
content: vec![
ContentItem::InputText {
text: "Image Generation Call".to_string(),
},
ContentItem::InputText {
text: format!("Image ID: {id}"),
},
ContentItem::InputText {
text: format!("Prompt: {revised_prompt}"),
},
ContentItem::InputImage { image_url },
],
end_turn: None,
phase: None,
}
}
_ => item,
})
.collect();
}
/// Strip image content from messages and tool outputs when the model does not support images.
/// When `input_modalities` contains `InputModality::Image`, no stripping is performed.
pub(crate) fn strip_images_when_unsupported(
@@ -377,6 +335,9 @@ pub(crate) fn strip_images_when_unsupported(
*content_items = normalized_content_items;
}
}
ResponseItem::ImageGenerationCall { result, .. } => {
result.clear();
}
_ => {}
}
}