mirror of
https://github.com/openai/codex.git
synced 2026-11-25 15:24:26 +00:00
Include transparent background in image generation analytics (#40544)
## What changed Add the optional `transparent_background` value to image generation event parameters and populate it from the corresponding image generation item. ## Testing Add reducer coverage for completed events with true, false, and unset values, as well as failed events where the value is unset. GitOrigin-RevId: a9ee13696acb34feb998b345f54889cac7a401d9
This commit is contained in:
1 parent
2e4675919e
commit
348f49b292
3 files changed
+74
No files matched your search
@@ -5092,6 +5092,78 @@ async fn turn_lifecycle_emits_turn_event() {
|
|||||||
assert_eq!(payload["event_params"]["total_tokens"], json!(321));
|
assert_eq!(payload["event_params"]["total_tokens"], json!(321));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn image_generation_events_preserve_transparent_background_metadata() {
|
||||||
|
for (status, transparent_background) in [
|
||||||
|
("completed", Some(true)),
|
||||||
|
("completed", Some(false)),
|
||||||
|
("completed", None),
|
||||||
|
("failed", None),
|
||||||
|
] {
|
||||||
|
let mut reducer = AnalyticsReducer::default();
|
||||||
|
let mut out = Vec::new();
|
||||||
|
|
||||||
|
ingest_turn_prerequisites(
|
||||||
|
&mut reducer,
|
||||||
|
&mut out,
|
||||||
|
/*include_initialize*/ true,
|
||||||
|
/*include_resolved_config*/ true,
|
||||||
|
/*include_started*/ true,
|
||||||
|
/*include_token_usage*/ false,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let item = ThreadItem::ImageGeneration(ImageGenerationItem {
|
||||||
|
id: "image-1".to_string(),
|
||||||
|
status: status.to_string(),
|
||||||
|
revised_prompt: None,
|
||||||
|
result: "ok".to_string(),
|
||||||
|
transparent_background,
|
||||||
|
failure: None,
|
||||||
|
saved_path: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
reducer
|
||||||
|
.ingest(
|
||||||
|
AnalyticsFact::Notification(Box::new(ServerNotification::ItemStarted(
|
||||||
|
ItemStartedNotification {
|
||||||
|
thread_id: "thread-2".to_string(),
|
||||||
|
turn_id: "turn-2".to_string(),
|
||||||
|
started_at_ms: 998,
|
||||||
|
item: item.clone(),
|
||||||
|
},
|
||||||
|
))),
|
||||||
|
&mut out,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
reducer
|
||||||
|
.ingest(
|
||||||
|
AnalyticsFact::Notification(Box::new(ServerNotification::ItemCompleted(
|
||||||
|
ItemCompletedNotification {
|
||||||
|
thread_id: "thread-2".to_string(),
|
||||||
|
turn_id: "turn-2".to_string(),
|
||||||
|
completed_at_ms: 1_000,
|
||||||
|
item,
|
||||||
|
},
|
||||||
|
))),
|
||||||
|
&mut out,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let event = out
|
||||||
|
.iter()
|
||||||
|
.find(|event| matches!(event, TrackEventRequest::ImageGeneration(_)))
|
||||||
|
.expect("image generation event should be emitted");
|
||||||
|
let payload = serde_json::to_value(event).expect("serialize image generation event");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
payload["event_params"].get("transparent_background"),
|
||||||
|
Some(&json!(transparent_background))
|
||||||
|
);
|
||||||
|
assert_eq!(payload["event_params"]["terminal_status"], json!(status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn turn_event_counts_completed_tool_items() {
|
async fn turn_event_counts_completed_tool_items() {
|
||||||
let mut reducer = AnalyticsReducer::default();
|
let mut reducer = AnalyticsReducer::default();
|
||||||
|
|||||||
@@ -895,6 +895,7 @@ pub(crate) struct CodexImageGenerationEventParams {
|
|||||||
pub(crate) base: CodexToolItemEventBase,
|
pub(crate) base: CodexToolItemEventBase,
|
||||||
pub(crate) revised_prompt_present: bool,
|
pub(crate) revised_prompt_present: bool,
|
||||||
pub(crate) saved_path_present: bool,
|
pub(crate) saved_path_present: bool,
|
||||||
|
pub(crate) transparent_background: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|||||||
@@ -2831,6 +2831,7 @@ fn tool_item_event(input: ToolItemEventInput<'_>) -> Option<TrackEventRequest> {
|
|||||||
base,
|
base,
|
||||||
revised_prompt_present: item.revised_prompt.is_some(),
|
revised_prompt_present: item.revised_prompt.is_some(),
|
||||||
saved_path_present: item.saved_path.is_some(),
|
saved_path_present: item.saved_path.is_some(),
|
||||||
|
transparent_background: item.transparent_background,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in new issue
Block a user