
    ^hjM             D       l   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKJr  S SKJrJrJr  S SKJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJr  S SK r S SK!r!S SK"r"S SK#r#S SK$J%r%  S SK&J'r'  S SK(r(S S	K(J)r)J*r*J+r+J,r,J-r-  S S
K.J/r/  S SK0J)r1  S SK2J3r3J4r4  S SK5J6r6  S SK7J8r8J9r9  S SK:J;r;  S SK<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrFJGrGJHrHJIrIJJrJJKrKJLrLJMrMJNrNJOrO  SSKPJQrQ  SSKRJSrSJTrTJUrU  SSKVJWrW  SSKXJYrYJZrZJ[r[J\r\J]r]J^r^  SSK_J`r`  SSKaJbrbJcrcJdrd  SSKeJfrf  SSKgJhrh  SSKiJjrjJkrk  SSKlJmrm  SSKnJoro  SSKpJqrq  SSKrJsrsJtrt  SSKuJvrv  SS KwJxrx  SS!KyJzrz  SS"K{J|r}  SS#K~Jr  SS$KJrJr  SS%KJr  SS&KJr  SS'KJrJr  SS(KJr  SS)KJr  SS*KJr  SS"KJ|r  SS+KJr  SS,KJr  SS-KJr  SS.KJr  SS/KJr  SS0KJr  SS"KJ|r  SS1KJr  SS*KJr  SS2KJr  SS3KJr  SS4KJr  SS5KJr  SS6KJr  SS7KJr  SS8KJr  SS9KJr  SS:KJr  SS;KJr  SS<KJr  SS=KJr  SS"KJ|r  SS>KJr  SS?KJr  SS@KJrJrJrJrJrJr  SSAKJrJrJrJrJrJrJr  \#GR                  " SB5      rS SCK<JrJrJrJrJrJrJrJrJr  \" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\q" 5       r\f" 5       r\j" 5       r\m" 5       r\o" 5       r\h" 5       r\" 5       r\" 5       r\z" 5       r\t" 5       r\s" 5       r\v" 5       r\x" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r " SD SE5      Gr  " SF SG5      Gr " SH SI5      Gr " SJ SK5      Gr\*/ SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS4 SLG\SM\SN\\   SO\G\   SP\\G\G\4      SQ\G\   SR\G\   SS\G\   ST\G\   SU\G\   SV\G\   SW\G\   SX\\\      SY\\   SZ\\   S[\G\   S\\G\   S]\G\   S^\G\   S_\\G\\\%   4      S`\G\   Sa\\   Sb\G\   Sc\G\   Sd\G\   Se\G\   Sf\G\   Sg\G\   Sh\G\   Si\G\	   Sj\G\   Sk\\\=4   4@Sl jj5       Gr
Sm Gr      SSLG\SM\ST\G\   SS\G\   So\G\G\G\4   Sp\\   4Sq jjGr\*/ SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS4 SLG\SM\SP\\G\G\\!GR                  4      SQ\G\   SR\G\   SS\G\   ST\G\   SU\G\   SW\G\   SV\G\   SX\\\      SY\\   SZ\\   S[\G\   S\\G\   S]\G\   S^\G\   S_\\G\\\%   4      S`\G\   Sa\\   Sb\\G\G\4      Sd\G\   Se\G\   Sc\G\   Sj\G\   SN\\   SO\G\   Sf\G\   Sg\G\   Sh\G\   Si\G\	   Sk\\\=4   4@Sr jj5       rSs GrSt Gr\*Sk\4Su j5       Gr\*/ SSSvSSSSSnSSSS4Sw\G\   Sx\G\   Sy\G\   Sg\G\   Sh\G\   Sz\G\   S{G\S^\G\   Sk\4S| jj5       Gr\*Sk\\\4   4S} j5       Gr\*                     SS~\G\\\G\\\G\\G\   4      4      4   SL\G\   S\G\   S\G\   S\\G\   S]\\G\G\4      Sd\G\   SV\G\   SS\G\   S[\G\   S\\G\\G\   4      ST\G\   SU\G\   S\G\   SQ\G\   SR\G\   S^\G\   Sy\G\   Sg\G\   Sh\G\   Si\G\	   S\G\   4,S jj5       GrSG\Sk\\\%\4      4S jGrSG\Sk\\\%\4      4S jGr SSG\SL\G\   Sh\G\   4S jjGr\* SSG\SL\G\   Sh\G\   4S jj5       Gr\*Sk\4S j5       Gr\*            SS~G\SL\G\   SS\G\   S\G\   S_\G\   S\G\   S\G\   S^\G\   Sh\G\   Sy\G\   Sg\G\   Sk\4S jj5       Gr\*Sk\4S j5       Gr\*            SSLG\S\S\G\   S~\G\   S_\\S      S\\\S         SQ\G\   S^\G\   Sh\G\   Sy\G\   Sg\G\   S\G\   Sk\4S jj5       Gr\*Sk\4S j5       Gr\*               SSLG\SG\S\\G\G\4      Sh\G\   Sy\G\   Sg\G\   S\G\   S\G\   S\G\   S\G\   SP\\G\\!GR                  4      S_\G\   S\G\   S\G\   S\G\   S\G\   Sk\4"S jj5       GrSLG\SG\SG\SkG\4S jGr    SSG\S\\S      S~\G\   S\\   SG\4
S jjGr S Gr!S Gr" SSG\	SM\\   Sk\4S jjGr# SSG\	SM\G\	   Sk\\\\4      4S jjGr$g)    N)futures)FIRST_COMPLETEDThreadPoolExecutorwait)deepcopy)partial)
AnyCallableDictListLiteralMappingOptionalTypeUnioncast)	BaseModel)overload)Loggingclientexception_typeget_litellm_paramsget_optional_params)CustomLogger)r   )mock_embeddingmock_image_generation)get_content_from_model_response)AsyncHTTPHandlerHTTPHandler)get_secret_str)CustomStreamWrapperUsageasync_completion_with_fallbacks#async_mock_completion_streaming_objcompletion_with_fallbacks convert_to_model_response_objectcreate_pretrained_tokenizercreate_tokenizerget_api_keyget_llm_providerget_optional_params_embeddingsget_optional_params_image_gen!get_optional_params_transcription
get_secretmock_completion_streaming_objread_config_argssupports_httpx_timeouttoken_counter!validate_chat_completion_messages   )verbose_logger)disable_cacheenable_cacheupdate_cache)get_completion_messages)custom_promptfunction_call_promptmap_system_message_pt	ollama_ptprompt_factory stringify_json_tool_call_content)ChunkProcessor)basetenmaritalkollama_chat)AnthropicChatCompletion)AzureAudioTranscription)AzureChatCompletion_check_dynamic_azure_params)AzureOpenAIO1ChatCompletion)AzureTextCompletion)AzureAIEmbedding)BedrockConverseLLM
BedrockLLM)BedrockEmbedding)BedrockImageGeneration)CodestralTextCompletion)handler)BaseLLMHTTPHandler)	CustomLLMcustom_chat_llm_router)DatabricksChatCompletion)DatabricksEmbeddingHandler)aleph_alphapalm)GroqChatCompletion)Huggingface)
completion)	oobabooga)OpenAITextCompletion)OpenAIChatCompletion)OpenAIAudioTranscription)OpenAILikeChatHandler)OpenAILikeEmbeddingHandler)PredibaseChatCompletion)SagemakerChatHandler)SagemakerLLM)TogetherAITextCompletion)vertex_ai_non_gemini)	VertexLLM)GoogleBatchEmbeddings)VertexImageGeneration)VertexMultimodalEmbedding)VertexTextToSpeechAPI)VertexAIPartnerModels)VertexEmbedding)VertexAIModelGardenModels)WatsonXChatHandler)IBMWatsonXAI)ChatCompletionAssistantMessageChatCompletionAudioParamChatCompletionModality$ChatCompletionPredictionContentParamChatCompletionUserMessageHttpxBinaryResponseContent)AdapterCompletionStreamWrapperChatCompletionMessageToolCallCompletionTokensDetails	FileTypesHiddenParamsPromptTokensDetailsall_litellm_paramscl100k_base)	ChoicesEmbeddingResponseImageResponseMessageModelResponseTextChoicesTextCompletionResponseTextCompletionStreamWrapperTranscriptionResponsec                       \ rS rSrSSSS\R
                  SS.S\\   S\\   S\\   S\\	   S	\\
\\4      4
S
 jjrSrg)LiteLLM   NX  )api_keyorganizationbase_urltimeoutmax_retriesdefault_headersr   r   r   r   r   c                T    [        5       U l        [        U R                  S S9U l        g )N
router_obj)localsparamsChatchat)selfr   r   r   r   r   r   s          F/home/james-whalen/.local/lib/python3.13/site-packages/litellm/main.py__init__LiteLLM.__init__   s     h6	    )r   r   )__name__
__module____qualname____firstlineno__litellmnum_retriesr   strfloatintr   r   __static_attributes__ r   r   r   r      sv     &*"&#&%,%8%87;7 sm	7
 3-7 %7 c]7 "'#s("347 7r   r   c                   (    \ rS rSrS\\   4S jrSrg)r      r   c                     Xl         U R                   R                  SS5      SL a5  U R                   R                  S5        [        U R                   US9U l        g [        U R                   US9U l        g )NacompletionFTr   )r   getpopAsyncCompletionscompletionsCompletionsr   r   r   s      r   r   Chat.__init__   sZ    ;;??=%0D8KKOOM*EU
FD  +4;;:NDr   )r   r   N)r   r   r   r   r   r	   r   r   r   r   r   r   r      s    O8C= Or   r   c                   2    \ rS rSrS\\   4S jrSS jrSrg)r      r   c                     Xl         X l        g Nr   r   r   s      r   r   Completions.__init__       $r   Nc                 8   UR                  5        H  u  pEXPR                  U'   M     U=(       d    U R                  R                  S5      nU R                  b*  U R                  R                  " SX!S.U R                  D6nU$ [	        SX!S.U R                  D6nU$ Nmodelr   messagesr   )itemsr   r   r   rZ   r   r   r   kwargskvresponses          r   createCompletions.create   s    LLNDAKKN #11??&11 26++H
  "PPDKKPHr   r   r   	r   r   r   r   r   r	   r   r   r   r   r   r   r   r          %8C= %
r   r   c                   2    \ rS rSrS\\   4S jrSS jrSrg)r   i  r   c                     Xl         X l        g r   r   r   s      r   r   AsyncCompletions.__init__	  r   r   Nc                 h  #    UR                  5        H  u  pEXPR                  U'   M     U=(       d    U R                  R                  S5      nU R                  b2  U R                  R                  " SX!S.U R                  D6I S h  vN nU$ [	        SX!S.U R                  D6I S h  vN nU$  N' N7fr   )r   r   r   r   r   r   s          r   r   AsyncCompletions.create  s     LLNDAKKN #11??&!__88 26++ H
  )WuW4;;WWH Xs$   BB2B. B2'B0(B20B2r   r   r   r   r   r   r   r     r   r   r   r   r   	functionsfunction_callr   temperaturetop_pnstreamstream_options
max_tokensmax_completion_tokens
modalities
predictionaudiopresence_penaltyfrequency_penalty
logit_biasuserresponse_formatseedtoolstool_choiceparallel_tool_callslogprobstop_logprobsr   api_versionr   
model_listextra_headersreturnc!           	        #    U!R                  SS5      n"[        R                  " 5       n#U!R                  SS5      n$0 SU _SU_SU_SU_SU_S	U_S
U_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_0 SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S U_S!U_S"U_S#U_S$U _S%S&_En%U$c  [        U U%R                  S S5      S'9u  n&n$  n&U"=(       d    [        R
                  n"U"b)  [        SU0 U%DS(SU"00D6I Sh  vN n'U'c  [        S)5      eU'$  [        [        40 U%DU!D6n([        R                  " 5       n)[        U)R                  U(5      n*U$S*:X  Gd  U$S+:X  Gd  U$S,:X  Gd  U$S-:X  Gd   U$S.:X  d  U$S/:X  d  U$S0:X  d  U$S1:X  d  U$S2:X  d  U$S3:X  d  U$S4:X  d  U$S5:X  d  U$S6:X  d  U$S7:X  d  U$S8:X  d  U$S9:X  d  U$S::X  d  U$S;:X  d  U$S<:X  d  U$S=:X  d  U$S>:X  d  U$S?:X  d  U$S@:X  d  U$SA:X  d  U$SB:X  d  U$SC:X  d|  U$SD:X  dv  U$SE:X  dp  U$SF:X  dj  U$SG:X  dd  U$SH:X  d^  U$SI:X  dX  U$SJ:X  dR  U$SK:X  dL  U$SL:X  dF  U$SM:X  d@  U$SN:X  d:  U$SO:X  d4  U$SP:X  d.  U$SQ:X  d(  U$[        R                  ;   d  U$[        R                  ;   a  U#R                  SU*5      I Sh  vN n+[!        U+["        5      (       d  [!        U+[$        5      (       a#  [!        U+["        5      (       a  [%        SU0 U+D6n'U+n'O([        R&                  " U+5      (       a  U+I Sh  vN n'OU+n'U$S?:X  d  U$S=:X  aK  [!        U'[(        5      (       a6  [        R*                  " 5       R-                  U'[        R$                  " 5       SR9n'OU#R                  SU*5      I Sh  vN n'[!        U'[.        5      (       a  U'R1                  U#SS9  U'$  GN GN N N2! [         a  n,U$=(       d    S*n$[3        U U$U,U%U!ST9eSn,A,ff = f7f)Va  
Asynchronously executes a litellm.completion() call for any of litellm supported llms (example gpt-4, gpt-3.5-turbo, claude-2, command-nightly)

Parameters:
    model (str): The name of the language model to use for text completion. see all supported LLMs: https://docs.litellm.ai/docs/providers/
    messages (List): A list of message objects representing the conversation context (default is an empty list).

    OPTIONAL PARAMS
    functions (List, optional): A list of functions to apply to the conversation messages (default is an empty list).
    function_call (str, optional): The name of the function to call within the conversation (default is an empty string).
    temperature (float, optional): The temperature parameter for controlling the randomness of the output (default is 1.0).
    top_p (float, optional): The top-p parameter for nucleus sampling (default is 1.0).
    n (int, optional): The number of completions to generate (default is 1).
    stream (bool, optional): If True, return a streaming response (default is False).
    stream_options (dict, optional): A dictionary containing options for the streaming response. Only use this if stream is True.
    stop(string/list, optional): - Up to 4 sequences where the LLM API will stop generating further tokens.
    max_tokens (integer, optional): The maximum number of tokens in the generated completion (default is infinity).
    max_completion_tokens (integer, optional): An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
    modalities (List[ChatCompletionModality], optional): Output types that you would like the model to generate for this request. You can use `["text", "audio"]`
    prediction (ChatCompletionPredictionContentParam, optional): Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.
    audio (ChatCompletionAudioParam, optional): Parameters for audio output. Required when audio output is requested with modalities: ["audio"]
    presence_penalty (float, optional): It is used to penalize new tokens based on their existence in the text so far.
    frequency_penalty: It is used to penalize new tokens based on their frequency in the text so far.
    logit_bias (dict, optional): Used to modify the probability of specific tokens appearing in the completion.
    user (str, optional):  A unique identifier representing your end-user. This can help the LLM provider to monitor and detect abuse.
    metadata (dict, optional): Pass in additional metadata to tag your completion calls - eg. prompt version, details, etc.
    api_base (str, optional): Base URL for the API (default is None).
    api_version (str, optional): API version (default is None).
    api_key (str, optional): API key (default is None).
    model_list (list, optional): List of api base, version, keys
    timeout (float, optional): The maximum execution time in seconds for the completion request.

    LITELLM Specific Params
    mock_response (str, optional): If provided, return a mock completion response for testing or debugging purposes (default is None).
    custom_llm_provider (str, optional): Used for Non-OpenAI LLMs, Example usage for bedrock, set model="amazon.titan-tg1-large" and custom_llm_provider="bedrock"
Returns:
    ModelResponse: A response object containing the generated completion and associated metadata.

Notes:
    - This function is an asynchronous version of the `completion` function.
    - The `completion` function is called using `run_in_executor` to execute synchronously in the event loop.
    - If `stream` is True, the function returns an async generator that yields completion lines.
	fallbacksNcustom_llm_providerr   r   r   r   r   r   r   r   r   r   stopr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   deployment_idr   r   r   r   r   r   Tr   api_baser   z]No response from fallbacks. Got none. Turn on `litellm.set_verbose=True` to see more details.openaiazure
azure_textcustom_openaianyscalemistral
openrouter	deepinfra
perplexitygroq
nvidia_nimcohere_chatcoherecerebras	sambanova	ai21_chatai21
volcengine	codestraltext-completion-codestraldeepseektext-completion-openaihuggingfaceollamarC   	replicate	vertex_aivertex_ai_betagemini	sagemakersagemaker_chat	anthropicanthropic_text	predibasebedrock
databrickstritonclarifaiwatsonx
cloudflareresponse_objectmodel_response_object)loopr   r   original_exceptioncompletion_kwargsextra_kwargsr   )r   asyncioget_event_loopr*   r   model_fallbacksr#   	Exceptionr   rZ   contextvarscopy_contextrunopenai_compatible_providers_custom_providersrun_in_executor
isinstancedictr   iscoroutiner   OpenAITextCompletionConfig%convert_to_chat_model_response_objectr!   set_logging_event_loopr   )-r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  _r   funcctxfunc_with_contextinit_responsees-                                                r   r   r     s_    h 

;-I!!#D **%:DA##H# 	Y# 		#
 	7# 	{# 	# 	Q# 	&# 	.# 	# 	j# 	 !6# 	j# 	j#  	!#" 	,##$ 	.%#& 	j'#( 	)#* 	?+#, 	-#. 	/#0 	{1#2 	23#4 	H5#6 	7#8 	9#: 	H;#< 	{=#> 	7?#@ 	jA#B 	C#D 	tE#H "'7"3"7"7
D"I(
$1 4W44I8 

)4i(@
 
 o  X
zA%6A&A &&(#CGGT2  8+"g-"l2"o5"j0"i/"l2"k1"l2"f,"l2"m3"h."j0"k1"k1"f,"l2"k1"&AA"j0"&>>"m3"h."m3"k1"k1"&66"h."k1"&66"k1"&66"k1"i/"l2"h."j0"i/"l2"g&I&II"g&?&??"&"6"6t=N"OOM-..*}3 3 mT22,=}=H($$]33!..( $'??&*EEX'=>>"==?ee$,*1*?*?*A f  "11$8IJJHh 344++ ,  q
z P / K  
1=X 3 /
 	

so   C6O8N9OE.N <N=A1N .N/A4N #N$)N ON N N 
N?"N::N??Oc                  #     [        SU  35        [        R                  " U 5      (       a
  U I S h  vN n U   S h  vN n[        SU 35        U7v   M   N$ N
 g ! [         a  nU=(       d    Sn[	        UUUS9eS nAff = f7f)Nz'received response in _async_streaming: zline in async streaming: r   )r   r   r  )print_verboser  r+  r"  r   )r   r   r   argsliner4  s         r   _async_streamingr9    s     
?zJKx((%~H" 	$5dV<=J &	(  
1=X 3 
 	

sS   B.A AA AAAA AA B
B'A==BBFmock_responsemock_tool_callsc                 >    Ub  UR                  USS9  [        U[        5      (       a  [        U[        R                  5      (       a  Ue[
        R                  " [        USS5      [        US[        U5      5      [        USU=(       d    S5      U [        R                  " S	S
S9S9e[        U[        5      (       a0  US:X  a*  [
        R                  " S[        USU=(       d    S5      U S9e[        U[        5      (       a0  US:X  a*  [
        R                  " S[        USU=(       d    S5      U S9e[        U[        5      (       aA  UR                  S5      (       a+  [
        R                  " SUSU [        R                  " S	S
S9S9e[        U[        5      (       a-  UR                  S5      (       a  [
        R                  " SSU SS9nUR                  SS5      n	U	b  [        R                   " U	5        [        U["        5      (       a  [%        S00 UD6$ [%        US9n
USL a=  UR                  SS5      SL a  ['        [)        XXS9U SUS 9$ ['        [+        XXS9U SUS 9$ [        U[
        R                  5      (       a  UeUc  XJR,                  S!   R.                  l        Oe/ n[3        U5       HN  n[
        R4                  R7                  U[
        R4                  R9                  US"S#9S$9nUR;                  U5        MP     Xl        [=        [        R                  " 5       5      U
l        X
l         U(       a8  U Vs/ s H  n[C        S00 UD6PM     snU
R,                  S!   R.                  l"        [G        U
S%[I        S&S'S(S)95         [
        R4                  RK                  U S*9u  p  nXzRL                  S+'   Ub  URO                  US,S-S.9  U
$ s  snf ! [         a     N'f = f! [         a1  n[        U[        R                  5      (       a  Ue[        S/5      eSnAff = f)1a@  
Generate a mock completion response for testing or debugging purposes.

This is a helper function that simulates the response structure of the OpenAI completion API.

Parameters:
    model (str): The name of the language model for which the mock response is generated.
    messages (List): A list of message objects representing the conversation context.
    stream (bool, optional): If True, returns a mock streaming response (default is False).
    mock_response (str, optional): The content of the mock response (default is "This is a mock request").
    **kwargs: Additional keyword arguments that can be used but are not required.

Returns:
    litellm.ModelResponse: A ModelResponse simulating a completion response with the specified model, messages, and mock response.

Raises:
    Exception: If an error occurs during the generation of the mock completion response.
Note:
    - This function is intended for testing or debugging purposes to generate mock completion responses.
    - If 'stream' is True, it returns a response that mimics the behavior of a streaming completion.
Nzmock-key)inputr   status_code  textllm_providerr   POSTzhttps://api.openai.com/v1/)methodurl)r>  messagerA  r   requestzlitellm.RateLimitErrorzthis is a mock rate limit error)rE  rA  r   zlitellm.InternalServerErrorz$this is a mock internal server errorz Exception: content_filter_policyi  r   zException: mock_streaming_errorz&This is a mock error raised mid-streamr  i  )rE  rA  r   r>  
mock_delayr   Tr   F)r:  r   r   completion_streamr   r   logging_objr   	assistant)contentrole)indexrE  usage
         prompt_tokenscompletion_tokenstotal_tokensr   r   zmy-secret-keyzmy-original-responser=  r   original_responsezMock completion response failedr   )(pre_callr)  r"  r   APIErrorr   MockExceptiongetattrr   httpxRequestRateLimitErrorInternalServerError
startswithr   timesleepr*  r   r!   r$   r/   choicesrE  rM  rangeutilsr~   r   appendr   createdr   rw   
tool_callssetattrr"   r*   _hidden_params	post_call)r   r   r   r   r:  r;  loggingr   r   
time_delaymodel_response_all_choicesi_choice	tool_callr/  r4  s                    r   mock_completionrv    s3   @F;"   mY//-99##''#M=#Fvs=7IJ$!>3F3R( V9UV  }c**}@X/X((9$!>3F3R(   }c**!>>-->$!>3F3R(   s++0H0H.1
 1
 ''%$V9UV  s++0H0H-1
 1
 $11@(	M ZZd3
!JJz"mT** 1=11&f5T>zz-/47*&I&5'  (0 '  '"?"u# $,#  mW%:%:;;98E""1%--5L1X!--//#MM11 -K 2  0  ##G,  &2"!$TYY[!1$ "1<!0I .:	:!0<N""1%--8
 	brJ	
	+2==+I+IPU+I+V(AAqCV))*?@
 '"8  
 1<  		  ;a))G9::;sa   HO! 6O! O! !CO! <O5O! /O 6O! O! 
OO! OO! !
P+,PPc!                 `   [        5       n"U!R                  SS5      n#U!R                  SS5      n$U!R                  SS5      n%U!R                  SS5      n&U!R                  SS5      n'U!R                  SS	5      n(U!R                  S
S5      n)U!R                  SS5      n*U!R                  SS5      n+U!R                  SS5      n,U!R                  SS5      n-U!R                  SS5      n.U!R                  SS5      n/U!R                  SS5      =(       d    Un0U!R                  SS5      n1U!R                  SS5      n2U!R                  SS5      n3U0c  0 n0Ub  U0R                  U5        U!R                  SS5      n4U!R                  SS5      n5U!R                  SS5      n6U!R                  SS5      n7U!R                  SS5      n8U!R                  SS5      n9U!R                  SS5      n:U!R                  SS5      n;U!R                  SS5      n<U!R                  SS5      n=U!R                  SS5      n>U!R                  S S5      n?U!R                  S!S5      n@U!R                  S"S5      nAU!R                  S#S5      nBU!R                  S$S5      nCU!R                  S%S5      nDU!R                  S&S5      nEU!R                  S'S	5      nFU!R                  S(S	5      nGU!R                  S)S	5      nHU!R                  S*S5      nIU!R                  S+S	5      nJ[        [        [
           U!R                  S,S5      5      nK[        [        [           U!R                  S-S5      5      nL[        UU1=(       d    S	U2U3S.9n/ S/QnMUM[        -   nN0 nOU!R                  5        VPVQs0 s H  u  nPnQUPWN;  d  M  WPWQ_M     nRnPnQ[        U*[        5      (       a  WKb  U*R                  U UWRU0WKWLS09u  pnS Ub  Un#U4b  U4n5U*nTU/=(       d    [        R                  n/U/b  [        GSF0 U"D6$ U b9  U  VUs/ s H  nUUUS1   U :X  d  M  WUS2   PM     nVnU[        R                   " GSFS3UV0U"D6$ [        R"                  (       a'  U [        R"                  ;   a  [        R"                  U    n [%        5       nW['        UWS4[        R(                  " 5       5        U!R                  S5S	5      S6L a  S5n)Ub  Un S5n)[+        U U)U#US79u  n n)nXn#WWb?  [-        WWS85      (       a.  U)WWR.                  S
'   U!R                  S9S5      UWR.                  S:'   [1        US;9nU=(       d    U!R                  S<S5      =(       d    Sn[        U[2        R4                  5      (       a&  [7        U)5      (       d  UR8                  =(       d    SnO*[        U[2        R4                  5      (       d  [;        U5      nU9b%  U:b"  [        R<                  " U) S=U  3U9U:U)S>.05        O&U;b#  U<n<[        R<                  " U) S=U  3U;U<U)S?.05        0 nYU=(       d  U>(       d  U?(       d  W@(       d  WA(       aO  U 0 0nYU=(       a  U=WYU    S'   U>(       a  U>WYU    S'   U?(       a  U?WYU    S '   W@(       a  W@WYU    S!'   WA(       a  WAWYU    S"'   WDb#  [        WD[>        5      (       a  WDS	L a	  [A        US;9nWXb  WXn[C        GSF0 S@U_SAU_SBU_SCU_SDU_SEU_SFU_SGU_SHU
_SIU	_SJU_SKU_SLU_SMU_SNU_SOU_SPU_SQU _S
U)_SRU_SSU_STU_SUU_SU5_SVU_SWU_SXU_SYU_SZU_WRD6nS[        RD                  (       a2  WSR                  S[S5      (       a  WSRG                  S[5      nZ[I        UUZS\9n[K        GSF0 S)WH_S]U_SU&_SU'_SU(_S
U)_SU#_S^U!R                  S^S5      _S_[        R"                  _S`U+_SU,_SU-_SU._S#WB_SaWJ_SU;_SU9_SU<_SU:_SU6_S'U!R                  S'5      _SbU!R                  Sb5      _SU!R                  S5      _S&WE_ScU!R                  Sc5      _S$WC_SdWY_6nOWTRM                  U UWSUOU)Se9  U$(       d  U%(       a"  [O        U UUUU$U%WTWHU!R                  SfS5      U)Sg9
$ U)S5:X  Ga  S	n[WIbJ  [        WI[P        RR                  5      (       d  [        WI[P        RT                  5      (       a  [W        SXU0WISh9n[[Y        Si5      =(       d    S5n\U#=(       d"    [        RZ                  =(       d    [Y        Sj5      n#U=(       d9    [        R\                  =(       d"    [Y        Sk5      =(       d    [        R^                  nU=(       dK    [        R`                  =(       d4    [        Rb                  =(       d    [Y        Sl5      =(       d    [Y        Sm5      nWSR                  Sn0 5      RG                  SoS5      =(       d    [Y        Sp5      n]U0=(       d    [        Rd                  n0Ub  UWSSq'   [        Rf                  (       a  [        Rh                  " 5       Rk                  U Sr9(       an  [        Rh                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M     [n        Rq                  U UU0UU#UW\W[W]WW[r        WSWOU'WTWHUWISs9n_Om[        Rt                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M     [v        Rq                  U UU0UU#UW\W[W]WW[r        WSWOU'WTWHUWISs9n_WSR                  SES	5      (       a  WTRy                  UUW_U0UU#St.Su9  W_$ U)Sv:X  Ga  [Y        Si5      =(       d    S5n\U#=(       d"    [        RZ                  =(       d    [Y        Sj5      n#U=(       d"    [        R\                  =(       d    [Y        Sk5      nU=(       dK    [        R`                  =(       d4    [        Rb                  =(       d    [Y        Sl5      =(       d    [Y        Sm5      nWSR                  Sn0 5      RG                  SoS5      =(       d    [Y        Sp5      n]U0=(       d    [        Rd                  n0Ub  UWSSq'   [        Rt                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M     [z        Rq                  U UU0UU#UW\W]WW[r        WSWOU'WTWHUWISw9n_USR                  SES	5      (       d  WHS6L a  WTRy                  UUW_U0UU#St.Su9  W_$ U)Sx:X  GaG  U#=(       d"    [        RZ                  =(       d    [Y        Sy5      n#U=(       d9    [        R`                  =(       d"    [        R|                  =(       d    [Y        Sz5      nU0=(       d    [        Rd                  n0Ub  UWSSq'   [        R~                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M     S{U ;   a	  [        US;9n [        Rq                  U UU0WW[r        UU#WHWTWSWOU'UWYWIU8U)WRR                  S|5      S}9n_WSR                  SES	5      (       a  WTRy                  UUW_SU00Su9  W_$ U)S~:X  d6  SU ;   d0  SU ;   d*  U)[        R                  ;   GaY  U!R                  S'5      S6L GaD  S[P        lD        U#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#S[P        l.        U=(       d9    [        R`                  =(       d"    [        R|                  =(       d    [Y        S5      nU0=(       d    [        Rd                  n0Ub  UWSSq'   [        R                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M     [        R                  (       a  [        R                  [P        lF        [        U5      S:  a-  SUS   ;   a$  [        US   S   [        5      (       a	  US   S   naO%SR                  U Vbs/ s H  nbUbS   PM
     snb5      naU)S:X  a$  [        Rq                  U UWW[r        UU#WHWIWTWSWOU'US9ncO#[        Rq                  U UWW[r        UU#WHWIWTWSWOU'US9ncWSR                  SES	5      S	L a-  WHS	L a(  WFS	L a#  [        R                  " 5       R                  WcWWS9ncWSR                  SES	5      (       d  WHS6L a  WTRy                  UUWcSU00Su9  Wcn_U_$ U)S:X  Ga  U#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#U=(       d9    [        R`                  =(       d"    [        R                  =(       d    [Y        S5      nU0=(       d    [        Rd                  n0[        R                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M     [        Rq                  U UU0WW[r        UU#WHWTWSWOU'UWYWIU)[        S9n_U_$ U [        R                  ;   dc  U)S:X  d]  U)S:X  dW  U)S:X  dQ  U)S:X  dK  U)S:X  dE  U)S:X  d?  U)S:X  d9  U)S:X  d3  U)S:X  d-  U)S:X  d'  U)S:X  d!  U)S:X  d  U)[        R                  ;   d  SU ;   Gap  U#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#U8=(       d+    [        R                  =(       d    [Y        S5      =(       d    Sn8U8[P        lF        U=(       d9    [        R`                  =(       d"    [        R|                  =(       d    [Y        S5      nU0=(       d    [        Rd                  n0Ub  UWSSq'   [        R                  Rm                  5       n^U^R                  5        H  u  nPnQUPWS;  d  M  WQWSWP'   M      [        Rq                  U UU0WW[r        UU#WHWTWSWOU'UWYWIU8U)S9n_WSR                  SES	5      (       a  WTRy                  UUW_SU00Su9  W_$ SU ;   d  U)S:X  d  U [        R                  ;   a  U=(       dK    [        R                  =(       d4    [        R`                  =(       d    [Y        S5      =(       d    [Y        S5      ndU#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#WY=(       d    [        R                  nY[        U UU#WW[r        WSWOU'[        WdWTUYWHU0S9nWUSR                  SES	5      S6L a  WTRy                  UWdWWS9  WWn_U_$ SU ;   d  U)S:X  d  U [        R                  ;   a  SneU=(       dK    [        R                  =(       d4    [        R`                  =(       d    [Y        S5      =(       d    [Y        S5      neU#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#[        R                  " 5       R                  U U#5      n#[        Rq                  U US6UWHU#WWWSWOSUU0[        WeWTS9n_U_$ U)S:X  a  U=(       dM    [        R                  =(       d6    [        R`                  =(       d    [        R                  R                  S5      nWY=(       d    [        R                  nYU#=(       d=    [        RZ                  =(       d&    [Y        S5      =(       d    [Y        S5      =(       d    Sn#U#b  U#R                  S5      (       d  U#S-  n#[        Rq                  U UUWHU#WWWSWOSUU0[        UWTS9n_U_$ U)S:X  Ga=  U=(       dM    [        R                  =(       d6    [        R`                  =(       d    [        R                  R                  S5      nWY=(       d    [        R                  nYU#=(       d=    [        RZ                  =(       d&    [Y        S5      =(       d    [Y        S5      =(       d    Sn#U#b  U#R                  S5      (       d  U#S-  n#[        Rq                  U UU#WH[        R                  WW[r        WSWOU'[        UWTU0UWIU)S9n_USR                  SES	5      (       d  WHS6L a  WTRy                  UUW_S9  W_n_U_$ U)S:X  a  U=(       d9    [        R                  =(       d"    [Y        S5      =(       d    [        R`                  nfU#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#[        U UU#WW[r        WSWOU'[        WfWTS9n_SEUS;   a  WSSE   S6L a  [        W_U SWTS9n_WSR                  SES	5      (       d  WHS6L a  WTRy                  UUW_S9  W_n_U_$ U)S:X  a  U=(       dK    [        R                  =(       d4    [Y        S5      =(       d"    [Y        S5      =(       d    [        R`                  ngU#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#[        Rp                  " U UU#WW[r        WSWOU'[        [        R                  WgWTS9nWSEUS;   a  WSSE   S6L a  [        WWU SWTS9n_U_$ WWn_U_$ U)S:X  a  U=(       dK    [        R                  =(       d4    [Y        S5      =(       d"    [Y        S5      =(       d    [        R`                  nhU#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#U0=(       d    [        Rd                  =(       d    0 n0U0c  0 n0Ub  U0R                  U5        [        Rq                  U UUWHU#WWWSWOSUU0[        WhWTWIS9n_U_$ U)S:X  a  U=(       dK    [        R                  =(       d4    [        S5      =(       d"    [        S5      =(       d    [        R`                  nhU#=(       d+    [        RZ                  =(       d    [        S5      =(       d    Sn#U0=(       d    [        Rd                  =(       d    0 n0U0c  0 n0Ub  U0R                  U5        [        Rq                  U UUWHU#WWWSWOSUU0[        WhWTS9n_U_$ U)S:X  a  U=(       d9    [        R                  =(       d"    [Y        S5      =(       d    [        R`                  niU#=(       d+    [        RZ                  =(       d    [Y        S5      =(       d    Sn#[        Rq                  U UU#WW[r        WSWOU'[        WiWTSWYS9nWUWn_U_$ U)S:X  Ga  Sn)U=(       ds    [        R                  =(       d\    [        R                  R                  S5      =(       d6    [        R                  R                  S5      =(       d    [        R`                  njU0=(       d    [        Rd                  nkWY=(       d    [        R                  nY[        Rq                  U UU#Wk=(       d    0 WW[r        WSWOU'[        WjWHWTWYUWIS9nWSEUS;   a  WSSE   S6L a  WHS	L a  [        WWU SWTS9n_U_$ WWn_U_$ U)S:X  aH  Sn)[        Rp                  " U UWWU#[r        WSWOSU'[        WTS9nWSEUS;   a  WSSE   S6L a  [        WWU SWTS9n_U_$ WWn_U_$ U)S:X  a  U#=(       d-    [        RZ                  =(       d    [        R                  " S5      n#U=(       d9    [        R`                  =(       d"    [        R                  =(       d    [Y        S5      nU0=(       d    [        Rd                  n0 [        Rq                  U UU0WW[r        UU#WHWTWSWOU'UWYWI[        SS9n_WSR                  SES	5      (       a  WTRy                  UUW_SU00Su9  W_$ U)S:X  Ga  U#=(       d    [        RZ                  =(       d    Sn#U=(       dK    [        R`                  =(       d4    [        R                  =(       d    [Y        S5      =(       d    [Y        S5      n[Y        S5      =(       d    Snl[Y        S5      =(       d    SnmWlUmS.nnU0=(       d    [        Rd                  noUo(       a  WnR                  Wo5        Wnn0[        R                  Rm                  5       n^U^R                  5        H<  u  nPnQUPSn:X  a#  SnWS;   a  WSWP   R                  WQ5        M(  WQWSWP'   M/  WPWS;  d  M7  WQWSWP'   M>     XS.WSEnp[        Rq                  U UU0UU#WW[r        USWOU'WTWHUSS9n_UTRy                  U[P        R`                  U_S9  U_$ U)S:X  d  SU ;   d  U [        R                  ;   a    W_$ U)S:X  a  [        S5      eU)S:X  d  U)S:X  Ga\  WSRG                  SS5      =(       d;    WSRG                  SS5      =(       d"    [        R                  =(       d    [Y        S5      nqWSRG                  SS5      =(       d;    WSRG                  SS5      =(       d"    [        R                  =(       d    [Y        S5      nrWSRG                  SS5      =(       d$    WSRG                  SS5      =(       d    [Y        S5      nsU=(       d4    [Y        S5      =(       d"    [Y        S5      =(       d    [        R`                  nt[        WS5      nu[        Rq                  U UWW[r        UuWOU'[        WrWqWsUtWTWHUU)WIU#US9n_U_$ U)S:X  GaZ  WSRG                  SS5      =(       d;    WSRG                  SS5      =(       d"    [        R                  =(       d    [Y        S5      nqWSRG                  SS5      =(       d;    WSRG                  SS5      =(       d"    [        R                  =(       d    [Y        S5      nrWSRG                  SS5      =(       d$    WSRG                  SS5      =(       d    [Y        S5      ns[        WS5      nuU R                  S5      (       dX  U R                  S5      (       dB  U R                  S5      (       d,  U R                  S5      (       d  U R                  S5      (       a-  [        Rq                  U UWW[r        WuWOU'[        U#WrWqWsWTWHU0WYUWIS9nWOSU ;   d  WOR                  S&5      b7  SWOS&   ;   a.  [        Rq                  U UWW[r        WuWOU'[        WrWqWsSWTWHUU)WIU#US9nWO|SU ;   a-  [        Rq                  U UWW[r        WuWOU'[        U#WrWqWsWTWHU0WYUWIS9nWOI[        Rp                  " U UWW[r        WuWOU'[        WrWqWsWTWHS9nWSEWS;   a  WSSE   S6L a  WHS	L a  [        WWU SWTS9n_U_$ WWn_U_$ U)S:X  GaH  WSRG                  SS5      =(       d;    WSRG                  SS5      =(       d"    [        R                  =(       d    [Y        S5      nvUvc  [        S5      eU#=(       dV    WSRG                  SS5      =(       d=    WSRG                  GS S5      =(       d#    [        RZ                  =(       d    [Y        GS5      n#U=(       d:    [        R`                  =(       d#    [        R                  =(       d    [Y        GS5      nG[         Rq                  U UWW[r        WSWOU'[        WTWHU#WYUWvUGS9nwSEUS;   a  WSSE   S6L a  WHS	L a  Ww$ Wwn_U_$ U)GS:X  a  U#=(       dM    WSRG                  SS5      =(       d4    WSRG                  GS S5      =(       d    [        RZ                  =(       d    GSn#U=(       d#    [        R`                  =(       d    [Y        GS5      n[        GR                  " UGS9nxG[        Rq                  U UUx[r        WSWOU'[        WTWHU#WYUUGS9nwSEUS;   a  WSSE   S6L a  WHS	L a  Ww$ Wwn_U_$ U)GS	:X  a+  G[        Rq                  U UWW[r        WSWOWYU'[        WTWHGS
9nWUWn_U_$ U)GS:X  a,  G[        Rq                  U UWW[r        WSWOWYWCU'[        WTWHGS9nWUWn_U_$ U)GS:X  Ga  WY=(       d    [        R                  nYGSWS;   a  G[
        GR                  " GS5        WSRG                  GS5      nyUyGR                  5       GR                  5       nzUzGR                  (       a  WzGR                  WSGS'   WzGR                  (       a  WzGR                  WSGS'   WzGR                  (       a  WzGR                  WSGS'   S9WS;  d  WSS9   c  WyGR                  GR                  WSS9'   [        GR                  " 5       GR                  U 5      nEUE[        GR                   ;   d  U R                  GS5      (       aA  U GR#                  GSGS5      n G[$        Rq                  U UWYWW[r        WSWOU'[        WTUUWHWIU#GS9n_O@U GR#                  GSGS5      n G[&        Rq                  U UWYWW[r        WSWOU'[        WTUUWHWIU#GS9n_WSR                  SES	5      (       a  WTRy                  USW_S9  W_n_U_$ U)GS:X  a/  G[(        Rq                  U UU0WW[r        UU#WHWTWSWOU'UWYWI[        GSS9n_U_$ U)GS:X  a  WY=(       d    [        R                  nYG[*        Rq                  U UUYWW[r        WSWOU'[        WTUWHGS9n_SEUS;   a4  WSSE   S6L a,  [        W_[        5      (       d  [        G[-        W_5      U GSWTS9n_WSR                  SES	5      (       a  WTRy                  USW_S9  W_n_U_$ U)GS:X  aa  WY=(       d    [        R                  nYG[.        Rp                  " U UUYWW[r        WSWOU'[        WTGS9
nWSEUS;   a  WSSE   S6L a  [        WWU GSWTS9n_U_$ WWn_U_$ U)GS:X  a^  [        RZ                  =(       d    U#=(       d    [Y        GS5      =(       d    GSn#[        Rq                  U UUWHU#WWWSWOGSUU0[        UWTWIS9n_U_$ U)GS:X  a  [        RZ                  =(       d    U#=(       d    [Y        GS5      =(       d    GSn#U=(       dO    [        GR0                  =(       d7    [        R                  R                  GS 5      =(       d    [        R`                  nG[2        GR4                  " U#UU UWSWTWHWW[        GS!9	n{UHS6L d  WSR                  SES	5      S6L a  W{$ W{n_U_$ U)GS":X  a?  [        RZ                  =(       d    U#n#[        Rq                  U UUWHU#WWWSWOU)UU0[        UWTS9n_U_$ U)GS#:X  a  U=(       d;    [        GR6                  =(       d#    [        R`                  =(       d    [Y        GS$5      n[Y        GS%5      n|U#=(       d2    [        RZ                  =(       d    [Y        GS&5      =(       d    GS'W| GS(3n#WY=(       d    [        R                  nY[        Rq                  U UUWHU#WWWSWOGS#UU0[        UWTS9n_U_$ U)GS):X  d  [        RZ                  GS*:X  a  GS)n)U=(       dO    [        GR8                  =(       d7    [        R                  R                  GS+5      =(       d    [        R`                  n}G[:        Rp                  " U UWW[r        WSWOU'[        U}WTGS,9
nWG[<        GR>                  " UW5      (       d  SEWS;   a  WSSE   S6L a  [        WWU GS)WTS9n_U_$ WWn_U_$ U)GS-:X  d  U [        GR@                  ;   a~  U#=(       d    [        RZ                  n#GS-n)WSRG                  SES	5      nG[B        Rp                  " U UU#WW[r        USWOU'[        WTWIGS.9nWUS6L a  WWGS/   S   GS0   S   n~[        U~U GS-WTS9n_U_$ WWn_U_$ U)GS1:X  Ga  [        RZ                  =(       d    U#=(       d    GSnUb  WGS:X  a  [        GS25      e SR                  U Vbs/ s H  nbUbS   PM
     snb5      na[        GRD                  GRG                  WU Ua/U
UUU!R                  GS3GS45      GS5.GS6.GS79nUGRI                  5       n UGS8   S   GS9   S   nUWWGRJ                  S   GRL                  l        G[Q        G[R        GRR                  " 5       5      UWl        U UWl        UWn_U_$ U)[        GRX                  ;   a  Sn[        GRZ                   H  nUGS:   U):X  d  M  WGS;   nM     Wc  [        GS<U" 35      eG[]        WHUWGS=9nU0=(       d    [        Rd                  n0W" GSF0 SQU _SZU_SU0_GS>WW_GS?[r        _S]U_SU#_S)WH_GS@WT_GSAWS_S2WO_SU'_GSBU_SdWY_S*WI_GSC[        _6n_US6L a  [        W_U U)WTGSD9$  W_$ [        GS<U" 35      es  snQnPf s  snUf ! [         a$  n`WTRy                  UU[        U`5      SU00Su9  U`eSn`A`ff = fs  snbf ! [         a$  n`WTRy                  UU[        U`5      SU00Su9  U`eSn`A`ff = f! [         a$  n`WTRy                  UU[        U`5      SU00Su9  U`eSn`A`ff = fs  snbf ! [         a  n`G[_        U U)U`U"U!GSE9eSn`A`ff = f(G  a  
Perform a completion() using any of litellm supported llms (example gpt-4, gpt-3.5-turbo, claude-2, command-nightly)
Parameters:
    model (str): The name of the language model to use for text completion. see all supported LLMs: https://docs.litellm.ai/docs/providers/
    messages (List): A list of message objects representing the conversation context (default is an empty list).

    OPTIONAL PARAMS
    functions (List, optional): A list of functions to apply to the conversation messages (default is an empty list).
    function_call (str, optional): The name of the function to call within the conversation (default is an empty string).
    temperature (float, optional): The temperature parameter for controlling the randomness of the output (default is 1.0).
    top_p (float, optional): The top-p parameter for nucleus sampling (default is 1.0).
    n (int, optional): The number of completions to generate (default is 1).
    stream (bool, optional): If True, return a streaming response (default is False).
    stream_options (dict, optional): A dictionary containing options for the streaming response. Only set this when you set stream: true.
    stop(string/list, optional): - Up to 4 sequences where the LLM API will stop generating further tokens.
    max_tokens (integer, optional): The maximum number of tokens in the generated completion (default is infinity).
    max_completion_tokens (integer, optional): An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
    modalities (List[ChatCompletionModality], optional): Output types that you would like the model to generate for this request.. You can use `["text", "audio"]`
    prediction (ChatCompletionPredictionContentParam, optional): Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.
    audio (ChatCompletionAudioParam, optional): Parameters for audio output. Required when audio output is requested with modalities: ["audio"]
    presence_penalty (float, optional): It is used to penalize new tokens based on their existence in the text so far.
    frequency_penalty: It is used to penalize new tokens based on their frequency in the text so far.
    logit_bias (dict, optional): Used to modify the probability of specific tokens appearing in the completion.
    user (str, optional):  A unique identifier representing your end-user. This can help the LLM provider to monitor and detect abuse.
    logprobs (bool, optional): Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message
    top_logprobs (int, optional): An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.
    metadata (dict, optional): Pass in additional metadata to tag your completion calls - eg. prompt version, details, etc.
    api_base (str, optional): Base URL for the API (default is None).
    api_version (str, optional): API version (default is None).
    api_key (str, optional): API key (default is None).
    model_list (list, optional): List of api base, version, keys
    extra_headers (dict, optional): Additional headers to include in the request.

    LITELLM Specific Params
    mock_response (str, optional): If provided, return a mock completion response for testing or debugging purposes (default is None).
    custom_llm_provider (str, optional): Used for Non-OpenAI LLMs, Example usage for bedrock, set model="amazon.titan-tg1-large" and custom_llm_provider="bedrock"
    max_retries (int, optional): The number of retries to attempt (default is 0).
Returns:
    ModelResponse: A response object containing the generated completion and associated metadata.

Note:
    - This function is used to perform completions() using the specified language model.
    - It supports various optional parameters for customizing the completion behavior.
    - If 'mock_response' is provided, a mock completion response is returned for testing or debugging.
r   Nr:  r;  force_timeoutr   	logger_fnverboseFr   litellm_logging_objidmetadata
model_infoproxy_server_requestr   headersensure_alternating_rolesuser_continue_messageassistant_continue_messager   r   cooldown_timecontext_window_fallback_dictr   input_cost_per_tokenoutput_cost_per_tokeninput_cost_per_secondoutput_cost_per_secondinitial_prompt_valuerolesfinal_prompt_value	bos_token	eos_tokenpreset_cache_keyhf_model_namesupports_system_message
base_modeltext_completionatext_completionr   r   zno-log	prompt_idprompt_variables)r   r  r  r  )$r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   request_timeoutr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   non_default_paramsr  r  r  
model_namelitellm_paramsdeploymentsrP  r   Tr   r   r   r   rm  aws_region_nameregion_name)r   r  /r  r  litellm_providerr  r  r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   functions_unsupported_model)r   r   r   litellm_call_idmodel_alias_mapcompletion_call_idno_logazure_ad_token_providerlitellm_trace_idcustom_prompt_dictr   r   optional_paramsr  r   rG  )r   r   r:  r;  ro  r   rG  r   )azure_client_paramsazure_clientAZURE_API_TYPEAZURE_API_BASEAZURE_API_VERSIONAZURE_OPENAI_API_KEYAZURE_API_KEY
extra_bodyazure_ad_tokenAZURE_AD_TOKENr   rX  )r   r   r  r   r   r   api_typedynamic_paramsr  rq  r6  r  r  ry  rK  r   r   r   )r  r   r   )r=  r   rZ  additional_argsr   )r   r   r  r   r   r   r  r  rq  r6  r  r  ry  rK  r   r   r   azure_aiAZURE_AI_API_BASEAZURE_AI_API_KEYz	command-rdrop_params)r   r   r  rq  r6  r   r   r   rK  r  r  ry  r   r  r   r   r   r  r  zft:babbage-002zft:davinci-002r   OPENAI_API_BASEhttps://api.openai.com/v1OPENAI_API_KEYr   rM   together_ai)r   r   rq  r6  r   r   r   r   rK  r  r  ry  r   r  r   GROQ_API_BASEzhttps://api.groq.com/openai/v1GROQ_API_KEY)r   r   r  rq  r6  r   r   r   rK  r  r  ry  r   r  r   r   encodingr   r   r   r   r   r   r  r  r   r   zft:gpt-3.5-turboOPENAI_ORGANIZATION)r   r   r  rq  r6  r   r   r   rK  r  r  ry  r   r  r   r   r   r  REPLICATE_API_KEYREPLICATE_API_TOKENREPLICATE_API_BASEzhttps://api.replicate.com/v1)r   r   r   rq  r6  r  r  ry  r  r   rK  r  r   r  rY  r  CLARIFAI_API_KEYCLARIFAI_API_TOKENCLARIFAI_API_BASEzhttps://api.clarifai.com/v2)r   r   fake_streamr   r   r   rq  r  r  r   r   r  r  r   rK  r  ANTHROPIC_API_KEYANTHROPIC_API_BASEANTHROPIC_BASE_URLz%https://api.anthropic.com/v1/completez/v1/complete)r   r   r   r   r   rq  r  r  r   r   r  r  r   rK  r  z%https://api.anthropic.com/v1/messagesz/v1/messages)r   r   r   r   r  rq  r6  r  r  ry  r  r   rK  r  r   r   r   	nlp_cloudNLP_CLOUD_API_KEYNLP_CLOUD_API_BASEzhttps://api.nlpcloud.io/v1/gpu/)r   r   r   rq  r6  r  r  ry  r  r   rK  )r   rK  rV   ALEPH_ALPHA_API_KEYALEPHALPHA_API_KEYALEPH_ALPHA_API_BASEz$https://api.aleph-alpha.com/complete)r   r   r   rq  r6  r  r  ry  r  default_max_tokens_to_sampler   rK  r   COHERE_API_KEY
CO_API_KEYCOHERE_API_BASEz!https://api.cohere.ai/v1/generate)r   r   r   r   r   rq  r  r  r   r   r  r  r   rK  r   r   zhttps://api.cohere.ai/v1/chatrB   MARITALK_API_KEYMARITALK_API_BASEzhttps://chat.maritaca.ai/api)r   r   r   rq  r6  r  r  ry  r  r   rK  r   r  r  HF_TOKENHUGGINGFACE_API_KEY)r   r   r   r  rq  r6  r  r  ry  r  r   r   rK  r  r   r   r[   )r   r   rq  r   r6  r  r  r   ry  r  rK  r  DATABRICKS_API_BASEDATABRICKS_API_KEY)r   r   r  rq  r6  r   r   r   rK  r  r  ry  r   r  r   r  r   r   zhttps://openrouter.ai/api/v1OPENROUTER_API_KEY
OR_API_KEYOR_SITE_URLzhttps://litellm.aiOR_APP_NAMEliteLLM)zHTTP-RefererzX-Titler   )r   r   r  r   r   rq  r6  r  r  ry  rK  r   r   r   togethercomputerrW   zPalm was decommisioned on October 2024. Please use the `gemini/` route for Gemini Google AI Studio Models. Announcement: https://ai.google.dev/palm_docs/palm?hl=enr
  r  vertex_projectvertex_ai_projectVERTEXAI_PROJECTvertex_locationvertex_ai_locationVERTEXAI_LOCATIONvertex_credentialsvertex_ai_credentialsVERTEXAI_CREDENTIALSGEMINI_API_KEYPALM_API_KEY)r   r   rq  r6  r  r  ry  r  r  r  r  gemini_api_keyrK  r   r   r   r   r   r   r	  zmeta/r  jambaclaude)r   r   rq  r6  r  r  ry  r  r   r  r  r  rK  r   r  r  r   r   )r   r   rq  r6  r  r  ry  r  r  r  r  rK  r   r  	tenant_idpredibase_tenant_idPREDIBASE_TENANT_IDzMissing Predibase Tenant ID - Required for making the request. Set dynamically (e.g. `completion(..tenant_id=<MY-ID>)`) or in env - `PREDIBASE_TENANT_ID`.r   PREDIBASE_API_BASEPREDIBASE_API_KEY)r   r   rq  r6  r  r  ry  r  rK  r   r   r  r   r  r   r  z/https://codestral.mistral.ai/v1/fim/completionsCODESTRAL_API_KEYrH  )r   r   rq  r6  r  r  ry  r  rK  r   r   r  r   r   r  )r   r   rq  r6  r  r  r  ry  r  rK  r   r  )r   r   rq  r6  r  r  r  r  ry  r  rK  r   r  aws_bedrock_clientz'aws_bedrock_client' is a deprecated param. Please move to another auth method - https://docs.litellm.ai/docs/providers/bedrock#boto3---authentication.aws_access_key_idaws_secret_access_keyaws_session_tokenz	converse/ )r   r   r  rq  r6  r  r  ry  r  rK  r   r   r   r   r   zinvoke/r  watsonx_text)r   r   r  rq  r6  r  r  ry  r  rK  r   r   vllm)
r   r   r  rq  r6  r  r  ry  r  rK  r  OLLAMA_API_BASEhttp://localhost:11434rC   OLLAMA_API_KEY)	r   r   r   r   r  rK  r   rq  r  r  r  CLOUDFLARE_API_KEYCLOUDFLARE_ACCOUNT_IDCLOUDFLARE_API_BASEz.https://api.cloudflare.com/client/v4/accounts/z/ai/run/rA   zhttps://app.baseten.coBASETEN_API_KEY)
r   r   rq  r6  r  r  ry  r  r   rK  petals)r   r   r   rq  r6  r  r  ry  r  rK  r   rf  rE  customzGapi_base not set. Set api_base or litellm.api_base for custom endpointstop_k(   )promptr   r   r   r  )r   r   )jsondataoutputprovidercustom_handler8Unable to map your input to a model. Check your input - )async_fnr   
custom_llmrq  r6  rK  r  r   r  rI  r  r   )r   r   updater   r   r   r*  r9   r|   r   r)  LiteLLMLoggingObjget_chat_completion_promptr   r!  r%   batch_completion_modelsr  r   rl  r"   r*   hasattrrm  r3   r_  Timeoutr1   readr   register_modelboolr<   r   add_function_to_promptr   r;   r   update_environment_variablesrv  r   AzureOpenAIAsyncAzureOpenAIrG   r.   r   r   AZURE_DEFAULT_API_VERSIONr   	azure_keyr  enable_preview_featuresAzureOpenAIO1Configis_o1_model
get_configazure_o1_chat_completionsrZ   r6  AzureOpenAIConfigazure_chat_completionsrn  azure_text_completions
openai_keyAzureAIStudioConfigr?   openai_chat_completionsr"  +openai_text_completion_compatible_providersr  r,  r   lenlistjointogether_ai_text_completionsopenai_text_completionsr-  groq_keyGroqChatConfiggroq_chat_completionsr  open_ai_chat_completion_modelsr&  OpenAIConfigreplicate_modelsreplicate_keyr  replicate_chat_completionclarifai_modelsclarifai_keyClarifaiConfig_convert_model_to_urlbase_llm_http_handleranthropic_keyosenvironendswithanthropic_chat_completionsnlp_cloud_keynlp_cloud_chat_completionr!   aleph_alpha_keyrV   r   
cohere_keyr    maritalk_keyopenai_like_chat_completionhuggingface_keyr  r[   getenvdatabricks_keydatabricks_chat_completionsopenrouter_keyOpenrouterConfigtogether_ai_models
ValueErrorr  r  r   vertex_chat_completionrc  %vertex_partner_models_chat_completion#vertex_model_garden_chat_completionre   r  predibase_keypredibase_chat_completionsr   codestral_text_completionssagemaker_chat_completionsagemaker_llmr5   warning_get_credentialsget_frozen_credentials
access_key
secret_keytokenmetar  AmazonConverseConfig_get_base_modelbedrock_converse_modelsreplace bedrock_converse_chat_completionbedrock_chat_completionwatsonx_chat_completion	watsonxaiitervllm_handler
ollama_keyrC   get_ollama_responsecloudflare_api_keybaseten_keyrA   inspectisgeneratorpetals_modelspetals_handlermodule_level_clientpostr  rf  rE  rM  r   rd  rj  r   r'  custom_provider_maprS   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7  r   r:  r;  rx  ry  rz  r   r{  r|  r}  r~  r  r   r  r  r  r  r   r   r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  openai_paramsdefault_paramsr  r   r   r  r  ro  mr  rq  dynamic_api_keyr  r  r  r  r  configr   r4  r  rE  	_responser<  r?  rH  rJ  rK  rL  rN  
hf_headersopenrouter_site_urlopenrouter_app_nameopenrouter_headers_headersr  r  r  r  r  
new_paramsr  _model_responsetext_completion_model_responser  creds	generator
account_idrr  resp_stringrD  respresponse_jsonstring_responser  item
handler_fns                                                                                                                                         r   rZ   rZ     sd6   p 8Dzz*d+HJJ5Mjj!2D9OJJ4M

;-IjjE*G **%:DA **%:DA	D$	Bzz*d+HL$/J!::&<dC

;-IjjD):]G/5zz"D0 BHB LR::$dL  }%**tK **]D1KJJ5M#)::.Ld#S ::nd3L!::&<dC"JJ'>E"JJ'>E#ZZ(@$G!::&<dCJJw%E$8$?

;-I

;-Izz"4d;JJ5M$jj)BDIL$/Jjj!2E:Ozz"4e<**]E2KZZ$'FZZ%(FXc]FJJ{D$ABIHTNFJJ7I4,PQ&!9!BU3#=	H%MN #%77NN'A1N+B1   %'899i>S::!#5#!1 ;  	)j
H"%K%8!8!8	 ,4t44!-7-71\?e;S#"#Z   22S{SdSS""u0G0G'G++E '9JJw&$.")$!E")@P 3	A
="OX %'.BR*S*SCVN))*?@;A::!4<N))-8
 5hG FVZZ(93?F3gu}}--6L7
 7
 ll)cGGU]]33GnG  +0E0Q""*+1UG40D1F,?7 "-%;"""*+1UG41F2H,?7   !"'#DX"5)*@A5:"5)'2!BT"5)*>?9B"5)+69B"5)+6 $/2D99'50,h?H&%G-  
 
' 
 $ 
 	 

  
  
 * 
  
 " 
 #8 
 " 
 " 
  
 . 
 0 
  "! 
" # 
& ' 
( !4) 
* ,+ 
, - 
. / 
0 $1 
2 $3 
4 5 
6 &7 
8 $9 
: !4; 
<  ? 
D ))o.A.A)4/
 /
 +:*=*=-+' ,!-HH
 , 
#

 (
  	

 
 !4
 
 #JJ'8$?
 $33
  "
 
 "
 "6
 .
 
  #8!
" "6#
$ $:%
& #8'
( ()
* #JJ'89+
, %+JJ/H$I-
. #)**-D"E/
0 "1
2 $ZZ(:;3
4 (5
6  27
: 	,,+) 3 	- 	
 O"+ /'!::lD9$7  ') #N!66#5#566ff&=&=>>!<)6(D!'"
 ""23>wHS7#3#3SzBR7SH  5&&5125 44	   /??/$$/ 45/ o.  -00rBFF $ .,-  0G(3@0 ////1==E=J !44??A"LLNDAq0-.*	 + 5??%##% +%#1#1#1"/$3#1' ' +#!% @ , !22==?"LLNDAq0-.*	 + 2<<%##% +%#1#1#1"/$3#1' ' +#!% = * ""8U33!!"#&.#*'2$,%	 " 	Z5 G5 !L0!"23>wHS7#3#3SzBR7SH Uw22UjAT6U 
  /??/$$/ 45/ o.  -00rBFF $ .,-  0G(3@0 ..99;F1_,)*OA&	 ' .88!!'!--+ /-##'# 9 H( ""8U33{d7J!!"#&.#*'2$,%	 " 	R3 2 !J. 3##312   2??2%%2 01	  0G(3@0 00;;=F1_,)*OA&	 ' e#;XN2==%##1"/#% + '$3#1'#'9!!-(; 2 6 6} E% > < ""8U33!!"#&.%.$8	 " |0 o0  #;;5(5("BBC

,-5&FO  /##//0/ /	  "&F  0??0%%0 ./	  0G(3@0 77BBDF1_,)*OA&	 '
 ##&-&:&:# H!!,x{95t<< "!Y/X"NX'79#5X"NO #m38CC%#1"/#% +! '$3#1'# D 	  4>>%#1"/#% +! '$3#1'# ? 	"  ##He4=5(#u, $>>@ff$-^ g 	 ""8U33{d7J!!"#&/%.$8	 "  !H^- ]- !F* 4##4o.4 4	   .??.##. n-	  0G ++668F1_,)*OA&	 ' -77!-+!'# /-##5$7!# 8 Hh, A, W;;;"o5"k1"l2"l2"j0"k1"l2"j0"j0"i/"h."m3"g&I&II!U*
  /##//0/ /	   ''34 	  #/F  0??0%%0 ./	  0G(3@0 ))446F1_,)*OA&	 '2==%##1"/#% + '$3#1'#'9!!-(;# > : ""8U33!!"#&.%.$8	 " V) G) 5 "k1000  5((5??5 125 34   2##2232 2	  "4!Qw7Q7Q6!!-+ /-#!%##5'N" ""8U3t;!!")&4 "  &Hh' e' %"j0///L 4''4??4 014 23   1##1121 1	  --/EEeXVH,77 !'!- /-$.!$# 8 H|& [& !$44 7((7??7 ::>>"56	  "4!Qw7Q7Q ;##;23; 23; ;  #H,=,=n,M,MN*,77!'!- /-$4!# 8 Ht% U% !K/ 7((7??7 ::>>"56	  "4!Qw7Q7Q  ;##;23; 23; ;  #H,=,=n,M,MN*1<<!!'#*#=#=-+ /-#!#$7# = H& ""8U33{d7J!!"#&. " 
  Hv# u# !K/ #((#12# ??	   5##5235 5	  1!!-+ /-#!%#H ?*x/HD/P.(3 '	 ""8U33{d7J!!"#&. "   HX" W" !M1 #**#34# 23# ??   :##:45: :	  )33!!-+ /-#!-4-?-?'#N ?*x/HD/P."(5 '	  %HF! E! !H, #%%#./# l+# ??   7##7/07 7	  66BG(}-,77!'!- /-$,!"# 8 HV  u !M1 #%%#!"23# ",/# ??   3##3!"343 3	  66BG(}-,77!'!- /-$1!"# 8 HF g !J. #''#01# ??	   2##2122 2	  9CC!!-+ /-#!$#$.#5 D N  &Hh g !M1"/ #**#::>>*-# ::>>"78# ??  !3GOOJ!3!Qw7Q7Q(33!!"(b-+ /-#!''##5! 4 N& O+#H-55( /"(5 '	  %HP O !K/"-&11!-!+ /-#!#N ?*x/HD/P."(3 '	  %H^ ] !L0 4##49923   4??4))4 23	  0G6AA%##1"/#% + '$3#1'#'9!%(4# B : ""8U33!!"#&.%.$8	 " x m !L0U7#3#3U7UH  ,??,)), 23, l+  #-]";"S?S",]";"Hy !4."
 1'//H"))(3(G --88:F1$#6'*11!4-.*o-)*OA& ' #LOLD /99!!-+ /-##'$0 : H" (  z s  =0"e+333 d c !F* v  !$448Kx8W##$4d; 2"&&':DA2))2 01	   ##$5t< 3"&&';TB3**3 12	   ##$8$? 6"&&'>E645   #./#n-# ??	  "/2J-88!-+ *-#! 20#5-#'$7!+' 9 Hd y !K/##$4d; 2"&&':DA2))2 01	   ##$5t< 3"&&';TB3**3 12	   ##$8$? 6"&&'>E645  "/2J  ))##I..##K00##G,,##H--!F!Q!Q%#1"/$.#1'%%$6#4'9 ' +#'9#!% "R "( U"""<0<| <<!7!B!B%#1"/$.#1'%$6#4'9#' ' +#(;!%"/' "C "* U"!D!O!O%#1"/$.#1'%%$6#4'9 ' +#'9#!% "P "* "6!@!@%#1"/$.#1'%$6#4'9 ' +"" /'1T9#u,2&,7$+	 H $O%HB A !K/##K6 5"&&'<dC5..5 34	     q 
  4"&&z484"&&z484 ##4 23   3??3((3 12	  9CC!-+ /-#!#'!#5# D O& O+#H-55(&&&HX W !$?? E"&&z48E"&&z48E ##E E  SSJ?R4SG-4-K-K.* 9CC!=+ /-#!#'!#5 D O$ O+#H-55(&&&HJ I !$446AA!-+ /-#5#!#' B N &Hf e !K/*55!-+ /-#5+#!#' 6 N  &H@  !I-!3!Qw7Q7Q#6&& n &5%8%89M%N"*;;=TTV###;@;K;KO$78###?D?O?OO$;<;;;;@;;O$78%_<&'89A +//;; $$56 !557GGNJW<<<@P@PA A k26;FF%'9#1"/$3#1'% '"/# +!% G $ i42==%'9#1"/$3#1'% '"/# +!% > $ ""8U33!!" &. "   Hb a !I-.99!-+!'# /-##5!$-# : H^ y
 !N2!3!Qw7Q7Q ++!#5-+ /-#!#' , H O+#H-5"8-@AA /N(1 '	 ""8U33!!" &. "   Hn	 m	 !F*!3!Qw7Q7Q)44!#5-+ /-#!#N O+0IT0Q /"(. '	   &Ht s !H,   ,,/0, ,	  -77!'!- /-$,!# 8 Hd A !M1   ,,/0, ,	   #%%#::>>"23# ??	  $77!! /#'-!
I d"o&9&9(E&Jd&R   HF C !H,''38H,77!'!- /-$7!# 8 H~ _ !L0 4--4??4 23	  $$;<J Y##Y34Y DJ<xX	  "4!Qw7Q7Q,77!'!- /-$0!# 8 H~ ]  9,#;;"+ #&&#::>>"34# ??	  %//!-+ /-#!##N "">22O+0IT0Q /"(1 '	  %HX W !H,9N9N0N37#3#3H"*$((59F+66!!-+ /-#!#N ~,Y7:9EiP.(0 '	  %H^ ] !H,""4h4"C{cRi ] " XXJgwy1JKF..33"#)(&0'2!&!'GR!8	 4 D !IIKM ,F3A6x@CO8GN""1%--5%(%5N"#(N %Hj g  7#<#<< 37N33
#'::%)*:%;N 4 % NtfU 
 0$VJ 0G " !    .	
 ,   " ( $ !0  . $   $6   "!H$ ~*&.(; '	    J4&Q a?8Z  !!"#&)!f%.$8	 "  J #O\  !!"#&)!f%.$8	 "  ^  !!"#&)!f%.$8	 "  d Kn  
 3 "
 	

s  B~B~3C@= C@= B~	B~"C@= =PC@= ?G4C@= 7A*C@= %AC@= EC@= A#C@= ?CC@= C@= )7B~   ,C@= D!C@= 2BC@= 4BC	C@= BCC@= E5C@= FFC@= L	C@= L('B M,C@= M<DC@= RC5C@= U;C>C@= Y:EC@= ^>C!C@= b CC@= e?C@= fC/C@= i3C.C@= m"B&C@= p	D
C@= tC@= tA	C@= u"C@= u&BC@= w>+C@ x),C@= yD>C@= ~AC@= ,#C@= @E9C@= F
IC@= O'C@= O+E
C@= T6C@= T:CC@= XC@= X1C@= Y2C@= ZHC@= b5C@= b9B-C@= e'A#C@= gC@= gA$C@= h4CC@= lC@= lAC@= mCC@= p$CC@= s<C@= t BC@= vC@= vAC@= w+C@8w:B8C@= z33C@= {*BC@= ~C@= ~C@= ~C@= ~ 
B~*B		BC@= 
C@ B??C@@C@= @
C@5@C@0@0C@5@5C@= @=
CAACAACAc                      SSK nUR                  SS5      nSUS'   SUS'   UR                  SS5      nUR                  S	[        5      nUS
:X  a/  UR	                  UR                  SSS9UR                  U5      SS9nOUR	                  UR                  U5      SS9nU" U/U Q70 UD6$ ! [         a  n[        SU 35      eSnAff = f)z0
Executes a litellm.completion() with 3 retries
r   N?tenacity import failed please run `pip install tenacity`. Errorr      r   retry_strategyconstant_retryoriginal_functionexponential_backoff_retryr4   rQ  
multipliermaxTr   r   reraiser   r  tenacityr"  r   rZ   Retryingwait_exponentialstop_after_attemptr7  r   r  r4  r   r  r  retryers           r   completion_with_retriesr    s   
 **]A.KF=F=MSZZ*NN 

#6
C44##**aR*@,,[9 $ 
 ##,,[94 $ 
 $6t6v66/  
MaSQ
 	

s   B* *
C4CCc                    #     SSK nUR                  SS5      nSUS'   SUS'   UR                  SS5      nUR                  S	[        5      nUS
:X  a/  UR	                  UR                  SSS9UR                  U5      SS9nOUR	                  UR                  U5      SS9nU" U/U Q70 UD6I Sh  vN $ ! [         a  n[        SU 35      eSnAff = f N$7f)zo
[DEPRECATED]. Use 'acompletion' or router.acompletion instead!
Executes a litellm.completion() with 3 retries
r   Nr  r   r  r   r  r  r  r  r4   rQ  r  Tr  r  r  r  s           r   acompletion_with_retriesr    s	    

 **]A.KF=F=ZZ 02BCN

#6
C44##**aR*@,,[9 $ 
 ##,,[94 $ 
 *<T<V<<<)  
MaSQ
 	

( =s4   CB4 B'C/C0C4
C>CCCc            	        #    [         R                  " 5       n[        U 5      S:  a  U S   OUS   nSUS'   Sn [        [        /U Q70 UD6n[
        R                  " 5       n[        UR                  U5      n[        X1R                  SS5      S9u  p  nSn	US:X  d  US	:X  d  US
:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US:X  d  US:X  d~  US:X  dx  US:X  dr  US:X  dl  US:X  df  US:X  d`  US:X  dZ  US:X  dT  US:X  dN  US:X  dH  US:X  dB  US:X  d<  US:X  d6  US:X  d0  US :X  d*  US!:X  d$  US":X  d  US#:X  d  US$:X  d  US%:X  d  US&:X  d  US:X  ay  UR                  SU5      I Sh  vN n
[        U
[        5      (       a  [        S+0 U
D6n	OX[        U
[        5      (       a  U
n	O@[         R                  " U
5      (       a
  U
I Sh  vN n	OUR                  SU5      I Sh  vN n	U	b4  [        U	[        5      (       a  [        U	S'5      (       a  XIR                   S('   U	c  [#        S)5      eU	$  N Nh NO! [$         a  nU=(       d    Sn['        UUUU US*9eSnAff = f7f),a]  
Asynchronously calls the `embedding` function with the given arguments and keyword arguments.

Parameters:
- `args` (tuple): Positional arguments to be passed to the `embedding` function.
- `kwargs` (dict): Keyword arguments to be passed to the `embedding` function.

Returns:
- `response` (Any): The response returned by the `embedding` function.
r   r   T
aembeddingNr   r   r   r   
xinferencevoyager   r   r  r   r   r   r   r   r   r   r   r   r  r  fireworks_air  r	  r  r  r  r   r  r  r  r  openai_likejina_airm  r   zCUnable to get Embedding Response. Please pass a valid llm_provider.r  r   )r  r   r1  r   	embeddingr#  r$  r%  r*   r   r(  r)  r*  r   r+  r  rm  rU  r"  r   )r7  r   r  r   r   r0  r1  r2  r/  r   r3  r4  s               r   r  r    s     !!#D4y1}DG&/EF<N
y24262 &&(#CGGT2'7**Z">(
$1 158+"g-"l2"h."i/"o5"h."j0"l2"k1"l2"f,"l2"j0"k1"k1"l2"j0"n4"h."k1"h."l2"i/"h."m3"i/"j0"m3"m3"i/"h. #'"6"6t=N"OOM-..,=}=M+<==($$]33!.. "11$8IJJH 8%677"233=P##$9:U  + P / K  
1=X 3 "
 	

sa   6I D2H6 +H0,AH6 	H2
H6 $H4%A
H6 /I 0H6 2H6 4H6 6
I III r   
dimensionsencoding_formatr   r  cachingc                    UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S5      nUR                  SS5      nUR                  S	S5      nUR                  S
S5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      n UR                  SS5      n!/ SQn"SS/[        -   n#U"U#-   n$UR                  5        V%V&s0 s H  u  n%n&U%U$;  d  M  U%U&_M     n'n%n&[	        U UUUS9u  pn(nU(b  U(n[        SyU U
UUUS.U'D6n)Ub
  [        U US9$ Ub$  Ub!  [        R                  " U SU  3UUUS.05        U b,  U!=(       d    Sn![        R                  " U SU  3U U!US.05         Sn*Un+U+R                  U U
U)UUUUUUUUS0 US.S9  USL d  US:X  Ga(  [        S 5      =(       d    SnU=(       d"    [        R                  =(       d    [        S!5      nU=(       d9    [        R                  =(       d"    [        S"5      =(       d    [        R                  nU)R                  S#S5      =(       d    [        S$5      n,U=(       d9    [        R                  =(       d"    [        R                  =(       d    [        S%5      nUc  [!        S&5      e["        R%                  U UUUUU,U+U['        5       U)UUUU=(       d    US'9n*G	O[U [        R(                  ;   d  US(:X  d  US):X  d  US*:X  a  U=(       d+    [        R                  =(       d    [        S+5      =(       d    S,n[        R*                  =(       d    [        S-5      =(       d    S[,        l        U=(       d9    [        R                  =(       d"    [        R.                  =(       d    [        S.5      nUb  UU)S'   S(nSn[0        R%                  U UUUU+U['        5       U)UUUS/9n*GOXUS0:X  a  U=(       d"    [        R                  =(       d    [3        S15      nU=(       d9    [        R                  =(       d"    [        R4                  =(       d    [3        S25      n[6        R%                  U UUUU+U['        5       U)UUS39
n*GOUS4:X  d  US5:X  d  US6:X  a  U=(       d"    [        R                  =(       d    [        S75      nU=(       d9    [        R                  =(       d"    [        R8                  =(       d    [        S85      n[:        R%                  U UUUU+U['        5       U)UUS39
n*GOUS9:X  d  US::X  a  U=(       dK    [        R<                  =(       d4    [3        S;5      =(       d"    [3        S<5      =(       d    [        R                  n-Ub  [?        U[@        5      (       a  UnO0 n[B        R$                  " U UU)[D        U-UU+['        5       UUUS=9n*GOqUS>:X  al  U=(       d9    [        RF                  =(       d"    [3        S?5      =(       d    [        R                  n[H        R%                  U U[D        UUU+['        5       U)UUS@9
n*GOUSA:X  aL  [?        U[J        5      (       a  U/n.OUn.[L        RO                  U U.[D        U+U)['        5       UUU0 U[P        USB9n*GOUSC:X  a5  Uc  [!        SD5      e[R        R%                  U UUUUU+U['        5       U)UUSE9n*GOrUSF:X  a\  U=(       d"    [        SG5      =(       d    [        R                  n/[T        RW                  U U[D        U+U)['        5       SSSU[P        SFU/SH9n*GOUSI:X  Ga  U)R                  SJS5      =(       dM    U)R                  SKS5      =(       d4    [        RX                  =(       d    [        SL5      =(       d    [        SM5      n0U)R                  SNS5      =(       dM    U)R                  SOS5      =(       d4    [        RZ                  =(       d    [        SP5      =(       d    [        SQ5      n1U)R                  SRS5      =(       d6    U)R                  SSS5      =(       d    [        ST5      =(       d    [        SU5      n2SVU);   d  SWU);   d  U [\        R^                  ;   a0  [\        Ra                  U U[D        U+U)['        5       U0U1U2U[P        SISX9n*GO[b        R%                  U U[D        U+U)['        5       U0U1U2SIUU[P        USY9n*GOlUSZ:X  a)  [d        R$                  " U U[D        UU+U)['        5       US[9n*GO=US\:X  a  [        R                  =(       d    U=(       d    [        S]5      =(       d    S^n[?        U[J        5      (       a  U/n[g        S_ U 5       5      (       d  [        Rh                  " S`U 3U S\Sa9eUSL a  [j        Rl                  O[j        Rn                  n3U3" UU U[D        U+U)['        5       Sb9n*GO|USc:X  a+  [p        R%                  U U[D        U+U)['        5       [P        Sd9n*GOKUSe:X  aQ  U=(       d"    [        R                  =(       d    [        Sf5      n[0        R%                  U UUUU+U['        5       U)UUS39
n*GOUSg:X  aQ  U=(       d"    [        R                  =(       d    [        Sh5      n[0        R%                  U UUUU+U['        5       U)UUS39
n*GOUSi:X  a'  [R        R%                  U UUUUU+U['        5       U)UUSE9n*GOpUSj:X  a  U=(       d+    [        R                  =(       d    [        Sk5      =(       d    SlnU=(       d+    [        R                  =(       d    [        Sm5      =(       d    Snn[0        R%                  U UUUU+U['        5       U)UUS39
n*OUSo:X  a'  [r        R%                  U U[D        U+U)['        5       UUSp9n*OUSq:X  a  U=(       d"    [        R                  =(       d    [        Sr5      nU=(       d9    [        R                  =(       d"    [        R.                  =(       d    [        Ss5      n[t        R%                  U UUUU+U['        5       U)UUS39
n*O[w        5       n4[!        StU4 35      eU*b   [y        U*Su5      (       a  UU*Rz                  Sv'   U*c  [w        5       n4[!        StU4 35      eU*$ s  sn&n%f ! [|         a+  n5UR                  UU[K        U55      Sw9  [        U U5UUSx9eSn5A5ff = f)za#  
Embedding function that calls an API to generate embeddings for the given input.

Parameters:
- model: The embedding model to use.
- input: The input for which embeddings are to be generated.
- encoding_format: Optional[str] The format to return the embeddings in. Can be either `float` or `base64`
- dimensions: The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
- timeout: The timeout value for the API call, default 10 mins
- litellm_call_id: The call ID for litellm logging.
- litellm_logging_obj: The litellm logging object.
- logger_fn: The logger function.
- api_base: Optional. The base URL for the API.
- api_version: Optional. The version of the API.
- api_key: Optional. The API key to use.
- api_type: Optional. The type of the API.
- caching: A boolean indicating whether to enable caching.
- custom_llm_provider: The custom llm provider.

Returns:
- response: The response received from the API call.

Raises:
- exception_type: If an exception occurs during the API call.
r   Nr   rpmtpmr   r{  r  r:  max_parallel_requestsr~  r}  r  r  r   r  r  r  r  r  )r   r  r  r   r   r   r   r   r   r   r   r   r  r  )r   r   r  r  r   r   r:  r  r  g        r  )r   r   r  ry  r  r~  r}  r  r  stream_responser  )r   r   r  r  Tr  r  r  r  r  r  zPNo API Base provided for Azure OpenAI LLM provider. Set 'AZURE_API_BASE' in .env)r   r=  r   r   r   r  rK  r   rq  r  r   r  r   r  r   r  r   r  r  r  r  )r   r=  r   r   rK  r   rq  r  r   r  r   r  r  r  )
r   r=  r   r   rK  r   rq  r  r   r  r  r  hosted_vllmOPENAI_LIKE_API_BASEOPENAI_LIKE_API_KEYr   r   r  r  )r   r=  r  r  r   r  rK  rq  r  r   r   r  r  )
r   r=  r  r   r   rK  rq  r  r   r  r  )r   r=  r  rK  r  rq  r   r   r  r  r   r6  r   r  z7api_base is required for triton. Please pass `api_base`)r   r=  r   r   r   rK  r   rq  r  r   r  r  r  )r   r=  r  rK  r  rq  r  r  r  r  r6  r   r   r	  r  r  r  VERTEX_PROJECTr  r  r  VERTEX_LOCATIONr  r  r  VERTEX_CREDENTIALSimagevideo)r   r=  r  rK  r  rq  r  r  r  r  r6  r   )r   r=  r  rK  r  rq  r  r  r  r   r   r  r6  r   r[   )r   r=  r  r   rK  r  rq  r   r  r  r  c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r)  r   ).0r  s     r   	<genexpr>embedding.<locals>.<genexpr>  s     ?z$,,s   z+Invalid input for ollama embeddings. input=rE  r   rA  )r   r   promptsr  rK  r  rq  r  )r   r=  r  rK  r  rq  r6  r   MISTRAL_API_KEYr  FIREWORKS_AI_API_KEYr  r  XINFERENCE_API_KEYzstub-xinference-keyXINFERENCE_API_BASEzhttp://127.0.0.1:9997/v1r  )r   r=  r  rK  r  rq  r  r   r  r  r  z*No valid embedding model args passed in - rm  r   rY  )r   r  r   r  r   )Ar   r   r|   r   r*   r+   r   r   r  r   r    r   r   r#  r   r$  rU  r+  r  r   open_ai_embedding_modelsr   r   r-  r/  r.   rP  databricks_embeddingopenai_like_keyopenai_like_embeddingrK  r)  r*  cohere_embedr  rN  r  r   bedrock_embedding
embeddingsr6  rB  google_batch_embeddingsbatch_embeddingsr  r  vertex_multimodal_embedding%SUPPORTED_MULTIMODAL_EMBEDDING_MODELSmultimodal_embeddingvertex_embeddingr[   allBadRequestErrorr  ollama_aembeddingsollama_embeddingsr]  rl  azure_ai_embeddingr   r  rm  r"  rn  r   )6r   r=  r  r  r   r   r   r   r  r  r   r   r  ry  r   r   r   r  r  r   r{  r  r:  r  r~  r}  r  r  r   r  r  r  r  r  rz  r  r{  r   r   r  r}  r  r   ro  r  rK  transformed_inputr  r  r  r  ollama_embeddings_fnr7  r4  s6                                                         r   r  r  $  s   Z JJw%EZZ$'F
**UD
!C
**UD
!C**]D1K-3ZZ8M-NJJ5M+1::ot+LM"JJ'>EL$/Jzz*d+H!::&<dCL$/JJJ5MjjD)G!::&<dC"JJ'>E"JJ'>E#ZZ(@$GM  	 	N
 #^3N'A1N+B1   =M/	=9E "!4 '/ O  EGG',A,M&'q0,@-B(;3	
 (!7!>3&'q0-B.D(;3	

04.,,+"#2&(<($($(#%!.	 	- 	
$ D=/7:%&67B7HW7#3#3W~FV7WH  5&&5!"565 44	  -00 $ 2 01 
  3??3$$3 "/2	   f 
 .77!'-#02 /%'0= 8 H" W555"h."m3"l2  /##/!"34/ /	  $$ !"78   4??4%%4 ""23	  (3@0HK /88!#02 /%' 9 H !L0X7#3#3XzBW7XH  4??4))4 23	  ,55!#02 /% 6 H  =0"i/"m3 VG,,V?U0V   9??9**9 ""78	  -66!#02 /% 7 H !H,0C}0T #%%#./# l+# ??  (Zt-L-L'#-- /!"#02%H !M1 #**#34# ??	  #,,!!#02 /% - H !I-%%%%*G!$)!(33'!# /02%!!++ 4 H !H, M  -66$7!#02 /% 7 H !H,N>*:;Nw  /??!# /02# $#'%+$,& @ H  !K/##$4d; 4"&&':DA4))4 ""454 ""23   ##$5t< 5"&&';TB5**5 ""565 ""34   ##$8$? 8"&&'>E8!"898 ""67	  ?*o-.TTU 7KK% '$3#4#6#4$6'9)"/(3 L  ,55% '$3#4#6#4$6'9(3#)"/# 6   !K/ **!!# /02	H !H,   ,,!"34, ,	  %%%????--I%Q!)  % ))-- !
 ,!!# /02H !K/$..!# /02+ / H !I-UUNCT4UG.88!#02 /% 9 H !N2T7??Tn=S.T  /88!#02 /% 9 H !H,,66$7!#02 /% 7 H !L0 )??)!"67) )	   .##.!"78. .	  /88!#02 /% 9 H !I- **!# /02% + 	H !J. 7##7!"56   6??6%%6 ""45	  *33!#02 /% 4 H 8DI$PQQGH6F$G$G=PH##$9:8DI$PQQ@  
%%!!f 	& 	
   3	
 	

s%   =tt"k0t 
u#&u		uc            	        #    [         R                  " 5       n[        U 5      S:  a  U S   OUS   nSUS'   Sn [        [        /U Q70 UD6n[
        R                  " 5       n[        UR                  U5      n[        X1R                  SS5      S9u  p  nUS:X  d  US	:X  d  US
:X  d  US:X  d  US:X  d  US:X  dz  US:X  dt  US:X  dn  US:X  dh  US:X  db  US:X  d\  US:X  dV  US:X  dP  US:X  dJ  US:X  dD  US:X  d>  US:X  d8  US:X  d2  US:X  d,  US:X  d&  US:X  d   US:X  d  US:X  d  U[        R                  ;   a@  UR                  SU5      I Sh  vN n	[         R                  " U	5      (       a
  U	I Sh  vN n	OUR                  SU5      I Sh  vN n	UR                  SS 5      SL d*  [        U	[        5      (       d  [        U	[         5      (       a  [        [#        U	UUU S!9UUS"9$ [        U	[$        5      (       a  U	$ [         R                  " U	5      (       a
  U	I Sh  vN n	[%        5       n
[        R&                  R(                  R+                  U
U	US#9n
U
$  GN
 N N N@! [,         a  nU=(       d    Sn[/        UUUU US$9eSnAff = f7f)%zH
Implemented to handle async streaming for the text completion endpoint
r   r   Tr   Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r	  r   F)r   r   r   r7  )rJ  r   r   )text_completion_responser   r   r  )r  r   r1  r   r  r#  r$  r%  r*   r   r   r&  r(  r+  r)  r   r!   r9  r   rh  LiteLLMResponseObjectHandlerconvert_chat_to_text_completionr"  r   )r7  r   r  r   r   r0  r1  r2  r/  r   r  r4  s               r   r  r    s     !!#D4y1}DG&/E F=R
888 &&(#CGGT2'7**Z">(
$1
  8+"g-"l2"o5"j0"i/"l2"k1"l2"f,"l2"j0"k1"k1"f,"l2"&AA"j0"n4"&>>"m3"h."k1"g&I&II "11$8IJJH""8,,!)> "11$8IJJHJJx'4/($?@@($788."2%(;	# $7	 	 ($:;;$$X..!)>'='?$'.}}'Q'Q'q'q)A!$7 (r ($
 ,+E K) K* *  
1=X 3 "
 	

s   6JDI I$I ,I-I IAI J I 6J7 I I8I JI I I I 
J$I<<JJr  best_ofechor   suffixr   c           
        ^^^^)^*^+ SS K n ST;   a0  TS   nTc  [        U[        5      (       a  UmTR                  S5        [	        5       m*0 m)Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S	'   U	b  U	T)S
'   U
b  U
T)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   Ub  UT)S'   [        TUUS9u  nnnnUS:X  Ga!  USL a  ST;  a  STS'   [        U [        5      (       a  SS Kn[        R                  " S5      m+[        U 5      S:  a  [        U S   [        5      (       a  U  Vs/ s H  nS PM     nnUUUU)U*U+4S jnUR                  R                  5        n [        U 5       V!V"s/ s H  u  n!n"U R                  UU!U"5      PM     n#n!n"[        UR                  R                  U#5      5       H  u  n!n$U$R!                  5       UU!'   M     UT*l        S S S 5        T*$ / n%[        U [        5      (       aG  [        U 5      S:  a8  [        U S   [        5      (       a   U  H  n&SU&S.n'U%R%                  U'5        M     O[        U [        5      (       a  SU S./n%OUS:X  d  US:X  d  US :X  d  US!:X  d  US":X  aW  [        U [        5      (       aB  [        U 5      S:  a3  [        U S   [        5      (       a  [&        R(                  " S#S$9  SU S./n%O[+        S%U  S&35      eTR                  S'S 5        Ub1  US:X  a+  U[,        R.                  ;  a  S(U-   mT)R                  SS 5        Tc  [1        S)5      eSTS*'   [3        TTU%S+.TDT)D6n(TR5                  S,S-5      SL a  U($ USL d*  TR5                  SS-5      SL d  [        U([6        5      (       a  [9        U(TUUS.9n(U($ [        U([8        5      (       a  U($ [        U([        5      (       a  U($ [,        R:                  R<                  R?                  U(T*S/9m*T*$ s  snf s  sn"n!f ! , (       d  f       T*$ = f)0Nr   enginer  r  r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r  Ttop_n_tokensr  ztext-davinci-003c                    > T
R                  U5      n0 TETEn[        TTUSS.UD6nUR                  SS 5      T	S'   ST	S'   UR                  SS 5      T	S'   UR                  SS 5      T	S'   US   S	   $ )
Nr  )r   r  r   r|  r  objectrj  r   rf  r   )decoder  r   )rs  individual_promptdecoded_prompt
all_paramsr   r7  r   r   r  r  	tokenizers        r   process_prompt'text_completion.<locals>.process_prompt  s    %.%5%56G%HN!>F!>o!>J7F  $-$%8
 %8H 6>\\$5M,T29J,X6:B,,yRV:W,Y78@Wd8S,W5#I.q11r   )rN  rM  r   r   r   r  r  z\List of lists being passed. If this is for tokens, then it might not work across all models.)msgzVUnmapped prompt format. Your prompt is neither a list of strings nor a string. prompt=z;. File an issue - https://github.com/BerriAI/litellm/issuesr  ztext-completion-openai/z;model is not set. Set either via 'model' or 'engine' param.r  r   r   F)rJ  r   r   r   )r   r  ) copyr)  r   r   r   r*   r2  concurrent.futurestiktokenencoding_for_modelr1  r   r   	enumeratesubmitas_completedresultrf  ri  r5   r^  r"  r   r9  rU  rZ   r   r!   r   rh  r  r  ),r  r   r  r  r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r7  r   r  _engine_modelr}  
concurrentx	responsesr  executorrs  r  completed_futuresfuturer   prE  r   r  r  r  s,    `                    ``                 @@@r   r  r    s/   j 4 6"=Z55E

857&(O%,	""&$/@+,(2%&.
#(2%} #.>*+"&$*!!,:()$*!)4&#( "&&.
#)4&%,	"&1D-. >N/>:F( m+4<V+)*~& fd##% 334FGI6{Q:fQi#>#>+126aT6	22 2"  ''::< 5>f4E)4E0A0 !;LM4E & ) &/"**778IJ&	6 (.}}	!& 8A,4 = 0/ H&$CK!O
6!9c8R8RA%!4GOOG$  
FC	 	 #78  8+"g-"l2"&AA"&>>vt$$K!Ovay$''n	
 $78dekdl  mh  i
 	
 JJxx'???-6E 5t<}VWW $F 
  	
 H zz-'4/$::h&$.h 344.&) 3	
 	H9	:	: (233 	22RR%= 	S 	
  $#a 3() =< 0/s%   'P1P<) P6	AP<6P<<
Q
adapter_idc                   #     Sn[         R                   H  nUS   U :X  d  M  US   nM     Uc)  [        SR                  U [         R                  5      5      eUR	                  US9n[        S0 UD6I Sh  vN nSn[        U[        5      (       a  UR                  US9n[        U[        5      (       a  UR                  US9nU$  NP! [         a  nUeSnAff = f7f)	z<
Implemented to handle async calls for adapter_completion()
Nr|  adapterHNo matching adapter given. Received 'adapter_id'={}, litellm.adapters={}r   r   rJ  r   )r   adaptersrU  format!translate_completion_input_paramsr   r)  r   "translate_completion_output_paramsr!   ,translate_completion_output_params_streamingr"  )r  r   translation_objr  
new_kwargsr   translated_responser4  s           r   aadapter_completionr    s     26$$DDzZ'"&y/ % "Zaa 0 0  %FFfFU
DOD]R\D]>]  	 h.."1"T"T! #U # h 344LL&. M    #" ?^   sA   CC	 AC	 6C7AC	 CC	 	
CCCCc                    S n[         R                   H  nUS   U :X  d  M  US   nM     Uc)  [        SR                  U [         R                  5      5      eUR	                  US9n[        S0 UD6nS n[        U[        5      (       a  UR                  US9nU$ [        U[        5      (       d  [        R                  " U5      (       a  UR                  US9nU$ )Nr|  r  r  r	  r
  r  r   )r   r  rU  r  r  rZ   r)  r   r  r!   rs  rt  r  )r  r   r  r  r  r   r  s          r   adapter_completionr  C  s     /3O  :#"9oO ! V]]G,,
 	
 !BB&BQJ:D:Rz:RH  (M**-PP Q 
  
H1	2	2g6I6I(6S6SHH"* I  	 r   r=  c                 J   U=(       d9    [         R                  =(       d"    [         R                  =(       d    [        S5      nUR	                  SS 5      nUc  [
        R                  " US9nUb  UR                  R                  XS9nU$ UR                  R                  U S9nU$ )Nr  r   )r   r=  r   r=  )	r   r   r-  r    r   r   OpenAImoderationsr   )r=  r   r   r   openai_clientr   s         r   
moderationr  i  s    
 	 	,??	,	, *+	  JJx.M
  ,,33%3M O !,,33%3@Or   c                   #    SSK Jn  U=(       d9    [        R                  =(       d"    [        R                  =(       d    [        S5      nUR                  SS 5      nUb  [        XT5      (       d  [        R                  SUS9nOUnUb#  UR                  R                  XS9I S h  vN nU$ UR                  R                  U S9I S h  vN nU$  N) N7f)	Nr   )AsyncOpenAIr  r   T)is_asyncr   r  r  )r   r  r   r   r-  r    r   r)  r/  _get_openai_clientr  r   )r=  r   r   r   r  r  _openai_clientr   s           r   amoderationr#    s      # 	 	,??	,	, *+	  JJx.MJ}$J$J '>&P&P 'Q '

 ''33:::TT O (33:::GGO UGs$   B$C&C'"C	C
CCc            	        #    [         R                  " 5       n[        U 5      S:  a  U S   OUS   nSUS'   Sn [        [        /U Q70 UD6n[
        R                  " 5       n[        UR                  U5      n[        X1R                  SS5      S9u  p  nUR                  SU5      I Sh  vN n	[        U	[        5      (       d  [        U	[        5      (       a$  [        U	[        5      (       a  [        S
0 U	D6n	U	n
U
$ [         R                  " U	5      (       a  U	I Sh  vN n
U
$ UR                  SU5      I Sh  vN n
U
$  N N$ N
! [         a  nU=(       d    Sn[!        UUUU US	9eSnAff = f7f)ay  
Asynchronously calls the `image_generation` function with the given arguments and keyword arguments.

Parameters:
- `args` (tuple): Positional arguments to be passed to the `image_generation` function.
- `kwargs` (dict): Keyword arguments to be passed to the `image_generation` function.

Returns:
- `response` (Any): The response returned by the `image_generation` function.
r   r   Taimg_generationNr   r   r   r  r   )r  r   r1  r   image_generationr#  r$  r%  r*   r   r(  r)  r*  r   r+  r"  r   r7  r   r  r   r   r0  r1  r2  r/  r3  r   r4  s               r   aimage_generationr(    s}     !!#D4y1}DG&/E $F"
'9$9&9 &&(#CGGT2'7**Z">(
$1
 #2249JKKmT**j=/
 /
 -.. - > >$H    //**H  "11$8IJJH L + K 
1=X 3 "
 	

sx   6E/A0E )D?*AE ;E/< E EE "E/#E 8E9E >E/?E E E 
E,E''E,,E/qualitysizestylec                 \
    [        5       nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	0 5      nUR                  S
5      nUR                  SS5      nUR                  SS5      nUR                  SS5      =(       d    0 nUb  UR                  U5        [        R                  R                  5       nUc  Ub  [        UUU
S9u  pnn
OSnSnUUR                  S'   / SQn[        nUU-   nUR                  5        VV s0 s H  u  nn UU;  d  M  UU _M     n!nn [        S7UUUUUUUUS.U!D6n"Un#U#R                  UUU"USUUUUUS0 S.	US9  Ub
  [        UUS9$ US:X  Ga.  [        S5      =(       d    Sn$U
=(       d"    [        R                  =(       d    [        S5      n
U=(       d"    [        R                  =(       d    [        S5      nU	=(       dK    [        R                   =(       d4    [        R"                  =(       d    [        S5      =(       d    [        S5      n	U"R%                  SS5      =(       d    [        S5      n%SU	S .n&U&R                  5        H  u  nn UU;  d  M  U UU'   M     [&        R)                  UU UU	U
UU"UUUUUS!9nU$ US:X  a  [*        R)                  UU UU	U
UU"UUUS"9
nU$ US#:X  a)  Uc  [-        S$5      e[.        R)                  UU UUU"UUS%9nU$ US&:X  Ga  U"R%                  S'S5      =(       d;    U"R%                  S(S5      =(       d"    [        R0                  =(       d    [        S)5      n'U"R%                  S*S5      =(       d;    U"R%                  S+S5      =(       d"    [        R2                  =(       d    [        S,5      n(U"R%                  S-S5      =(       d$    U"R%                  S.S5      =(       d    [        S/5      n)[4        R)                  UU UUU"UU'U(U)US09
nU$ U[        R6                  ;   a  Sn*[        R8                   H  n+U+S1   U:X  d  M  U+S2   n*M     U*c  [;        S3U 35      eUS4L a5  Sn,Ub  [=        U[>        5      (       a  Un,U*RA                  UU U	U
UU"UUU,S59	nU$ Sn-Ub  [=        U[B        5      (       a  Un-U*R)                  UU U	U
UU"UUU-S59	nU$ s  sn nf ! [,         a  n.[E        UUU.[        5       US69eSn.A.ff = f)8zj
Maps the https://api.openai.com/v1/images/generations endpoint.

Currently supports just Azure + OpenAI.
r%  Fr  Nry  r:  r  r~  r}  r{  r   r   r  r  zdall-e-2r   r   )r   r  r   r   r   r   r   r   r   r   r   r   r)  r*  r+  )r   r   r)  r   r*  r+  r   r   )	r   r   r  ry  r  r~  r}  r  r  r  r  r   r  r  r  r  r  r  r  zapplication/json;)zContent-Typezapi-key)r   r  r   r   r   rK  r  rq  r   r%  r   r  )
r   r  r   r   r   rK  r  rq  r%  r   r  z!Model needs to be set for bedrock)r   r  r   rK  r  rq  r%  r	  r  r  r  r  r  r  r  r  r  )
r   r  r   rK  r  rq  r  r  r  r%  r  r  r  T)	r   r  r   r   rq  r  rK  r   r   r  r   )#r   r   r  r   rh  r   r*   rm  r|   r   r,   r   r   r    r   r   r   r$  r   r+  r&  r/  r"  bedrock_image_generationr  r  vertex_image_generationr'  ry  rU  r)  r   r(  r   r   )/r  r   r   r)  r   r*  r+  r   r   r   r   r   r   r   r7  r%  r  ry  r:  r  r~  r}  r{  r   r   r  rq  r}  rz  r  r{  r   r   r  r  ro  r  r  r   r  r  r  r  r  async_custom_clientcustom_clientr4  s/                                                  r   r&  r&    sU   ,p
x **%6> **%6=JJ{D1	'-zz/4'H%zz*@$GZZd3
::j"-17<Q1RHd+

?D9

9d39r$NN=)(/(C(C(E 3 ?DT$7!EAE E"*16%%g.
" ,&7#\\^
+TQq/FDAqD^ 	 
 8 

+ 3

 !

 /,,+"#2&(<($$(#%
 !4 	- 	
" $(uMRR')%&67B7HW7#3#3W~FV7WH  7&&7!"56   3??3$$3 ""893 "/2  -00 $ 2 01 
 !4"O (--/1G#!"GAJ 0 4DD!/ /-' / E Nn S !H,4EE!/ /- / F NP y !I-} CDD5FF/ /- / G Nr a !K/##$4d; 6"&&':DA6))6 ""45	   ##$5t< 7"&&';TB7**7 ""56	   ##$8$? :"&&'>E:!"89 
 5EE/ /-0 2#5 / F N| c  7#<#<< 37N33
#'::%)*:%;N 4 % NtfU 
 $&BF#%*V=M*N*N*0' "0!A!A!#%#1$3 3#. "B 
": # 8<%*V[*I*I$*M "0!@!@!#%#1$3 3#( "A 
" u
v  
 3 $h
 	

sd   ET T(T/AT 2DT >(T '#T .T :D	T 0T 8AT 4T T 
T+T&&T+c            	        #    [         R                  " 5       n[        U 5      S:  a  U S   OUS   nSUS'   Sn [        [        /U Q70 UD6n[
        R                  " 5       n[        UR                  U5      n[        X1R                  SS5      S9u  p  nUR                  SU5      I Sh  vN n	[        U	[        5      (       a  [        S
0 U	D6n
U
$ [        U	[        5      (       a  U	n
U
$ [         R                  " U	5      (       a  U	I Sh  vN n
U
$ UR                  SU5      I Sh  vN n
U
$  N N$ N
! [         a  nU=(       d    Sn[!        UUUU US	9eSnAff = f7f)U
Calls openai + azure whisper endpoints.

Allows router to load balance between them
r   r   TatranscriptionNr   r   r   r  r   )r  r   r1  r   transcriptionr#  r$  r%  r*   r   r(  r)  r*  r   r+  r"  r   r'  s               r   r3  r3    ss     !!#D4y1}DG&/E#F 
}6t6v6 &&(#CGGT2'7**Z">(
$1
 #2249JKKmT**,=}=H  '<==$H    //**H  "11$8IJJH L + K 
1=X 3 "
 	

s   6EA0D2 )D,*%D2 ED2 (E) D2 	D.
D2 ED2 %D0&D2 +E,D2 .D2 0D2 2
E<EEEfilelanguage)r  r@  srtverbose_jsonvtttimestamp_granularities)wordsegmentr   c                 B   UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S5      nUR                  S	S5      nUR                  S
/ 5        UR                  SS5      nUR                  SS5      nU(       a  [        U5      UR                  S'   Uc  [        R
                  n[        R                  R                  5       n[        XU
S9u  pnn
Ub  Un	[        U UUUUUUUS9nUR                  U U0 UUUUS0 S.UEUS9  SnUS:X  a  U
=(       d"    [        R                  =(       d    [        S5      n
U=(       d"    [        R                  =(       d    [        S5      nUR                  SS5      =(       d    [        S5      nU	=(       d9    [        R                  =(       d"    [        R                   =(       d    [        S5      n	UUS	'   ["        R%                  U UUUUUUUU
U	UUUS9nOUS:X  d  US:X  a  U
=(       d+    [        R                  =(       d    ['        S5      =(       d    Sn
[        R(                  =(       d    ['        S5      =(       d    S[        l        U	=(       d9    [        R                  =(       d"    [        R*                  =(       d    ['        S5      n	[,        R%                  U UUUUUUUUU
U	S9nUc  [/        S5      eU$ ) r2  r  Nr  r~  r}  r3  Fr{  r   tagsr  r   r  )r   r6  r  r   r:  r   r   r  r  r  r~  r}  r  r  r  r   r  r  r  r  r  )r   
audio_filer  rq  r3  r   r   rK  r   r   r   r  r   r   r   r  r  r  r  )r   r@  r  rq  r3  r   r   rK  r   r   r   z8Unmapped provider passed in. Unable to get the response.)r   r   r   model_call_detailsr   DEFAULT_MAX_RETRIESr   rh  r   r*   r-   r   r   r    r   r   r$  azure_audio_transcriptionsaudio_transcriptionsr.   r   r-  openai_audio_transcriptionsrU  )r   r5  r6  r  r   r:  r   r   r   r   r   r   r   r   r   r  r  r~  r}  r3  r{  r   r  r   rq  r}  r  r   r  s                                r   r4  r4    sJ   6 jj!2D9O!::&<dCL$/Jzz*d+HZZ 0%8NZZ 0%8N-3ZZ8M-NJJ5M
JJvr**]D1K 	

8T"  ;>v;..x800]]88:N<Lx=9E "!7' 7/	O 44.$8$  $!
 
 0 5   15Hg%Sw//S>BR3S U7..U.AT2U 	  $4d; 
~@

  //  / o.	 	 ,9(-BB+))+#)# C 
 
	(,?6,I +++,+ +	 	    /0 	 bW__b0B0BbjQaFb.CC+))+# D 
 STTOr   c            	      f  #    [         R                  " 5       n[        U 5      S:  a  U S   OUS   nSUS'   UR                  SS5      n [	        [
        /U Q70 UD6n[        R                  " 5       n[	        UR                  U5      n[        X1R                  SS5      S9u  p  nUR                  SU5      I Sh  vN n	[         R                  " U	5      (       a  U	I Sh  vN n
U
$ UR                  SU5      I Sh  vN n
U
$  NG N$ N
! [         a  nU=(       d    S	n[        UUUU US
9eSnAff = f7f)z
Calls openai tts endpoints.
r   r   Taspeechr   Nr   r   r   r  )r  r   r1  r   r   speechr#  r$  r%  r*   r(  r+  r"  r   r'  s               r   rG  rG    s=    
 !!#D4y1}DG&/EF9 **%:DA
v/// &&(#CGGT2'7**Z">(
$1
 #2249JKK}--**H  "11$8IJJH L* K 
1=X 3 "
 	

sm   AD1	A0D 9D:$D DD $D1%D :D;D  D1D D D 
D.D))D..D1voicer   projectr}  speedr  rG  c                 t	   UR                  SS 5      nUR                  SS 5      nUR                  SS 5      nUR                  SS 5      nUR                  SS 5      n[        XUS9u  pnnUR                  S/ 5        0 nUb  UUS'   Ub  UUS	'   U
c  [        R                  n
Uc'  [        R
                  =(       d    [        R                  nUR                  S
S 5      nUR                  U U0 UUUU	S 0 S.UEUS9  S nUS:X  GaE  Ub  [        U[        5      (       d  [        R                  " SU US9eU=(       d+    [        R                  =(       d    [        S5      =(       d    SnU=(       d9    [        R                  =(       d"    [        R                  =(       d    [        S5      nU=(       d+    [        R                   =(       d    [        S5      =(       d    S nU=(       d+    [        R"                  =(       d    [        S5      =(       d    S nU=(       d    [        R$                  n[&        R)                  U UUUUUUUUU
UUS9nGOFUS:X  Ga9  Ub  [        U[        5      (       d  [        R                  " SU US9eU=(       d"    [        R                  =(       d    [        S5      nU=(       d"    [        R*                  =(       d    [        S5      nU=(       dK    [        R                  =(       d4    [        R,                  =(       d    [        S5      =(       d    [        S5      nUR                  S0 5      R                  SS 5      =(       d    [        S5      nU(       a  UUS'   [.        R)                  U UUUUUUUUUU
UUS9nGOUS :X  d  US!:X  a  S"S#KJn  U" S+0 UD6nUR                  =(       d    S$nUR4                  =(       d"    [        R4                  =(       d    [7        S%5      nUR8                  =(       d"    [        R8                  =(       d    [7        S&5      nUR:                  =(       d    [7        S'5      n Ub.  [        U[<        5      (       d  [        R                  " S(U 3U US9e[>        R)                  UU UUU
UU UUUUUS)9nUc)  [A        S*RC                  U[        RD                  5      5      eU$ ),Nr   r  r  r   r~  r  r>  r   rK  r{  r?  r  r   z;'voice' is required to be passed as a string for OpenAI TTSr  r  r  r  r  OPENAI_PROJECT)r   r=  rI  r  r   r   r   rJ  r   r   r   rG  r   z:'voice' is required to be passed as a string for Azure TTSr  r  r  r  r  r  r  )r   r=  rI  r  r   r   r   r  r   r   r   r   rG  r	  r
  r   )GenericLiteLLMParamsr  r  r  r  zN'voice' is required to be passed as a dict for Vertex AI TTS, passed in voice=)	_is_asyncr  r  r  r   r   r   r=  rI  r  r   rK  z@Unable to map the custom llm provider={} to a known provider={}.r   )#r   r*   r   r   r  r   r   rB  r   r)  r   r  r   r.   r   r-  r   rJ  r  r/  audio_speechr   r$  r+  litellm.types.routerrN  r  r    r  r  r*  vertex_text_to_speechr"  r  provider_list)!r   r=  rI  r   r   r   r   rJ  r   r}  r   r   rK  r   r  r   rG  r   r   r  r  r   r~  r}  r  rK  r   r  rN  generic_optional_paramsr  r  r  s!                                    r   rH  rH    s   * ::fd#D%+ZZ0A4%HO!::&<dCJJ5ML$/J<Lx=9E JJvrO"-<)*#( ))))GV-G-G**2D9K,,.$8$  $!
 
 0 -  6:Hh&=E3!7!7))U0   +++,+ +	 	  ,,!!, *+	 	  ##/0 	 	  *+ 	 	 ,W__*77+%# 8 
 
	'=E3!7!7))T0 
 Ow//O:>N3O![W%8%8[JGZ<[  ++  + 01+ /* 	 )8(;(;L"(M(Q(Qd)
 )

 	 /<OO,)66+#)%# 7 
 
	+/BFV/V="6"@"@*339r#22 2%%201 	 $33 3&&312 	 $66 645 	
 Zt%<%<))hinhop0 
 )551,.+# 6 
 NUU#W%:%:
 	

 Or   model_paramsc                 >  #    SU ;   at  SSK Jn  U" US9nS nU[        R                  ;   a.  [        R                  U   n[        R
                  " U5        US S nXBS'   XRS'   SUS	'   [        S
0 UD6I S h  vN   0 nU$ SUS	'   [        S
0 UD6I S h  vN   0 nU$  N$ N
7f)N*r   )*pick_cheapest_chat_model_from_llm_provider)r      r   r   r4   r   r   ),litellm.litellm_core_utils.llm_request_utilsrX  r   models_by_providerrandomshuffler   )r   r   rU  rX  cheapest_modelfallback_modelsmodelsr   s           r   ahealth_check_chat_modelsra    s      e|	

 D 3
 +/'"<"<<//0CDFNN6"$O !/W$3[!%&\")L))) O	 &'\")L)))O 	* 	*s$   A2B4B5BB	BBmode)rZ   r  r&  r   batchrerankdefault_timeoutc                   #    Sn U R                  SS5      nUc  [        S5      eU[        R                  ;   a%  Uc"  [        R                  U   R                  S5      n[	        US9u  pg  nU[        R                  ;   a%  Uc"  [        R                  U   R                  S5      nUnUnUc  SnUS:X  Ga  U R                  S5      =(       d    [        S	5      =(       d    [        S
5      n	U R                  S5      =(       d    [        S5      =(       d    [        S5      n
U
c  [        S5      eU R                  S5      =(       d    [        S5      =(       d    [        S5      nU R                  S5      =(       d    [        R                  =(       d    Un[        R                  UU R                  SS5      U	U
UUUUUS9	I Sh  vN nU$ US:X  d  US:X  a  U R                  S5      =(       d    [        S5      n	U R                  S5      nU R                  S5      =(       d    [        R                  =(       d    UnU R                  S5      =(       d    [        S5      n
US:X  a  Sn[        R                  UU R                  SS5      U	U
UUUUUS9	I Sh  vN nU$ SS0U S'   US:X  a8  U R                  SS5        X0S '   [        R                  " S.0 U D6I Sh  vN   0 nU$ US!:X  a8  U R                  SS5        X S"'   [        R                  " S.0 U D6I Sh  vN   0 nU$ US#:X  a>  U R                  SS5        X S$'   S%/U S&'   [        R                  " S.0 U D6I Sh  vN   0 nU$ [        UUU S'9I Sh  vN nU$  GN N N Nh N& N! [         al  n[         R"                  " 5       n[%        U[&        5      (       a  USS( nUc  S)S*['        U5       S+U 30s SnA$ ['        U5      S,-   S--   U-   nS)U0s SnA$ SnAff = f7f)/z
Support health checks for different providers. Return remaining rate limit, etc.

For azure/openai -> completion.with_raw_response
For rest -> litellm.acompletion()
Nr   zmodel not setrb  rX  r   r   r   r  r  r   r  AZURE_OPENAI_API_BASEzeAzure API Base cannot be None. Set via 'AZURE_API_BASE' in env var or `.completion(..., api_base=..)`r   r  AZURE_OPENAI_API_VERSIONr   r   )	r   r   r   r   r   r   rb  r  r=  r   r  r  r   r  rZ   )	r   r   r   r   r   rb  r  r=  r   zno-cacheTcacher  r=  r&  r  rd  queryzmy sample text	documents)r   r   rU  i  errorzerror:zz. Missing `mode`. Set the `mode` for the model - https://docs.litellm.ai/docs/proxy/health#embedding-models  
stacktrace: zQ
Have you set 'mode' - https://docs.litellm.ai/docs/proxy/health#embedding-modelsz
stack trace: r   )r   r"  r   
model_costr*   r    rU  r  r+  ahealth_checkr/  r   r  r(  arerankra  	traceback
format_excr)  r   )rU  rb  r  r=  re  passed_in_moder   r   r/  r   r   r   r   r   r   r4  stack_traceerror_to_returns                     r   rn  rn    s    " %)NH*+//>=O,,G&&&4<%%e,008D+;%+H(AqG&&&4<%%e,008D<D')  + :!/2:!"89    , ;!"23;!"9:   { 
   / >!"56>!"<=    + #**#"  4AA%))  !' B  HL q  8+"&>>"&&y1U^DT5UG'++N;L   + #**#"  $''
3X~FW7XH"&>>#4BB%))  !) C  HN 1 D%L! {"  T2(-W%((8<888$ # ++  T2)/X&//?,???  !  T2(.W%-=,>[)oo5555  ";(;!-" 
 M>( 9
 @ 6  ***,k3''%et,K!6#a&  *e  fq  er  s 
 Fbc   	 ))!*s   O;F;N M5N O;C
N M8N O;<N M:N O;5N M<N O;;N M>N O; N .N /N 4O;5N 8N :N <N >N  N 
O8AO3O8O;O3-O8.O;3O88O;c                      [         R                  " U 5        [        R                  (       a  [	        U 5        g g ! [
         a     g f = fr   )r5   debugr   set_verboseprintr"  )print_statements    r   r6  r6  i  s=    _-/"  s   6: 
AAc                      [         R                  b&  [        [         R                  5      n[        S0 U DUD6$ [	        S5      e)Nz`No config path set, please set a config path using `litellm.config_path = 'path/to/config.json'`r   )r   config_pathr0   rZ   rU  )r   config_argss     r   config_completionr}  r  sA    &&w':':;2F2k22n
 	
r   chunksc           
         U S   S   nU S   S   nU S   S   nU S   S   nU S   R                  SS 5      nU S   S   S   S	   nU S   S   S   S
   nUUUUUS SUUS./S S S S.S.n	/ n
U  H_  nUS   nU HQ  nUc  M  [        US5      (       d  M  UR                  S5      c  M/  UR                  S5      nU
R                  U5        MS     Ma     SR                  U
5      nXS   S   S'   [	        U5      S:  a  O  [        XQS9U	S   S'   [        UUSS9U	S   S'   U	S   S   U	S   S   -   U	S   S'   [        S0 U	D6$ ! [         a    [        S5        SU	S   S'    NRf = f)Nr   r|  r  rj  r   system_fingerprintrf  finish_reasonr   )r@  rO  r   r  rT  )r|  r  rj  r   r  rf  rP  r@  r  r   rP  rU  z1token_counter failed, assuming prompt tokens is 0T)r   r@  count_response_tokensrV  rW  r   )	r   r  ri  r3  r1  r2   r"  r6  r   )r~  r   r|  r  rj  r   r  r  r   r   content_listchunkrf  choicert  combined_contents                   r   $stream_chunk_builder_text_completionr  }  s    
4BAYx FQi	"G1IgE';TB2Jy)!,_=Mbz)$Q'
3H 0 $!.	
 "!% 
H( L	"F"FF++JJv&2 **V,##G,   ww|, &6Y6"
q /-:.
/* .;".HW)* 	/*Xg->?R-SS Wn% "-H-- 	/ 	IJ-./*	/s   :D< <EEc                     U c  [         R                  " SSSSS9eU (       d  g [        X5      nUR                  n [	        U 5      S:X  a  g [        U S   S   S   [         R                  R                  5      (       a	  [        XS9$ U S   S   nUR                  U 5      nU  Vs/ s H;  n[	        US   5      S:  d  M  S	US   S   S
   ;   d  M(  US   S   S
   S	   c  M9  UPM=     nn[	        U5      S:  aO  UR                  U5      n	[        [        UR                  S   5      n
S U
R                  l        XR                  l        U  Vs/ s H;  n[	        US   5      S:  d  M  SUS   S   S
   ;   d  M(  US   S   S
   S   c  M9  UPM=     nn[	        U5      S:  aN  [        [        UR                  S   5      n
S U
R                  l        UR#                  U5      U
R                  l        U  Vs/ s H;  n[	        US   5      S:  d  M  SUS   S   S
   ;   d  M(  US   S   S
   S   c  M9  UPM=     nn[	        U5      S:  a  UR'                  U5      US   S   S   S'   U  Vs/ s H;  n[	        US   5      S:  d  M  SUS   S   S
   ;   d  M(  US   S   S
   S   c  M9  UPM=     nn[	        U5      S:  a=  [        [        UR                  S   5      n
UR)                  U5      U
R                  l        [-        U5      nUR/                  U UUUS9n[1        USU5        U$ s  snf s  snf s  snf s  snf ! [2         aJ  n[4        R6                  " SR9                  [;        U5      5      5        [         R                  " SSSSS9eS nAff = f)Nr?  z=Error building chunks for logging/streaming usage calculationr  )r>  rE  rA  r   r   rf  )r~  r   r   rk  deltar   rM  rE  r   )r~  r   completion_outputr   rP  zAlitellm.main.py::stream_chunk_builder() - Exception occurred - {})r   r\  r@   r~  r1  r)  rh  r   r  build_base_responseget_combined_tool_contentr   r~   rf  rE  rM  rk  "get_combined_function_call_contentr   get_combined_contentget_combined_audio_contentr   r   calculate_usagerl  r"  r5   	exceptionr  r   )r~  r   
start_timeend_time	processorr   r   r  tool_call_chunkstool_calls_listrt  function_call_chunkscontent_chunksaudio_chunksr  rP  r4  s                    r   stream_chunk_builderr    s/   j
>""W	  "64	!! v;!1Ii #W]]%>%>
 
 8  q	'"008  
5#$q(  i 0 3G <<  i #G,\:	  	 
  1$'AABRSO7H$4$4Q$78G&*GOO#)8OO&   
5#$q(   5#3A#6w#??  i #G,_=	  	  
 #$q(7H$4$4Q$78G&*GOO#<<=QR OO)  
5#$q(  U9-a099  i #G,Y7	  	 
 ~"..~> Y"9-i8  
5#$q(  5+A.w77  i #G,W5	  	 
 |q 7H$4$4Q$78G$-$H$H$VGOO!;HE))/	 * 
 	'5)C
 


0  
  OVVA	

 S	
 	

s   !L2 &L2 :L2 L2 #L=LLL%A$L2 	L##L#4L#L#A#L2 .L(L(L(*L(02L2 "L-<L-L-L-$A9L2 L2 2
N<ANN)FNzThis is a mock requestNNN)NNNNNNNNNNNNNNNNNNNNN)NN)NNNNNNNr   NNNN)NNNNNNr   NNNNN)NNNNNNNNNNNNNNN)NNNip  r   )NNN(%  r  r#  datetimers  r  rD  r\  sysrd  rp  uuidr  r   r  r   r   r   r  r   	functoolsr   typingr	   r
   r   r   r   r   r   r   r   r   dotenvr_  r   r  pydanticr   typing_extensionsr   r   r   r   r   r   r   "litellm.integrations.custom_loggerr   *litellm.litellm_core_utils.litellm_loggingr  )litellm.litellm_core_utils.mock_functionsr   r   8litellm.litellm_core_utils.prompt_templates.common_utilsr   &litellm.llms.custom_httpx.http_handlerr   r   litellm.secret_managers.mainr    litellm.utilsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   _loggingr5   caching.cachingr6   r7   r8   0litellm_core_utils.prompt_templates.common_utilsr9   +litellm_core_utils.prompt_templates.factoryr:   r;   r<   r=   r>   r?   0litellm_core_utils.streaming_chunk_builder_utilsr@   llmsrA   rB   rC   llms.anthropic.chatrD   llms.azure.audio_transcriptionsrE   llms.azure.azurerF   rG   llms.azure.chat.o1_handlerrH   llms.azure.completion.handlerrI   llms.azure_ai.embedrJ   llms.bedrock.chatrK   rL   llms.bedrock.embed.embeddingrM    llms.bedrock.image.image_handlerrN   !llms.codestral.completion.handlerrO   llms.cohere.embedrP   r  "llms.custom_httpx.llm_http_handlerrQ   llms.custom_llmrR   rS   llms.databricks.chat.handlerrT   llms.databricks.embed.handlerrU   llms.deprecated_providersrV   rW   llms.groq.chat.handlerrX   llms.huggingface.chat.handlerrY   llms.nlp_cloud.chat.handlerrZ   rI  llms.ollama.completionr  llms.oobabooga.chatr[   llms.openai.completion.handlerr\   llms.openai.openair]   "llms.openai.transcriptions.handlerr^   llms.openai_like.chat.handlerr_   "llms.openai_like.embedding.handlerr`   llms.petals.completionrv  llms.predibase.chat.handlerra   llms.replicate.chat.handlerr=  llms.sagemaker.chat.handlerrb   !llms.sagemaker.completion.handlerrc   #llms.together_ai.completion.handlerrd   llms.vertex_aire   8llms.vertex_ai.gemini.vertex_and_google_ai_studio_geminirf   <llms.vertex_ai.gemini_embeddings.batch_embed_content_handlerrg   8llms.vertex_ai.image_generation.image_generation_handlerrh   6llms.vertex_ai.multimodal_embeddings.embedding_handlerri   4llms.vertex_ai.text_to_speech.text_to_speech_handlerrj   ,llms.vertex_ai.vertex_ai_partner_models.mainrk   2llms.vertex_ai.vertex_embeddings.embedding_handlerrl   'llms.vertex_ai.vertex_model_garden.mainrm   llms.vllm.completionrn  llms.watsonx.chat.handlerrn   llms.watsonx.completion.handlerro   types.llms.openairp   rq   rr   rs   rt   ru   types.utilsrv   rw   rx   ry   rz   r{   r|   get_encodingr  r~   r   r   r   r   r   r   r   r   r/  r5  rE  rQ  r8  r4  r  rG  r+  r)  r,  rC  r  rZ  r[  rj  ri  r  r-  rV  r  r  r.  r  rW  rX  rR  rl  r]  rk  r  rM  r  rB  r\  r   r   r   r   r   r   r   r  r*  r2  r   r9  r"  rv  r  r  r  r  r  r  r  r  r  r  r#  r(  r&  r3  r4  rG  rH  ra  rn  r6  r}  r  r  r   r   r   <module>r     s        	  
     H H          &   < S Q 7     , % F F U  M 0 0 8 D N C > 1 = : D F 6 B > B E 8 6 6 P 5 * @ 4 H @ J = @ P = ; I 0 O X O O N 9 9 9      /
 
 
 /0 .0 68 68 *, 79 %' 46 ,. 79 ,. 46 m46 46 $, #5#7  $& 13 " "$ 79 /1 /1 (=(? %&?&A #-/ N	,. 24 35 13 *, 02 7 7	O 	O $ $   $#'+/#'!!%)	 $+/9=AE04(,)-!%>B !%*.#"&"!%!!%$(Id
d
 d
 ~	d

 C=d
 eE3J'(d
 %d
 E?d
 }d
 TNd
 TNd
 d
 $C=d
 456d
  =>!d
" ,-#d
$ uo%d
&  'd
( )d
* 3-+d
. eD$y/$9:;/d
0 3-1d
2 D>3d
4 #5d
6 "$7d
8 tn9d
: 3-;d
@ smAd
B #Cd
D c]Ed
F Gd
H D>Id
N =--.Od
 d
N
( #1I&*f;f;f; TNf; }	f;
 i-.f; d^f;R  :>#'!!%)	+/ $9=AE04(,)-!%>B .2#"&*.$( $#'"!%!!%KC#
C#
 C#
 eE3567	C#

 %C#
 E?C#
 }C#
 TNC#
 TNC#
 $C=C#
 C#
 456C#
 =>C#
 ,-C#
  uo!C#
"  #C#
$ %C#
& 3-'C#
* eD$y/$9:;+C#
, 3--C#
. D>/C#
0 %T	*+1C#
2 tn3C#
4 3-5C#
6 "$7C#
: D>;C#
> ~?C#
@ C=AC#
D smEC#
F #GC#
H c]IC#
J KC#
P =--.QC#
 C#
LF7@=> ^
): ^
 ^
B   $%)"!%!"!B

 	B


 c]B

 smB

 #B

 c]B

 smB

 B

 3-B

$ %B

 B

L ]

!#>>?]
 ]
@ 
   	 	 	 	 	 	 	 	 	!%) 	#'! 	"!%!!%)-aG$T%T%T#Y"7889::G$ C=	G$
 G$ G$  G$ S#XG$" #G$( )G$. /G$4 5G$: c49n;G$@ TNAG$B TNCG$D EG$J %KG$L E?MG$N OG$V smWG$X #YG$Z c][G$\ ]G$` "#aG$ G$Z&&eI==>?&R  eI==>? N GK}6>sm0 FJ}6>sm < 2
 2
 2
j   !%)!"!%E
E
C=E
 }E
 c]	E

 c]E
 3-E
 C=E
 3-E
 c]E
 smE
 #E
 E
 E
V +
-B +
 +
\ 
 #  	JN!%!"!%!%%[[
[ sm	[
 SM[ <=[ &d73D+E&FG[ #[ 3-[ c][ sm[  #![" ##[( )[ [| %
&@ %
 %
P  )-!"!%"&!!%#59%)")-"#JJJ E#t)$%J c]	J
 smJ #J 3-J c]J #J tnJ eE5==012J c]J C=J d^J  "#!J" d^#J&  'J J`%(8<	L 	  !Z*Z*
T	
Z* SMZ* D>Z* Z*~
 .2G.G.$TNG.G.V NRm
m
$TNm
eM#99:;m
r   