
    hF                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZ  G d de j                        Z
dedefd	Zd
ededefdZdee   defdZy)    N)PathLike)Optional)	FileTypesOpenAIFilesPurposec                   (     e Zd Zdedef fdZ xZS )InMemoryFilecontentnamec                 2    t         |   |       || _        y N)super__init__r
   )selfr	   r
   	__class__s      \/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/router_utils/batch_utils.pyr   zInMemoryFile.__init__
   s    !	    )__name__
__module____qualname__bytesstrr   __classcell__)r   s   @r   r   r   	   s     S  r   r   purposereturnc                     | dk(  ryy)z
    Check if the model name should be replaced in the JSONL file for the deployment model name.

    Azure raises an error on create batch if the model name for deployment is not in the .jsonl.
    batchTF )r   s    r   should_replace_model_in_jsonlr      s     'r   file_contentnew_model_namec                 ~   	 t        | t              r| S t        | d      r| j                         }nt        | t              r| d   }n| }t        |t
              r|j                  d      }nt        |t              r|}n| S |j                         }g }|D ]U  }t        j                  |j                               }d|v r||d   d<   |j                  t        j                  |             W dj                  |      j                  d      }t!        |d      S # t        j"                  t$        t&        f$ r | cY S w xY w)	Nread   zutf-8bodymodel
zmodified_file.jsonl)r
   )
isinstancer   hasattrr"   tupler   decoder   
splitlinesjsonloadsstripappenddumpsjoinencoder   JSONDecodeErrorUnicodeDecodeError	TypeError)	r   r    file_content_bytesfile_content_strlinesmodified_lineslinejson_objectmodified_file_contents	            r   replace_model_in_jsonlr=      s2   )lH- <(!-!2!2!4e,!-a!- (%0188A*C01 ++-D**TZZ\2K $/=F#G, !!$**["9:  !%		. 9 @ @ I18MNN  "4i@ s   D A+D  BD  D<;D<function_namec                 N     t        g d      } rt         fd|D              ryy)z
    Helper to return what the "metadata" field should be called in the request data

    For all /thread or /assistant endpoints we need to call this "litellm_metadata"

    For ALL other endpoints we call this "metadata
    )r   generic_api_call_acreate_batchfile!_ageneric_api_call_with_fallbacksc              3   &   K   | ]  }|v  
 y wr   r   ).0methodr>   s     r   	<genexpr>z5_get_router_metadata_variable_name.<locals>.<genexpr>T   s      $*-s   litellm_metadatametadata)setany)r>   %ROUTER_METHODS_USING_LITELLM_METADATAs   ` r   "_get_router_metadata_variable_namerM   I   s4     -0d-)  .S  "r   )ior,   osr   typingr   litellm.types.llms.openair   r   BytesIOr   boolr   r   r=   rM   r   r   r   <module>rT      sk    	    C2:: 

	
* *C *I *Zhsm  r   