
    h                     |    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Dictcastget_type_hintsN)get_image_type)BaseImageEditConfig)FILE_MIME_TYPESFileType)ImageEditOptionalRequestParamsc            	       l    e Zd Zededede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
)ImageEditRequestUtilsmodelimage_edit_provider_configimage_edit_optional_paramsreturnc           	          |j                  |       }|D cg c]  }||vr|
 }}|r,t        j                  | d|  ddj                  |             |j	                  || t        j
                        }|S c c}w )aS  
        Get optional parameters for the image edit API.

        Args:
            params: Dictionary of all parameters
            model: The model name
            image_edit_provider_config: The provider configuration for image edit API

        Returns:
            A dictionary of supported parameters for the image edit API
        z5The following parameters are not supported for model z: z, )r   message)r   r   drop_params)get_supported_openai_paramslitellmUnsupportedParamsErrorjoinmap_openai_paramsr   )r   r   r   supported_paramsparamunsupported_paramsmapped_paramss          P/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/images/utils.pyget_optional_params_image_editz4ImageEditRequestUtils.get_optional_params_image_edit   s    ( 6QQRWX
 4
,, 
 
 00OPUwVXY]YbYbcuYvXwx  3DD'A++ E 
 '
s   A7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_param8   s_     $$BCHHJ
#\\^
QqJ1=AqD
 
 2ODD	
s   AAA
image_datac                    	 t        | t              rD| j                         }| j                  d       | j	                  d      }| j                  |       nt        | t
              rD| j                         }| j                  d       | j	                  d      }| j                  |       nt        | t              r| dd }nt        | 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    r1       r    <lambda>z>ImageEditRequestUtils.get_image_content_type.<locals>.<lambda>n   s    ar2   seek)pngjpeggifwebpheic)
isinstancer   r/   r4   r.   r   byteshasattrgetattrr   r   PNGr	   JPEGGIFWEBPHEICget	Exception)r+   current_pos
bytes_dataimage_type_strtype_mapping	file_types         r    get_image_content_typez,ImageEditRequestUtils.get_image_content_typeL   s   7	1*g.(oo/"'__
 ,J7(oo/"'__S1
,J.'-
 :v."H'*fi"H"JKz62"*!+!5Jz62"4*8<<88 ,J7N%&x||44  || ||  L %((8I &x||44"9-- 	1"8<<00	1s%   D?G' #G' &A7G' G' ' H
	H
N)__name__
__module____qualname__staticmethodstrr
   r   r   r!   r   r*   rJ   r1   r2   r    r   r      s    ))$7) %C) 
	) )V ES#XE	'E E& A13 A13 A1 A1r2   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   r1   r2   r    <module>rV      s)    & 2 2  C O 9 DC1 C1r2   