
    gJ                         d dl Z d dlmZmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ dee   defdZdee   defd	Zd
ededee   defdZy)    N)DictListOptional)Request
UploadFilestatus)verbose_proxy_logger)
Deploymentrequestreturnc                   K   	 | i S t        |       }|j                  dd      }d|v r!t        | j                          d{         S | j	                          d{   }|si S |j                         }t        j                  |      S 7 I7 /# t        j                  $ r t        j                  d       i cY S t        $ r0}t        j                  dj                  |             i cY d}~S d}~ww xY ww)z
    Safely read the request body and parse it as JSON.

    Parameters:
    - request: The request object to read the body from

    Returns:
    - dict: Parsed request data as a dictionary or an empty dictionary if parsing fails
    N)r   zcontent-type formzInvalid JSON payload received.z*Unexpected error reading request body - {})_safe_get_request_headersgetdictr   bodydecodejsonloadsJSONDecodeErrorr	   	exception	Exceptionformat)r   _request_headerscontent_typer   body_stres         b/var/www/openai/venv/lib/python3.12/site-packages/litellm/proxy/common_utils/http_parsing_utils.py_read_request_bodyr    
   s     ?I!:7!K'++NB?\!glln,-- !'D 	 {{}H ::h'' - (  &&'GH	 &&8??B	
 	s   C7B C7:B BB 
C7B BB &C7'$B C7B B *C4:C7<C4%C/)C4*C7/C44C7c                     	 | i S t        | j                        S # t        $ r0}t        j                  dj                  |             i cY d}~S d}~ww xY w)z7
    [Non-Blocking] Safely get the request headers
    Nz-Unexpected error reading request headers - {})r   headersr   r	   debugr   )r   r   s     r   r   r   6   sS    ?IGOO$$ "";BB1E	
 		s     	A%A	AArequest_datafilerouter_model_namesc                 l   ddl m}m}m}m} |j
                  xs d}|dz  }d| vri | d<   || d   d<   d}	|W| d   |v rP	 |j                  | d         }
|
r8|
j                  ,|
j                  j                  |
j                  j                  }	|	pt        j                  d
||	       |s1 |d|j                  j                   t         j"                  dd      ||	kD  r! |d| d|	 dt         j"                  dd      y# t        $ r)}t        j                  d	t        |             Y d}~d}~ww xY w)z
    Check if any files passed in request are under max_file_size_mb

    Returns True -> when file size is under max_file_size_mb limit
    Raises ProxyException -> when file size is over max_file_size_mb limit or not a premium_user
    r   )CommonProxyErrorsProxyException
llm_routerpremium_useri   metadatafile_size_in_mbNmodel)model_group_namez%Got error when checking file size: %sz=Checking file size, file content size=%s, max_file_size_mb=%sz:Tried setting max_file_size_mb for /audio/transcriptions. bad_requestr%   )messagecodetypeparamzGFile size is too large. Please check your file size. Passed file size: z MB. Max file size: z MBT)litellm.proxy.proxy_serverr(   r)   r*   r+   size"get_deployment_by_model_group_namelitellm_paramsmax_file_size_mbr   r	   errorstrr#   not_premium_uservaluer   HTTP_400_BAD_REQUEST)r$   r%   r&   r(   r)   r*   r+   file_contents_sizefile_content_size_in_mbr9   
deploymentr   s               r   check_file_size_under_limitrB   E   s     a0K@%#%Z 2IL./,w"7;M"M	==%1'%: >   --9-->>J#-#<#<#M#M  #""K#	

  TUfUwUwU}U}T~00"	  #%55 abyaz  {O  P`  Oa  ad  e00"	  5  	 &&7#a& 	s   AD 	D3
D..D3)r   typingr   r   r   fastapir   r   r   litellm._loggingr	   litellm.types.routerr
   r    r   r   r;   boolrB        r   <module>rJ      s}     ' ' / / 1 +)hw&7 )D )Xx'8 T @@
@ S	@ 
	@rI   