
    Cj                          S SK JrJr  S SKJrJrJrJrJrJ	r	  S SK
r
S SKJr  S SKJr  S SKJrJr  S SKJr   " S S	5      rg)
    )BufferedReaderBytesIO)AnyDictListOptionalcastget_type_hintsN)get_image_type)BaseImageEditConfig)FILE_MIME_TYPESFileType)ImageEditOptionalRequestParamsc                       \ rS rSr\  SS\S\S\S\\	   S\\
\      S\4S	 jj5       r\S
\\\4   S\4S j5       r\S\S\4S j5       rSrg)ImageEditRequestUtils   Nmodelimage_edit_provider_configimage_edit_optional_paramsdrop_paramsadditional_drop_paramsreturnc           	         UR                  U 5      n[        R                  SL =(       d    USL n[        U5      nU(       a  U H  nUR	                  US5        M     U Vs/ s H  oU;  d  M
  UPM     n	nU	(       aM  U(       a  U	 H  nUR	                  US5        M     O*[        R
                  " U SU  SSR                  U	5       3S9eUR                  [        [        U5      U US9n
U
$ s  snf )a  
Get optional parameters for the image edit API.

Args:
    model: The model name
    image_edit_provider_config: The provider configuration for image edit API
    image_edit_optional_params: The optional parameters for the image edit API
    drop_params: If True, silently drop unsupported parameters instead of raising
    additional_drop_params: List of additional parameter names to drop

Returns:
    A dictionary of supported parameters for the image edit API
TNz5The following parameters are not supported for model z: z, )r   message)r   r   r   )
get_supported_openai_paramslitellmr   dictpopUnsupportedParamsErrorjoinmap_openai_paramsr	   r   )r   r   r   r   r   supported_paramsshould_dropfiltered_optional_paramsparamunsupported_paramsmapped_paramss              f/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/litellm/images/utils.pyget_optional_params_image_edit4ImageEditRequestUtils.get_optional_params_image_edit   s   * 6QQRWX))T1H[D5H#'(B#C !/(,,UD9 0  8
7eHX;XE7 	 
 /E,00= 0 44STYSZZ\]a]f]fgy]z\{| 
 3DD'+.0H( # E 
 -
s    	C*-C*paramsc                     [        [        5      R                  5       nU R                  5        VVs0 s H  u  p#X!;   d  M  Uc  M  X#_M     nnn[	        [        U5      $ s  snnf )z
Filter parameters to only include those defined in ImageEditOptionalRequestParams.

Args:
    params: Dictionary of parameters to filter

Returns:
    ImageEditOptionalRequestParams instance with only the valid parameters
)r
   r   keysitemsr	   )r+   
valid_keyskvfiltered_paramss        r(   'get_requested_image_edit_optional_param=ImageEditRequestUtils.get_requested_image_edit_optional_paramB   s]     $$BCHHJ
#\\^
+TQqD1DAD^ 	 
 2ODD
s   A AA
image_datac                 ^    [        U [        5      (       aE  U R                  5       nU R                  S5        U R	                  S5      nU R                  U5        GO[        U [
        5      (       aD  U R                  5       nU R                  S5        U R	                  S5      nU R                  U5        O[        U [        5      (       a  U SS nO[        U S5      (       ai  [        U SS 5      " 5       n[        U S5      (       a  U R                  S5        U R	                  S5      n[        U S5      (       a  U R                  U5        O[        [        R                     $ [        U5      nUc  [        [        R                     $ [        R                  [        R                  [        R                  [        R                  [        R                   S.nUR#                  U5      nUc  [        [        R                     $ [        U   $ ! [$         a    [        [        R                     s $ f = f)	z
Detect the content type of image data using existing LiteLLM utils.

Args:
    image_data: Can be BytesIO, bytes, BufferedReader, or other file-like objects

Returns:
    The MIME type string (e.g., "image/png", "image/jpeg")
r   d   Nreadtellc                      g)Nr    r;       r(   <lambda>>ImageEditRequestUtils.get_image_content_type.<locals>.<lambda>w   s    ar<   seek)pngjpeggifwebpheic)
isinstancer   r9   r?   r8   r   byteshasattrgetattrr   r   PNGr   JPEGGIFWEBPHEICget	Exception)r5   current_pos
bytes_dataimage_type_strtype_mapping	file_types         r(   get_image_content_type,ImageEditRequestUtils.get_image_content_typeU   s   7	1*g..(oo/"'__
 ,J77(oo/"'__S1
,J..'-
 :v..")*fi"H"JKz622"*!+!5Jz622"4*8<<88 ,J7N%&x||44  || ||  L %((8I &x||44"9-- 	1"8<<00	1s%   EH !$H A8H ?H !H,+H,r;   )NN)__name__
__module____qualname____firstlineno__staticmethodstrr   r   r   boolr   r   r)   r   r3   rU   __static_attributes__r;   r<   r(   r   r      s    
 '+6:33$73 %C3 d^	3
 !)c 33 
3 3j ES#XE	'E E$ A13 A13 A1 A1r<   r   )ior   r   typingr   r   r   r   r	   r
   r   (litellm.litellm_core_utils.token_counterr   /litellm.llms.base_llm.image_edit.transformationr   litellm.types.filesr   r   litellm.types.images.mainr   r   r;   r<   r(   <module>re      s)    & B B  C O 9 DL1 L1r<   