
    g                         d dl Z d dlZd dlmZmZmZ  G d de j                        Zdeeee	ee	f   f   de	dee   fdZ
de	fd	Zy)
    N)OptionalTupleUnionc                   (     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      U/var/www/openai/venv/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   file_contentnew_model_namereturnc                 0   	 t        | d      r| j                         }nt        | t              r| d   }n| }t        |t              r|j                  d      }n|}|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 Y y w xY w)	Nread   zutf-8bodymodel
zmodified_file.jsonl)r	   )hasattrr   
isinstancetupler   decode
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_jsonlr6      s   ! <(!-!2!2!4e,!-a!- (%0188A1 ++-D**TZZ\2K $/=F#G, !!$**["9:  !%		. 9 @ @ I18MNN  "4i@ s   C1C4 4DDc                     d| v 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
    batchlitellm_metadatametadata )function_names    r   "_get_router_metadata_variable_namer=   3   s     -!r   )ior%   typingr   r   r   BytesIOr   r   r   r6   r=   r;   r   r   <module>rA      se    	  ) )2:: $uS%_556$HK$l$N r   