File tree Expand file tree Collapse file tree
packages/pinjected-genai/src/pinjected_genai Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -437,6 +437,18 @@ async def a_edit_image__genai(
437437 image_bytes = part .inline_data .data
438438 mime_type = part .inline_data .mime_type
439439 if image_bytes and not generated_image : # Take first image
440+ if first_transform :
441+ with Image .open (BytesIO (image_bytes )) as raw_image :
442+ raw_width , raw_height = raw_image .size
443+ if (
444+ raw_width != first_transform .target_dim
445+ or raw_height != first_transform .target_dim
446+ ):
447+ raise ValueError (
448+ "GenAI response image dimensions"
449+ f" { raw_width } x{ raw_height } do not match"
450+ f" expected { first_transform .target_dim } x{ first_transform .target_dim } "
451+ )
440452 processed_bytes = image_bytes
441453 if first_transform :
442454 processed_bytes = first_transform .restore (
You can’t perform that action at this time.
0 commit comments