mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve content kinds during image preparation (#40281)
## Why Image preparation can rewrite message content, including replacing images that cannot be processed with model-visible error text. The positional content-kind metadata must stay aligned with those rewrites. ## What changed - Process message images together with their content-kind annotations. - Preserve existing kinds for unchanged and resized content. - Classify failed-image placeholders as `images.preparation_error`. ## Testing - Cover metadata preservation across successful, resized, and failed images. - Verify Responses Lite sends `user.image` and `images.preparation_error` kinds. GitOrigin-RevId: 1be7bcbe47014251019bfff0d826c9dfe3239dec
This commit is contained in:
1 parent
6677fd827d
commit
479c8c8924
6 files changed
+122
-73
No files matched your search
@@ -52,6 +52,16 @@ fn preparation_preserves_small_image_bytes_and_replaces_remote_urls() {
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
}];
|
||||
items.push(ResponseItem::Message {
|
||||
id: None,
|
||||
role: "developer".to_string(),
|
||||
content: vec![ContentItem::InputImage {
|
||||
image_url: "https://example.com/developer-image.png".to_string(),
|
||||
detail: Some(ImageDetail::High),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
});
|
||||
|
||||
prepare_response_items(
|
||||
&mut items,
|
||||
@@ -71,6 +81,25 @@ fn preparation_preserves_small_image_bytes_and_replaces_remote_urls() {
|
||||
};
|
||||
assert_eq!(decoded_image(image_url).0, original_bytes);
|
||||
assert_eq!(text, REMOTE_IMAGE_URL_PLACEHOLDER);
|
||||
assert_eq!(
|
||||
&items[1],
|
||||
&ResponseItem::Message {
|
||||
id: None,
|
||||
role: "developer".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: REMOTE_IMAGE_URL_PLACEHOLDER.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: Some(
|
||||
InternalChatMessageMetadataPassthrough {
|
||||
content_item_kinds: Some(vec![ContentItemKind(
|
||||
"images.preparation_error".to_string()
|
||||
)]),
|
||||
..Default::default()
|
||||
}
|
||||
),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -199,7 +228,16 @@ fn resize_notices_preserve_original_image_positions_and_skip_failed_images() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
internal_chat_message_metadata_passthrough: Some(
|
||||
InternalChatMessageMetadataPassthrough {
|
||||
content_item_kinds: Some(vec![
|
||||
ContentItemKind("user.image".to_string()),
|
||||
ContentItemKind("user.image".to_string()),
|
||||
ContentItemKind("user.image".to_string()),
|
||||
]),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
id: None,
|
||||
@@ -231,9 +269,25 @@ fn resize_notices_preserve_original_image_positions_and_skip_failed_images() {
|
||||
"</image_resize_notice>"
|
||||
);
|
||||
|
||||
let ResponseItem::Message { content, .. } = &items[0] else {
|
||||
let ResponseItem::Message {
|
||||
content,
|
||||
internal_chat_message_metadata_passthrough,
|
||||
..
|
||||
} = &items[0]
|
||||
else {
|
||||
panic!("expected message");
|
||||
};
|
||||
assert_eq!(
|
||||
internal_chat_message_metadata_passthrough,
|
||||
&Some(InternalChatMessageMetadataPassthrough {
|
||||
content_item_kinds: Some(vec![
|
||||
ContentItemKind("user.image".to_string()),
|
||||
ContentItemKind("images.preparation_error".to_string()),
|
||||
ContentItemKind("user.image".to_string()),
|
||||
]),
|
||||
..Default::default()
|
||||
}),
|
||||
);
|
||||
let [
|
||||
ContentItem::InputImage {
|
||||
image_url: small_message_image_url,
|
||||
|
||||
Reference in new issue
Block a user