mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
Support file references in image edit requests (#47956)
## Why Editing recent conversation images failed when the selected images included a file reference from a message or tool output. ## What changed Use `ImageReference` in `ImageEditRequest` to accept both `image_url` and `file_id` inputs. Pass file references from conversation history through to image edit requests while preserving image selection order. ## Testing Update tests to cover file references from messages and tool outputs, and serialization of mixed inline and file references in image edit requests. GitOrigin-RevId: 2764bf36a81a62ddd25cf9df27346a434a10c449
This commit is contained in:
committed by
copyberry
parent
40e13e6281
commit
51d66fdd3b
@@ -122,13 +122,13 @@ mod tests {
|
||||
use crate::images::ImageBackground;
|
||||
use crate::images::ImageData;
|
||||
use crate::images::ImageQuality;
|
||||
use crate::images::ImageUrl;
|
||||
use crate::provider::RetryConfig;
|
||||
use codex_client::Request;
|
||||
use codex_client::RequestBody;
|
||||
use codex_client::Response;
|
||||
use codex_client::StreamResponse;
|
||||
use codex_client::TransportError;
|
||||
use codex_protocol::models::ImageReference;
|
||||
use http::StatusCode;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
@@ -339,9 +339,14 @@ mod tests {
|
||||
let (response, imagegen_request_id) = client
|
||||
.edit(
|
||||
&ImageEditRequest {
|
||||
images: vec![ImageUrl {
|
||||
image_url: "data:image/png;base64,Zm9v".to_string(),
|
||||
}],
|
||||
images: vec![
|
||||
ImageReference::Inline {
|
||||
image_url: "data:image/png;base64,Zm9v".to_string(),
|
||||
},
|
||||
ImageReference::File {
|
||||
file_id: "file-image".to_string(),
|
||||
},
|
||||
],
|
||||
prompt: "add a red hat".to_string(),
|
||||
background: None,
|
||||
model: "gpt-image-1.5".to_string(),
|
||||
@@ -362,7 +367,10 @@ mod tests {
|
||||
assert_eq!(
|
||||
request.body.as_ref().and_then(RequestBody::json),
|
||||
Some(&json!({
|
||||
"images": [{"image_url": "data:image/png;base64,Zm9v"}],
|
||||
"images": [
|
||||
{"image_url": "data:image/png;base64,Zm9v"},
|
||||
{"file_id": "file-image"},
|
||||
],
|
||||
"prompt": "add a red hat",
|
||||
"model": "gpt-image-1.5",
|
||||
}))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use codex_protocol::models::ImageReference;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
@@ -17,7 +18,7 @@ pub struct ImageGenerationRequest {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
pub struct ImageEditRequest {
|
||||
pub images: Vec<ImageUrl>,
|
||||
pub images: Vec<ImageReference>,
|
||||
pub prompt: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub background: Option<ImageBackground>,
|
||||
@@ -30,11 +31,6 @@ pub struct ImageEditRequest {
|
||||
pub size: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct ImageUrl {
|
||||
pub image_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ImageBackground {
|
||||
|
||||
@@ -83,7 +83,6 @@ pub use crate::images::ImageEditRequest;
|
||||
pub use crate::images::ImageGenerationRequest;
|
||||
pub use crate::images::ImageQuality;
|
||||
pub use crate::images::ImageResponse;
|
||||
pub use crate::images::ImageUrl;
|
||||
pub use crate::provider::Provider;
|
||||
pub use crate::provider::RetryConfig;
|
||||
pub use crate::provider::is_azure_responses_provider;
|
||||
|
||||
Reference in New Issue
Block a user