Ë
    uPêjá  ã                   ó|   — d dl mZmZ d dlmZmZmZmZ d dlZd dl	m
Z
 d dlmZ d dlmZmZ d dlmZ  G d„ d	«      Zy)
é    )ÚBufferedReaderÚBytesIO)ÚAnyÚFinalÚcastÚget_type_hintsN)Úget_image_type)ÚBaseImageEditConfig)ÚFILE_MIME_TYPESÚFileType)ÚImageEditOptionalRequestParamsc                   óŒ   — e Zd Ze	 	 ddededededz  dee   dz  de	fd„«       Z
ed	e	eef   defd
„«       Zededefd„«       Zy)ÚImageEditRequestUtilsNÚmodelÚimage_edit_provider_configÚimage_edit_optional_paramsÚdrop_paramsÚadditional_drop_paramsÚreturnc           	      ó®  — |j                  | «      }t        j                  du xs |du }t        |«      }|r|D ]  }|j	                  |d«       Œ |D �cg c]	  }||vsŒ|‘Œ }	}|	rH|r|	D ]  }|j	                  |d«       Œ n,t        j
                  | d| › ddj                  |	«      › �¬«      ‚|j                  t        t        |«      | |¬«      }
|
S c c}w )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              úY/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/images/utils.pyÚget_optional_params_image_editz4ImageEditRequestUtils.get_optional_params_image_edit   s  € ð* #=×"XÑ"XÐY^Ó"_Ðä$×0Ñ0°DÐ8ÒO¸KÈ4Ð<Oˆä*.Ð/IÓ*JÐ Ù!Ø/ò :�Ø(×,Ñ,¨U°DÕ9ð:ð 9QÖ$r¨uÐTYÐaqÒTq¢UÐ$rÐÐ$ráÙØ/ò >�EØ,×0Ñ0°¸Õ=ñ>ô ×4Ñ4ØØSÐTYÐSZÐZ\Ð]a×]fÑ]fÐgyÓ]zÐ\{Ð|ôð ð
  :×KÑKÜ'+Ô,JÐLdÓ'eØØ#ð  Ló  
ˆð Ðùò% %ss   Á	CÁCÚparamsc                 ó¾   — t        t        «      j                  «       }| j                  «       D ��ci c]  \  }}||v sŒ|€Œ||“Œ }}}t	        t        |«      S c c}}w )a  
        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_paramz=ImageEditRequestUtils.get_requested_image_edit_optional_param>   sY   € ô +Ô+IÓJ×OÑOÓQˆ
Ø39·<±<³>×!g©4¨1¨aÀQÈ*Â_ÐYZÑYf ! Q¡$Ð!gˆÑ!gÜÔ2°OÓDÐDùó "hs   ±A¾AÁAÚ
image_datac                 ó  — 	 t        | t        «      rD| j                  «       }| j                  d«       | j	                  d«      }| j                  |«       nìt        | t
        «      rD| j                  «       }| j                  d«       | j	                  d«      }| j                  |«       n˜t        | t        «      r| dd }n‚t        | d«      r_ t        | dd„ «      «       }t        | d«      r| j                  d«       | j	                  d«      }t        | d«      r)| j                  |«       nt        t        j                     S t        |«      }|€t        t        j                     S t        j                  t        j                  t        j                  t        j                  t        j                   dœ}|j#                  |«      }|€t        t        j                     S t        |   S # t$        $ r t        t        j                     cY S w xY w)	a  
        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                   ó   — y)Nr   © r6   ó    r%   ú<lambda>z>ImageEditRequestUtils.get_image_content_type.<locals>.<lambda>o   s   � r7   Úseek)ÚpngÚjpegÚgifÚwebpÚheic)Ú
isinstancer   r4   r9   r3   r   ÚbytesÚhasattrÚgetattrr   r   ÚPNGr	   ÚJPEGÚGIFÚWEBPÚHEICÚgetÚ	Exception)r0   Úcurrent_posÚ
bytes_dataÚimage_type_strÚtype_mappingÚ	file_types         r%   Úget_image_content_typez,ImageEditRequestUtils.get_image_content_typeO   sš  € ð5	1ä˜*¤gÔ.à(Ÿo™oÓ/�Ø—‘ Ô"Ø'Ÿ_™_¨SÓ1�
à—‘ Õ,Ü˜J¬Ô7à(Ÿo™oÓ/�Ø—‘ Ô"Ø'Ÿ_™_¨SÓ1�
à—‘ Õ,Ü˜J¬Ô.Ø'¨¨Ð-‘
ô ˜: vÔ.Ø"H¤'¨*°f¹iÓ"HÓ"J�KÜ˜z¨6Ô2Ø"Ÿ™¨Ô*Ø!+§¡°Ó!5�JÜ˜z¨6Ô2Ø"Ÿ™¨Õ4ä*¬8¯<©<Ñ8Ð8ô %3°:Ó$>ˆNàÐ%Ü&¤x§|¡|Ñ4Ð4ô  —|‘|Ü Ÿ™Ü—|‘|Ü Ÿ™Ü Ÿ™ñ#ˆLð  ,×/Ñ/°Ó?ˆIØÐ Ü&¤x§|¡|Ñ4Ð4ä" 9Ñ-Ð-øäò 	1ä"¤8§<¡<Ñ0Ò0ð	1ús%   ‚D?G' Å#G' Å&A7G' ÇG' Ç' H
È	H
)NN)Ú__name__Ú
__module__Ú__qualname__ÚstaticmethodÚstrr
   r   ÚboolÚlistr   r&   r   r/   rO   r6   r7   r%   r   r      sµ   „ Øð
 $(Ø37ñ/Øð/à$7ð/ð %Cð/ð ˜D‘[ð	/ð
 !% S¡	¨DÑ 0ð/ð 
ò/ó ð/ðb ðEØ�S˜#�X‘ðEà	'òEó ðEð  ð?1¨3ð ?1°3ò ?1ó ñ?1r7   r   )Úior   r   Útypingr   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   r6   r7   r%   ú<module>r]      s)   ðß &ß 3Ó 3ã Ý CÝ Oß 9Ý D÷D1ò D1r7   