@@ -668,54 +668,6 @@ def _build_fal_edit_payload(
668668 }
669669
670670
671- def _build_fal_edit_payload (
672- model_id : str ,
673- prompt : str ,
674- image_urls : list ,
675- aspect_ratio : str = DEFAULT_ASPECT_RATIO ,
676- seed : Optional [int ] = None ,
677- overrides : Optional [Dict [str , Any ]] = None ,
678- ) -> Dict [str , Any ]:
679- """Build a FAL *edit* request payload (image-to-image) from unified inputs.
680-
681- Every FAL edit endpoint takes ``image_urls`` (a list of source/reference
682- image URLs) plus the prompt. Size handling differs from text-to-image:
683- most edit endpoints auto-infer output dimensions from the input image, so
684- we only send ``image_size`` / ``aspect_ratio`` when the edit endpoint's
685- ``edit_supports`` whitelist accepts it. Keys outside ``edit_supports`` are
686- stripped before submission.
687- """
688- meta = FAL_MODELS [model_id ]
689- edit_supports = meta .get ("edit_supports" ) or set ()
690- size_style = meta ["size_style" ]
691- sizes = meta ["sizes" ]
692-
693- aspect = (aspect_ratio or DEFAULT_ASPECT_RATIO ).lower ().strip ()
694- if aspect not in sizes :
695- aspect = DEFAULT_ASPECT_RATIO
696-
697- payload : Dict [str , Any ] = dict (meta .get ("defaults" , {}))
698- payload ["prompt" ] = (prompt or "" ).strip ()
699- payload ["image_urls" ] = list (image_urls )
700-
701- # Only express output size when the edit endpoint advertises the key.
702- # gpt-image-2 edit auto-infers size from the input, so `image_size` is
703- # intentionally absent from its edit_supports whitelist.
704- if size_style in {"image_size_preset" , "gpt_literal" } and "image_size" in edit_supports :
705- payload ["image_size" ] = sizes [aspect ]
706- elif size_style == "aspect_ratio" and "aspect_ratio" in edit_supports :
707- payload ["aspect_ratio" ] = sizes [aspect ]
708-
709- if seed is not None and isinstance (seed , int ):
710- payload ["seed" ] = seed
711-
712- if overrides :
713- for k , v in overrides .items ():
714- if v is not None :
715- payload [k ] = v
716-
717- return {k : v for k , v in payload .items () if k in edit_supports }
718-
719671
720672# ---------------------------------------------------------------------------
721673# Upscaler
0 commit comments