
    h             K       p   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" d dl#Z#d dl$Z$d dl%Z%d dl&Z&d dl'm(Z( d dl)m*Z* d dl+Z+d d	l+m,Z,m-Z-m.Z.m/Z/m0Z0 d d
l1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z=m>Z> d dl?m,Z@ d dlAmBZBmCZC d dlDmEZE d dlFmGZGmHZH d dlImJZJ d dlKmLZLmMZM d dlNmOZO d dlPmQZQ d dlRmSZS d dlTmUZU d dlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZq ddlrmsZs ddltmuZumvZvmwZw ddlxmyZymzZz ddl{m|Z|m}Z} dd l~mZmZmZmZmZmZ dd!lmZ dd"lmZ dd#lmZ dd$lmZ dd%lmZmZ dd&lmZ dd'lmZ dd(lmZ dd)lmZmZ dd*lmZ dd+lmZ dd,lmZ dd-lmZ dd.lmZ dd/lmZ dd0lmZ dd1lmZmZ dd2lmZ dd3lmZmZ dd4lmZ dd5lmZ dd6lmZ dd.lmZ dd7lmZ dd8lmZ dd9lmZ dd:lmZ dd;lmZ dd<lmZ dd=lmZ dd.lmZ dd>lmZ dd6lmZ dd?lmZ dd@lmZ ddAlmZ ddBlmZ ddClmZ ddDlmZ ddElmZ ddFlmZ ddGlmZ ddHlmZ ddIlmZ dd.lmZ ddJlmZ ddKlmZ ddLlmZ ddMlmZmZmZmZmZmZmZmZ ddNlmZmZmZmZmZmZmZmZmZ  e&j                  dO      Zd dPlVm Z mZmZmZmZmZmZmZ  e       Z e       Z	 e«       Z
 e       Z e       Z e       Z e       Z e       Z e       Z e       Z e       Z e       Z eʫ       Z e       Z e       Z e       Z e       Z eԫ       Z e       Z eګ       Z eث       Z e֫       Z eޫ       Z e       Z eܫ       Z  eЫ       Z! e       Z" eƫ       Z# eī       Z$ e       Z% e       Z& e       Z' eΫ       Z( e       Z) G dQ dR      Z* G dS dT      Z+ G dU dV      Z, G dW dX      Z- e;j\                         e-g ddddddddddddddddddddddddddddddddddf#dYe/dZed[ee   d\ee/   d]ee e0e1f      d^ee0   d_ee0   d`ee1   daee2   dbee3   dcee1   ddee1   deeee      dfee   dgee   dhee0   diee0   djee3   dkee/   dlee e3ee(   f      dmee1   dnee   doee e/e3f      dpee2   dqee2   dree1   dseedt      duee/   dvee/   dwee/   dxee4   dyee3   dzee   d{ee   d|e eeWf   fFd}              Z5d~ Z6	 dde e/e7e3f   dYe/dee/   fdZ8dee2   d]ee e0e/e$jr                  f      dYe/fdZ:dee2   d]ee e0e/e$jr                  f      dYe/fdZ;d]e e0e/e$jr                  f   fdZ<d]e e0e/e$jr                  f   fdZ=	 	 	 	 	 	 	 	 ddYe/dZedaee2   d`ee1   de e/e7e3f   dee   dee2   d]ee e0e/e$jr                  f      fdZ>dYe/de/d|ee3e/f   fdZ? e;j\                         e-g ddddddddddddddddddddddddddddddddddf#dYe/dZed]ee e0e/e$jr                  f      d^ee0   d_ee0   d`ee1   daee2   dbee3   ddee1   dcee1   deeee      dfee   dgee   dhee0   diee0   djee3   dkee/   dseedt      dlee e3ee(   f      dmee1   dnee   doee e/e3f      dqee2   dree1   dpee2   d{ee   dyee3   d[ee   d\ee/   duee/   dvee/   dwee/   dxee4   dzee   d|e eeWf   fFd              Zd Z@d ZAe-d|efd       ZBe*g ddddddddddddfdee1   dee/   dee/   dvee/   dwee/   dee/   de2dkee/   ded   d|eeeef   fd       ZCe*g ddddddddddddfdddee1   dee/   dee/   dvee/   dwee/   dee/   de2dkee/   ded   d|efd       ZCe-g ddddddddddddfdee1   dee/   dee/   dvee/   dwee/   dee/   de2dkee/   d|e eeeeef   f   fd       ZCe-d|e eef   fd       ZDe-	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dde e/ee e/ee e/ee1   f      f      f   dYee/   dee1   dee2   diee0   djeee1e1f      dqee1   dcee1   d`ee1   dhee0   dee e/ee/   f      daee2   dbee3   dee/   d^ee0   d_ee0   dkee/   dee/   dvee/   dwee/   dxee4   dee/   f,d       ZEde/d|ee e(ef      fdZFde/d|ee e(ef      fdZG	 dde/dYee/   dwee/   d|efdZHe-	 	 	 dde/dYee/   dwee/   dee/   d|ef
d       ZIe-d|efd       ZJe-	 	 	 	 	 	 	 	 	 	 	 	 ddYe/dedee/   dee/   dleed      deeed         d^ee1   dkee/   dwee/   dee/   dvee/   dee1   d|e eeeeef   f   fd       ZKe-d|efd       ZLe-	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddYe/de/dee e/e3f      dwee/   dee/   dvee/   dee/   dee/   dee1   dee3   d]ee e0e$jr                  f      dlee/   dee1   dee/   dee3   dee/   dee2   d|ef$d       ZM	 	 	 dde3deed      dee/   dee   fdZNd ZOd ZP	 dde4dZee   d|efdZQ	 dde4dZee4   d|ee eef      fdZRy)    N)futures)FIRST_COMPLETEDThreadPoolExecutorwait)deepcopy)partial)AnyCallable	CoroutineDictListLiteralMappingOptionalTupleTypeUnioncastget_args)	BaseModel)overload)Loggingclientexception_typeget_litellm_paramsget_optional_params),DEFAULT_MOCK_RESPONSE_COMPLETION_TOKEN_COUNT(DEFAULT_MOCK_RESPONSE_PROMPT_TOKEN_COUNT)LiteLLMUnknownProvider)CustomLogger)get_audio_file_for_health_check)tracer)_create_health_check_response_filter_model_params)r   )mock_embeddingmock_image_generation)get_content_from_model_response)
BaseConfigBaseImageGenerationConfig)BedrockModelInfo)AsyncHTTPHandlerHTTPHandler)_realtime_health_check)get_secret_str)GenericLiteLLMParams)RawRequestTypedDict)CustomStreamWrapperProviderConfigManagerUsage_get_model_info_helperadd_openai_metadata/add_provider_specific_params_to_optional_params#async_mock_completion_streaming_obj convert_to_model_response_objectcreate_pretrained_tokenizercreate_tokenizerget_api_keyget_llm_provider!get_non_default_completion_params$get_non_default_transcription_paramsget_optional_params_embeddingsget_optional_params_image_gen!get_optional_params_transcription
get_secretget_standard_openai_paramsmock_completion_streaming_objpre_process_non_default_paramsread_config_argsshould_run_mock_completionsupports_httpx_timeouttoken_counter validate_and_fix_openai_messages$validate_chat_completion_tool_choice   )verbose_logger)disable_cacheenable_cacheupdate_cache)async_completion_with_fallbackscompletion_with_fallbacks)get_completion_messages#update_messages_with_model_file_ids)custom_promptfunction_call_promptmap_system_message_pt	ollama_ptprompt_factory stringify_json_tool_call_content)ChunkProcessor)baseten)AnthropicChatCompletion)AzureAudioTranscription)AzureChatCompletion_check_dynamic_azure_params)AzureOpenAIO1ChatCompletion)AzureTextCompletion)AzureAIEmbedding)BedrockConverseLLM
BedrockLLM)BedrockEmbedding)BedrockImageGeneration)BytezChatConfig)CodestralTextCompletion)handler)BaseLLMAIOHTTPHandler)BaseLLMHTTPHandler)	CustomLLMcustom_chat_llm_router)DatabricksEmbeddingHandler)aleph_alphapalm)GroqChatCompletion)HuggingFaceEmbedding)
completion)	oobabooga)OpenAITextCompletion)OpenAIImageVariationsHandler)OpenAIChatCompletion)OpenAIAudioTranscription)OpenAILikeChatHandler)OpenAILikeEmbeddingHandler)PredibaseChatCompletion)SagemakerChatHandler)SagemakerLLM)vertex_ai_non_gemini)	VertexLLM)GoogleBatchEmbeddings)VertexImageGeneration)VertexMultimodalEmbedding)VertexTextToSpeechAPI)VertexAIPartnerModels)VertexEmbedding)VertexAIModelGardenModels)WatsonXChatHandler)IBMWatsonXMixin)AnthropicThinkingParam)ChatCompletionAssistantMessageChatCompletionAudioParamChatCompletionModality$ChatCompletionPredictionContentParamChatCompletionUserMessageHttpxBinaryResponseContentOpenAIModerationResponseOpenAIWebSearchOptions)	AdapterCompletionStreamWrapperChatCompletionMessageToolCallCompletionTokensDetails	FileTypesHiddenParamsLlmProvidersPromptTokensDetailsProviderSpecificHeaderall_litellm_paramscl100k_base)ChoicesEmbeddingResponseMessageModelResponseTextChoicesTextCompletionResponseTextCompletionStreamWrapperTranscriptionResponsec                   t    e Zd Zddddej                  dddee   dee   dee   dee   dee	eef      f
d	Z
y)
LiteLLMNX  )api_keyorganizationbase_urltimeoutmax_retriesdefault_headersr   r   r   r   r   c                Z    t               | _        t        | j                  d       | _        y )N
router_obj)localsparamsChatchat)selfr   r   r   r   r   r   s          H/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/main.py__init__zLiteLLM.__init__  s     h6	    )__name__
__module____qualname__litellmnum_retriesr   strfloatintr   r    r   r   r   r     sq     &*"&#&%,%8%87;7 sm	7
 3-7 %7 c]7 "'#s("347r   r   c                       e Zd Zdee   fdZy)r   r   c                     || _         | j                   j                  dd      du r8| j                   j                  d       t        | j                   |      | _        y t        | j                   |      | _        y )NacompletionFTr   )r   getpopAsyncCompletionscompletionsCompletionsr   r   r   s      r   r   zChat.__init__  s\    ;;??=%0D8KKOOM*EU
FD  +4;;:NDr   N)r   r   r   r   r	   r   r   r   r   r   r     s    O8C= Or   r   c                   &    e Zd Zdee   fdZddZy)r   r   c                      || _         || _        y Nr   r   r   s      r   r   zCompletions.__init__      $r   Nc                 0   |j                         D ]  \  }}|| j                  |<    |xs | j                  j                  d      }| j                  + | j                  j                  d||d| j                  }|S t	        d||d| j                  }|S Nmodelr   messagesr   )itemsr   r   r   rt   r   r   r   kwargskvresponses          r   createzCompletions.create!  s    LLNDAqDKKN #11??&1t11 h26++H
  "PPDKKPHr   r   r   r   r   r   r	   r   r   r   r   r   r   r         %8C= %
r   r   c                   &    e Zd Zdee   fdZddZy)r   r   c                      || _         || _        y r   r   r   s      r   r   zAsyncCompletions.__init__/  r   r   Nc                 `  K   |j                         D ]  \  }}|| j                  |<    |xs | j                  j                  d      }| j                  3 | j                  j                  d||d| j                   d {   }|S t	        d||d| j                   d {   }|S 7 (7 wr   )r   r   r   r   r   r   s          r   r   zAsyncCompletions.create3  s     LLNDAqDKKN #11??&8T__88 h26++ H
  )WuxW4;;WWH Xs$   A?B.B*!B.#B,$B.,B.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_logprobsreasoning_effort)lowmediumhighr   api_versionr   
model_listextra_headersthinkingweb_search_optionsreturnc$                   K   |$j                  dd      }%|$j                  dd      }&|&du rt        |&||        d{    t        j                         }'|$j                  dd      }(|$j                  dd      })t	        |)t
              r|)j                  |$j                  dd      |$|      rw|)j                  | ||$|$j                  dd      |$j                  d	d      ||$j                  d
d      |$j                  dd             d{   \  } }}*|t        |      dk(  rd}i d| d|d|d|d|d|d|d|d|d|	d|
d|d|d|d|d|d|i d|d |d!|d"|d#|d$|d%|d&|d'|d(|d)|d*|d+|d,|d-| d.|d/|!d|"|#d0}+|("t        | |+j                  d*d      1      \  }*}(}*}*|%xs t        j                  }%|%*t        d>i |+d2d|%i|$i d{   },|,t        d3      |,S |$j                  d4      }-|$j                  d5      }.|$j                  d6      }/|$j                  d      }&|-r+t        |.|/|&7      rt        j                  |-       d{    	 t!        t"        fi |+|$}0t%        j&                         }1t!        |1j(                  |0      }2|'j+                  d|2       d{   }3t	        |3t,              st	        |3t.              rt	        |3t,              rt/        d>i |3},|3},n"t        j0                  |3      r|3 d{   },n|3},|(d8k(  s|(d9k(  rGt	        |,t2              r7t        j4                         j7                  |,t        j.                         :      },t	        |,t8              r|,j;                  |';       |,S 7 Y7 7 7 :7 7 # t        $ r}4|(xs d<}(t=        | |(|4|+|$=      d}4~4ww xY ww)?a  
    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mock_timeoutTcustom_llm_providerlitellm_logging_obj	prompt_id)r  non_default_paramsr   prompt_variablesprompt_labelprompt_version)r   r   r  r  r	  r   r
  r  r   r   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   )r   r   r   r   api_baser   z]No response from fallbacks. Got none. Turn on `litellm.set_verbose=True` to see more details.
mock_delaymock_responsemock_tool_calls)r  r  r  text-completion-openaitext-completion-codestralresponse_objectmodel_response_object)loopopenair   r  original_exceptioncompletion_kwargsextra_kwargsr   )r   _handle_mock_timeout_asyncasyncioget_event_loop
isinstanceLiteLLMLoggingObj"should_run_prompt_management_hooks async_get_chat_completion_promptlenr<   r   model_fallbacksrQ   	ExceptionrG   sleepr   rt   contextvarscopy_contextrunrun_in_executordictr   iscoroutiner   OpenAITextCompletionConfig%convert_to_chat_model_response_objectr1   set_logging_event_loopr   )5r   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  r  r  _r  r   r  r  r  funcctxfunc_with_contextinit_responsees5                                                        r   r   r   @  sR    p 

;-I::nd3Lt(wFFF!!#D **%:DA
 !**%:DA%'89>>jjd3% 	? 	
 &FF%jjd3#ZZ(:DAND9!::&6= G 	
 	
		
$ UqE&&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 	E&F 0K&N "'7"3"7"7
D"I(
$1 4W44I8 

)4i(J6(J
 
 o   L)JJJ/Mjj!23O::n-L0#'!
 mmJ''')
zA%6A&A &&(#CGGT2"2249JKKmT*j=/
 -.(9=9$H  /**H$H  #;;"&AA#9:99;aa (&-&;&;&= b H h 34++ ,  a 	G(	
L
( 	( L +"  
1=X 3 /
 	

s   9ONCON	CO#N$A?O#N$O)AN$ :N ;AN$ N"A;N$ OOOO N$ "N$ $	O-OOOc                   K   	 t        d|         t        j                  |       r
|  d {   } | 2 3 d {   }t        d|        | 7 #7 6 y # t        $ r}|xs d}t	        |||      d }~ww xY ww)Nz'received response in _async_streaming: zline in async streaming: r  )r   r  r  )print_verboser  r.  r'  r   )r   r   r  argsliner7  s         r   _async_streamingr<  8  s     
?zJKx(%~H" 	 	$5dV<=J &	(  
1=X 3 
 	

sR   A;(A AA AAAA AA A;	A8A33A88A;r  r  c           
          t        | t              ryt        | t        j                        r| t	        j
                  t        | dd      t        | dt        |             t        | d|xs d      |t        j                  dd      	      t        | t              r,| d
k(  r't	        j                  dt        | d|xs d      |      t        | t              r,| dk(  r't	        j                  dt        | d|xs d      |      t        | t              r,| dk(  r't	        j                  dt        | d|xs d      |      t        | t              rA| j                  d      r/t	        j
                  d| d|t        j                  dd      	      y y )N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.ContextWindowExceededErrorz,this is a mock context window exceeded errorzlitellm.InternalServerErrorz$this is a mock internal server errorz Exception: content_filter_policyi  azure)r!  r'  r  APIErrorr   MockExceptiongetattrr   httpxRequestRateLimitErrorContextWindowExceededErrorInternalServerError
startswithr  r   r  s      r   !_handle_mock_potential_exceptionsrS  I  s   
 -+mV__5##}cBM63}3EF ~/B/Nh MM5QR
 	
 
M3	'M=U,U$$5 ~/B/Nh 
 	
 	=#&AA00B ~/B/Nh 
 	
 	=#&::)): ~/B/Nh 
 	
 
M3	'M,D,D*- ##! MM5QR
 	
-	'r   r  c                 X    | du r&|#t        |       t        j                  dd|      y y NTzThis is a mock timeout errorr  rG  )_sleep_for_timeoutr   Timeoutr  r   r   s      r   _handle_mock_timeoutrY    s;    
 t 37#oo2!
 	
 !4r   c                 t   K   | du r.|+t        |       d {    t        j                  dd|      y y 7 wrU  )_sleep_for_timeout_asyncr   rW  rX  s      r   r  r    sH     
 t 3&w///oo2!
 	
 !4/s   868c                 <   t        | t              rt        j                  |        y t        | t              rt        j                  t        |              y t        | t
        j                        r-| j                   t        j                  | j                         y y y r   )r!  r   timer(  r   rL  rW  connectr   s    r   rV  rV    sb    '5!

7	GS	!

5>"	GU]]	+0K

7??# 1L	+r   c                   K   t        | t              rt        j                  |        d {    y t        | t              r't        j                  t        |              d {    y t        | t
        j                        r5| j                  (t        j                  | j                         d {    y y y 7 7 W7 wr   )r!  r   r  r(  r   rL  rW  r^  r_  s    r   r[  r[    s     '5!mmG$$$	GS	!mmE'N+++	GU]]	+0KmmGOO,,, 1L	+ 	%+,s4   )B>B86B>"B:#AB>0B<1B>:B><B>Fr  c
           
      @   	 |
j                  d      xs d}|d}t        ||	|        ||j                  |d       t        || |       t	        t
        t        t        f   |      }t        |t              r*|j                  d	      rt        j                  d
d| d      }|
j                  dd      }||st        j                  |       t        |t              rt        d i |S t        |      }|du rL|
j                  dd      du rt        t!        ||| |      | d|      S t        t#        ||| |      | d|      S t        |t        j                        r||||j$                  d   j&                  _        njg }t+        |      D ]S  }t        j,                  j/                  |t        j,                  j1                  |d            }|j3                  |       U ||_        t5        t        j                               |_        | |_        |r5|D cg c]  }t;        d i | c}|j$                  d   j&                  _        t?        |dtA        tB        tD        tB        tD        z                	 t        j,                  jG                  |       \  }}}}||jH                  d<   ||jM                  |dd       |S c c}w # tJ        $ r Y (w xY w# tJ        $ r;}t        |tN        jP                        r|tK        djS                  |            d}~ww xY w)!aS  
    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").
        mock_timeout (bool, optional): If True, the mock response will be a timeout error (default is False).
        timeout (float, optional): The timeout value to use for the mock response (default is None).
        **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.
    r   FNThis is a mock requestrX  zmock-key)inputr   rR  zException: mock_streaming_errorz&This is a mock error raised mid-stream	anthropici  )rE  rA  r   r>  r  r   T)r  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rc  r   original_responsez$Mock completion response failed - {}r   )*r   rY  pre_callrS  r   r   r   r-  r!  rQ  r   rJ  r]  r(  r   r1   r7   rD   choicesrE  rj  rangeutilsr   r   appendr   createdr   r   
tool_callssetattrr3   r   r   r<   _hidden_paramsr'  	post_callr  rI  format)r   r   r   r   r  r  r  loggingr  r   r   is_acompletion
time_delaymodel_response_all_choicesi_choice	tool_callr2  r7  s                       r   mock_completionr    sF   HpJM2;e 4M,uU "  
 	*' 3	
 #t)m
 mS)m.F.F-/
 $11@(	M ZZd3
!.JJz"mT* 1=11&f5T>zz-/47*&I&m5TU'  (0 '  '"?"-uPQ# $,#  mW%:%:;98EN""1%--5L1X!--//#MM11 -K 2  0  ##G,  &2N"!$TYY[!1$ "1< .:	:<N""1%--8
 	F"NE>?		
	+2==+I+IPU+I+V(A"AqCVN))*?@
 '"8  
 ;<&  		  Ja)G>EEaHIIJsb   C&K )?K )K CK K-AK 94K
 -K K 
	KK KK 	L"6LLc                    i }	 t        t        t        | |            }|j                  d      *| j	                  d      r| j                  dd      } d}||d<   || fS # t        $ r[}t        j                  dj                  |             | j	                  d      r| j                  dd      } d}||d<   Y d }~|| fS d }~ww xY w)Nr   r  modez
responses/ 	responseszError getting model info: {})
r   r-  r4   r   rQ  replacer'  rM   debugr  )r   r  
model_infor  r7  s        r   responses_api_bridge_checkr  I  s     "$J&"1D

 >>&!)e.>.>|.LMM,3ED!%Jv u  &;BB1EF
 MM,3ED!%Jvu&s   AA 	C'AB==Cc$                 bd   | t        d      t        |      }t        |      }t               }%|$j	                  dd      }&|$j	                  dd      }'|$j	                  dd      }(t        t        t           |$j	                  dd            })|$j	                  d	d
      }*|$j	                  dd      }+|$j	                  dd      },|$j	                  dd      }-|$j	                  dd      }.|$j	                  dd      }/|$j	                  dd      }0|$j	                  dd      }1|$j	                  dd      }2|$j	                  dd      }3t        t        t           |$j	                  dd            }4|$j	                  dd      xs |}5|$j	                  dd      }6|$j	                  dd      }7|$j	                  dd      }8|5i }5||5j                  |       |$j	                  dd      }9|$j	                  dd      }:|$j	                  dd      };|$j	                  dd      }<|$j	                  dd      }=|$j	                  dd      }>|$j	                  d d      }?|$j	                  d!d      }@|$j	                  d"d      }A|$j	                  d#d      }B|$j	                  d$d      }C|$j	                  d%d      }D|$j	                  d&d      }E|$j	                  d'd      }F|$j	                  d(d      }G|$j	                  d)d      }H|$j	                  d*d      }I|$j	                  d+d      }J|$j	                  d,d      }K|$j	                  d-d      }L|$j	                  d.d      }M|$j	                  d/d      }N|$j	                  d0d      }O|$j	                  d1d      }P|$j	                  d2d      }Qt        t        t           |$j	                  d3d            }Rt        t        t           |$j	                  d4d            }St        ||6xs d|7|85      }t        |$6      }Ti }Ut        |.t              rO|.j!                  RT7      r<|.j#                  | |TRS|$j	                  d8d      |$j	                  d9d      :      \  } }}V	 ||}&|9|9}:|.}W|3xs t$        j&                  }3|3t)        d{i |%S |"3|"D Xcg c]  }X|Xd;   | k(  sXd<    }Y}Xt%        j*                  d{d=|Yi|%S t$        j,                  r%| t$        j,                  v rt$        j,                  |    } t/               }Zt1        |Zd>t%        j2                                |$j	                  d?d      d@u rd?}-||} d?}-t5        | |-|&|!A      \  } }-}[}&|4|4d   |-k(  r|5j                  |4dB          Z:t7        ZdC      r.|-Zj8                  d<   |$j	                  dDd      |Zj8                  dE<   |xs |$j	                  dFd
      xs d
}t        |t:        j<                        rt?        |-      s|j@                  xs d
}n%t        |t:        j<                        stC        |      }|?#@!t%        jD                  |- dG|  |?@|-dHi       n$A"B}Bt%        jD                  |- dG|  A|B|-dIi       i }\CsDsEsFsGr6| i i}\CrC\|    d$<   DrD\|    d%<   ErE\|    d&<   FrF\|    d'<   GrG\|    d(<   |$j	                  dJ      retG        ||$j	                  di       j	                  dd      t        tH        t        tH        t        t        f   f   |$j	                  dJ            K      }d}]|-@|-tJ        D ^cg c]  }^|^jL                   c}^v r tO        jP                  | tK        |-      L      }]]]jS                  |      }J t        Jt              rJdu rtU        |      }[[}!i dM|dN|dO|dP|dQ|dR|dS|dT|dU|
dV|	dW|dX|dY|dZ|d[|d\|d]|i d^| d|-d_|d`|da|db|d|:dc|dd|de| df|dg|dh|di|#dj|dk|$j	                  dk      }_tW        d{i |_T}VtY        | |_|T|-|$j	                  dl      d@d@m      }`t$        jZ                  r0Vj	                  dnd      rVj]                  dn      }at_        ||ao      }ta        d{i d0Odp|!d	|*d|+d|,d|-d|&dq|$j	                  dqd      drt$        j,                  ds|/d|0d|1d|2d)HdtQd"Ad |?d#Bd!@d|;d.|$j	                  d.      du|$j	                  du      d|$j	                  d      d,Kdv|$j	                  dv      dw|$j	                  dw      d*Idx\dy|$j	                  dy      d-Ldz|$j	                  dz      d3Rd4Sd|>d{|$j	                  d{d      d||$j	                  d|d      de| d}|$j	                  d}      d~|$j	                  d~      d|$j	                  d      d|$j	                  d      d|$j	                  d      d|$j	                  d      d|$j	                  d      d|:d|}Ut        t        W      jc                  | |`|U|-       |'s|(s|)r9|$j]                  dd       te        | ||||'|(WO|$j	                  dd      |-|)|      S tg        | |-      \  }1} |1j	                  d      dk(  r*ddl4m5}b |bjm                  | ||5Z|!|&OWVU|P|-tn        |      S |-d?k(  rvd}cPCt        Ptp        jr                        st        Ptp        jt                        rtw        de| iP      }cty        d      xs d?}d|&xs t$        jz                  xs ty        d      }&| xs/ t$        j|                  xs ty        d      xs t$        j~                  } |!xs< t$        j                  xs* t$        j                  xs ty        d      xs ty        d      }!Vj	                  di       j]                  d}d      xs ty        d      }eUj	                  dud      }f|5xs t$        j                  }5||VdB<   |:|:Vd<   t%        j                         j                  |       rlt$        j                  j                         }g|gj                         D ]  \  }h}i|hVvsiVh<    t        jm                  | ||5|!|&| ceZt        VU|+WO|P|-      }jnlt$        j                  j                         }g|gj                         D ]  \  }h}i|hVvsiVh<    t        jm                  | ||5|!|&| dcefZt        VU|+WO|P      }jVj	                  dRd      rWj                  ||!j|5| |&d       jS |-dk(  rty        d      xs d?}d|&xs t$        jz                  xs ty        d      }&| xs t$        j|                  xs ty        d      } |!xs< t$        j                  xs* t$        j                  xs ty        d      xs ty        d      }!Vj	                  di       j]                  d}d      xs ty        d      }eUj	                  dud      }f|5xs t$        j                  }5||VdB<   t$        j                  j                         }g|gj                         D ]  \  }h}i|hVvsiVh<    t        jm                  | ||5|!|&| defZt        VU|+WO|P      }j|Vj	                  dRd      sOd@u rWj                  ||!j|5| |&d       jS |-dk(  r,	 t        jm                  | ||5Z|!|&OWVU|P|-tn        |]      }j|jS |-dk(  r|&xs t$        jz                  xs ty        d      }&|!xs/ t$        j                  xs t$        j                  xs ty        d      }!|5xs t$        j                  }5||VdB<   d| v rt        |      }	 t        jm                  | ||5Z|!|&OWVU|P|-tn        |      }jVj	                  dRd      rWj                  ||!jd|5i       jS |-dk(  s/d| v s+d| v s'|-t$        j                  v r|$j	                  d.      d@u rdtp        _R        |&xs. t$        jz                  xs ty        d      xs ty        d      xs d}&dtp        _>        |!xs/ t$        j                  xs t$        j                  xs ty        d      }!|5xs t$        j                  }5||VdB<   t$        j                  j                         }g|gj                         D ]  \  }h}i|hVvsiVh<    t$        j                  rt$        j                  tp        _T        t        |      dkD  r&d|d   v rt        |d   d   t              r	|d   d   }ln"dj                  |D mcg c]  }m|md   	 c}m      }lt        jm                  | |Zt        |!|-|&OPWVU|+|      }n|Vj	                  dRd      du r-Odu r)Mdu r%t%        j                         j                  nZ      }nVj	                  dRd      sOd@u rWj                  ||!nd|5i       n}j|jS |-dk(  r,	 t        jm                  | ||5Z|!|&OWVU|P|-tn        |]      }j|jS |-dk(  r,	 t        jm                  | ||5Z|!|&OWVU|P|-tn        |]      }j|jS |-dk(  r|&xs! t$        jz                  xs ty        d      xs d}&|!xs/ t$        j                  xs t$        j                  xs ty        d      }!|5xs t$        j                  }5t$        j                  j                         }g|gj                         D ]  \  }h}i|hVvsiVh<    t        jm                  | ||O|&ZVU|-||5tn        |!WP      }j|jS |-dk(  r|&xs. t$        jz                  xs ty        d      xs ty        d      xs d}&|!xs/ t$        j                  xs t$        j                  xs ty        d      }!|5xs t$        j                  }5||VdB<   t        jm                  | ||5Z|!|&OWVU|P|-tn        |      }j|jS | t$        j                  v sN|-dk(  sI|-dk(  sD|-dk(  s?|-dk(  s:|-dk(  s5|-dk(  s0|-dk(  s+|-dk(  s&|-dk(  s!|-dk(  s|-dk(  s|-t$        j                  v sd| v rf|&xs. t$        jz                  xs ty        d      xs ty        d      xs d}&|=xs! t$        j                  xs ty        d«      xs d}=|=tp        _T        |!xs/ t$        j                  xs t$        j                  xs ty        d      }!|5xs t$        j                  }5||VdB<   t$        j                  r|0t        |0      Vd<   t$        j                  j                         }g|gj                         D ]  \  }h}i|hVvsiVh<    	 t        jm                  | ||5Zt        |!|&OWVU|+|\P|=|-ë      }jVj	                  dRd      rWj                  ||!jd|5i       jS |-dk(  rq|!xs t$        j                  xs ty        dū      }!|&xs! t$        jz                  xs ty        dƫ      xs d}&t        jm                  | ||&|-Ztn        WV|UO||!|5P]ȫ      }j|jS d| v s|-dk(  s| t$        j                  v r|!xs< t$        j                  xs* t$        j                  xs ty        dʫ      xs ty        d˫      }o|&xs! t$        jz                  xs ty        d̫      xs d}&\xs t$        j                  }\t        | ||&Zt        VU|+tn        oW|\O|5Ϋ      }Z|Vj	                  dRd      d@u rWj                  |oZϫ       Z}j|jS d| v s|-dk(  s| t$        j                  v rd}p|!xs< t$        j                  xs* t$        j                  xs ty        dѫ      xs ty        dҫ      }p|&xs! t$        jz                  xs ty        dӫ      xs d}&t%        j                         j                  | |&      }&t        jm                  | |d@|O|&ZVUd||5tn        pWի      }j|jS |-dk(  r|!xsC t$        j                  xs1 t$        j                  xs t        j                  j	                  d׫      }!\xs t$        j                  }\|&xs. t$        jz                  xs ty        dث      xs ty        d٫      xs d}&|&|&j                  d۫      s|&dz  }&t        jm                  | ||O|&ZVUd||5tn        |!Wܫ      }j|jS |-dk(  r|!xsC t$        j                  xs1 t$        j                  xs t        j                  j	                  d׫      }!\xs t$        j                  }\|&xs. t$        jz                  xs ty        dث      xs ty        d٫      xs d}&|&|&j                  d߫      s|&dz  }&t        jm                  | ||&Ot$        j                  Zt        VU|+tn        |!W|5|P|-      }j|Vj	                  dRd      sOd@u rWj                  ||!jϫ       j}j|jS |-dk(  r|!xs/ t$        j                  xs ty        d      xs t$        j                  }q|&xs! t$        jz                  xs ty        d      xs d}&t        | ||&Zt        VU|+tn        qW      }jdR|Vv rVdR   d@u rt        j| dW      }jVj	                  dRd      sOd@u rWj                  ||!jϫ       j}j|jS |-dk(  r|!xs< t$        j                  xs* ty        d      xs ty        d      xs t$        j                  }r|&xs! t$        jz                  xs ty        d      xs d}&t        jl                  | ||&Zt        VU|+tn        t$        j                  rW      }ZdR|Vv rVdR   d@u rt        Z| dW      }j|jS Z}j|jS |-dk(  r|!xs< t$        j                  xs* ty        d      xs ty        d      xs t$        j                  }s|&xs! t$        jz                  xs ty        d      xs d}&|5xs t$        j                  xs i }5|5i }5||5j                  |       t        jm                  | ||O|&ZVUd||5tn        sWP      }j|jS |-dk(  r|!xs< t$        j                  xs* t        d      xs t        d      xs t$        j                  }s|&xs! t$        jz                  xs t        d      xs d}&|5xs t$        j                  xs i }5|5i }5||5j                  |       t        jm                  | ||O|&ZVUd||5tn        sWܫ      }j|jS |-dk(  r|!xs/ t$        j                  xs ty        d      xs t$        j                  }t|&xs! t$        jz                  xs ty        d      xs d}&t        jm                  | ||&Zt        VU|+tn        tWd\      }Z|Z}j|jS |-dk(  r|!xsd t$        j                  xsR t        j                  j	                  d      xs1 t        j                  j	                  d      xs t$        j                  }u|5xs t$        j                  }vt        jm                  | ||vZu|&OWVU|P|-tn        |      }j|jS |-dk(  rJd}-t        jl                  | |Z|&t        VUd|+tn        W      }ZdR|Vv rVdR   d@u rt        Z| dW      }j|jS Z}j|jS |-dk(  r|&xs' t$        jz                  xs t        j                  d      }&|!xs0 t$        j                  xs t$        j                  xs ty        d       }!|5xs t$        j                  }5	 t        jm                  | ||O|&ZVUd||5tn        |!WP      }jVj	                  dRd      rWj                  ||!jd|5i       jS |-dk(  r+t        jm                  | ||5Z|!|&OWVU|P|-tn        |]      }j|jS |-dk(  rs|&xs# t$        jz                  xs t        d      xs d}&|!xs> t$        j                  xs, t$        j                  xs ty        d      xs ty        d      }!ty        d      xs d}wty        d	      xs d
}xw|xd}y|5xs t$        j                  }z|zryj                  z       y}5t$        j                  j                         }g|gj                         D ]3  \  }h}i|hdk(  rdVv rVh   j                  i       $iVh<   *hVvs/iVh<   5 | |dV}{t        jm                  | ||O|&Z|VUd||5tn        |!WP      }j|Wj                  |tp        j                  |jϫ       |jS |-dk(  sd| v s| t$        j                   v r	 	 jS |-dk(  rt        d      |-dk(  s|-dk(  rZVj]                  dd      xs4 Vj]                  dd      xs t$        j                  xs ty        d      }|Vj]                  dd      xs4 Vj]                  dd      xs t$        j                  xs ty        d      }}Vj]                  dd      xs! Vj]                  dd      xs ty        d      }~|!xs, ty        d      xs ty        d      xs t$        j                  }|&xs t$        jz                  xs ty        d      }&t        V      }t        jm                  | |Zt        |U|+tn        }|~WO||-P|&|      }j|jS |-dk(  rVj]                  dd      xs4 Vj]                  dd      xs t$        j                  xs ty        d      }|Vj]                  dd      xs4 Vj]                  dd      xs t$        j                  xs ty        d      }}Vj]                  dd      xs! Vj]                  dd      xs ty        d      }~|&xs t$        jz                  xs ty        d       }&t        V      }t
        j                  |       r2t
        jm                  | |Zt        U|+tn        |&}|~WO|5\|P!      }ZnԐd| v sUj	                  d,      ;dUd,   v r3t        jm                  | |Zt        U|+tn        }|~dWO||-P|&|      }Znd| v r2t        jm                  | |Zt        U|+tn        |&}|~WO|5\|P!      }ZnMt        jl                  | |Zt        U|+tn        }|~WO"      }ZdRVv rVdR   d@u rOdu rt        Z| dW      }j|jS Z}j|jS |-d#k(  rVj]                  d~d      xs4 Vj]                  d$d      xs t$        j                  xs ty        d%      }|t        d&      |&xsG Vj]                  dd      xs3 Vj]                  d'd      xs t$        jz                  xs ty        d(      }&|!xs1 t$        j                  xs t$        j                  xs ty        d)      }!t        jm                  | |Zt        VU|+tn        WO|&\|!|*      }dR|Vv rVdR   d@u rOdu rS }j|jS |-d+k(  r|&xs> Vj]                  dd      xs* Vj]                  d'd      xs t$        jz                  xs d,}&|!xs t$        j                  xs ty        d-      }!t%        j                  |.      }t        jm                  | ||t        VU|+tn        WO|&\|!|/      }dR|Vv rVdR   d@u rOdu rS }j|jS |-d0k(  r-t        jm                  | ||O|&ZVUd0||5tn        |!WP      }Z|Z}j|jS |-d1k(  r/t        jm                  | |Zt        VU\I|+tn        WO2      }Z|Z}j|jS |-d3k(  r\xs t$        j                  }\d4Vv rȐt        j                   d5       Vj]                  d4      }|j#                         j%                         }|j&                  rj&                  Vd6<   j(                  rj(                  Vd7<   j*                  rj*                  Vd8<   dDVvsVdD   j,                  j.                  VdD<   t1        j2                  |       }|d9k(  rA| j5                  d:d;      } t6        jm                  | |\ZVU|+tn        W||OP|&|!<      }j|jS d=k(  r@| j5                  d>d;      } t        jm                  | ||O|&ZVUd3||5tn        |!WP      }j|jS t        jm                  | ||O|&ZVUd3||5tn        |!WP      }jjS |-d?k(  r3t8        jm                  | ||5Zt        |!|&OWVU|+|\Ptn        d?@      }j|jS |-dAk(  rf|!xs= Vj]                  dBd      xs( t        dC      xs t        dD      xs t        dE      }!|&xsl Vj]                  dF|Vj]                  d|Vj]                  d'd                  xs6 t        dG      xs( t        dH      xs t        dI      xs t        dJ      }&Vj]                  dK|Vj]                  dLd            }d}|Zj	                  dF|&      }&|j	                  dB|j	                  dp|!            }!|j	                  dM|j	                  dNd            }VdM<   t        jm                  | ||O|&ZVUdA||5tn        |!WP      }j|jS |-dOk(  r^\xs t$        j                  }\t;        jl                  | ||\Zt        VU|+tn        WP
      }ZdR|Vv rVdR   d@u rt        Z| dOW      }j|jS Z}j|jS |-dQk(  rRt$        jz                  xs |&xs ty        dR      xs dS}&t        jm                  | ||O|&ZVUdQ||5tn        |!WP      }j|jS |-dTk(  rt$        jz                  xs |&xs ty        dR      xs dS}&|!xsE t$        j<                  xs2 t        j                  j	                  dU      xs t$        j                  }!t        jm                  | ||O|&ZVUdT||5tn        |!WP      }j|jS |-dVk(  r=t$        jz                  xs |&}&t        jm                  | ||O|&ZVU|-||5tn        |!Wܫ      }j|jS |-dWk(  r|!xs1 t$        j>                  xs t$        j                  xs ty        dX      }!ty        dY      }|&xs( t$        jz                  xs ty        dZ      xs d[ d\}&\xs t$        j                  }\t        jm                  | ||O|&ZVUdW||5tn        |!Wܫ      }j|jS |-d]k(  st$        jz                  d^k(  rd]}-|!xsE t$        j@                  xs2 t        j                  j	                  d_      xs t$        j                  }tC        jl                  | |Zt        VU|+tn        |W`
      }ZtE        jF                  |Z      sdRVv rVdR   d@u rt        Z| d]W      }j|jS Z}j|jS |-dak(  s| t$        jH                  v r}|&xs t$        jz                  }&da}-Vj]                  dRd      }tK        jl                  | ||&Zt        |VU|+tn        WPb      }Z|d@u r"Zdc   d   dd   d   }t        || daW      }j|jS Z}j|jS |-dek(  s| t$        jL                  v r?	 |du rtO        |f      nd}Pt        jm                  | ||5Z|!|&OWVU||P|-tn        |      }j|jS |-dgk(  rf|!xs1 t$        jP                  xs t        dh      xs t$        j                  }!t        jm                  | ||5Z|!|&OWVU|P|-tn        |tR              }j	 |jS |-dik(  rt$        jz                  xs |&xs d;}|d;k(  rt        dj      	 dj                  |D mcg c]  }m|md   	 c}m      }lt$        jT                  jW                  |5| |lg|
|||$j	                  dk      dldm|$j	                  di       n      }|jY                         }	 |do   d   dp   d   }|ZjZ                  d   j\                  _        ta        tc        jb                               |Z_        | |Z_        |Z}j|jS |-t$        jh                  v rd}t$        jj                  D ]  }|dq   |-k(  sdr   } tm        | |-      to        O|s      }|5xs t$        j                  }5 d{i d^| dg|d|5dtZdut        dp|!d|&d0OdvWdwVd<Ud|+d|dx\d1Pdxtn        }j|d@u rt        j| |-Wy      S jS tm        | |-      c c}Xw c c}^w # t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY w# t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY wc c}mw # t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY w# t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY w# t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY w# t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY w# t        $ r'}kWj                  ||!t        k      d|5i       |kd}k~kww xY wc c}mw # t        $ r}ktq        | |-k|%|$z      d}k~kww xY w(|  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.
    Nzmodel param not passed in.)r   )r   r  r  r  r  force_timeoutr   	logger_fnverboseFr  r  idmetadatar  proxy_server_requestr  provider_specific_headerheadersensure_alternating_rolesuser_continue_messageassistant_continue_messager   r   cooldown_timecontext_window_fallback_dictr   
ssl_verify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(disable_add_transform_inline_image_blocktext_completionatext_completionr   r   zno-logr  r	  )r   r  r  r  r   )r  r  r
  r  )r   r   r  r  r	  r
  r  
model_namelitellm_paramsdeploymentsrm  rH  Tr   r  r  r   r   r}  aws_region_nameregion_namerequest_timeout/r  r  litellm_providerr  r  r  model_file_id_mapping)r   model_idr  r   providerr   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   allowed_openai_paramsadditional_drop_params)r   passed_paramsspecial_paramsr  r  remove_sensitive_keysadd_provider_specific_paramsfunctions_unsupported_model)r   r   r   litellm_call_idmodel_alias_mapcompletion_call_idno_logazure_ad_token_providerlitellm_trace_idlitellm_session_idcustom_prompt_dictlitellm_metadatadrop_params"merge_reasoning_content_in_choicesuse_litellm_proxyazure_ad_token	tenant_id	client_idclient_secretazure_usernameazure_passwordazure_scoper   r   r   optional_paramsr  r  r  )
r   r   r  r  r  r   r  r  r  r   r  r  r  r   )responses_api_bridge)r   r   r  r  r   r  r   rh  r  r  r   r   r  encodingr   )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_TOKENrr  )r   r   r  r   r  r   dynamic_paramsr  r  r9  r  r  r  rh  r   r   r   r  )r   r   r  r   r  r   api_typer  r  r  r  r9  r  r  r  rh  r   r   r   )r  r   r  )rc  r   rt  additional_args
azure_text)r   r   r  r   r  r   r  r  r  r  r9  r  r  r  rh  r   r   r   deepseek)r   r   r  r  r   r  r   rh  r  r  r   r   r  r  r   provider_configazure_aiAZURE_AI_API_BASEAZURE_AI_API_KEYz	command-rr  zft:babbage-002zft:davinci-002r  OPENAI_BASE_URLOPENAI_API_BASEhttps://api.openai.com/v1OPENAI_API_KEYrj   )r   r   r  r9  r   r  r  r   r   rh  r  r  r  r   r  fireworks_aixaigroqGROQ_API_BASEzhttps://api.groq.com/openai/v1GROQ_API_KEY)r   r   r   r   r  r  r  r  r  r   r  r  r   rh  r   aiohttp_openaicustom_openai	deepinfra
perplexity
nvidia_nimcerebras	sambanova
volcengineanyscaletogether_ainebiuszft:gpt-3.5-turboOPENAI_ORGANIZATION)r   r   r  r  r9  r   r  r   rh  r  r  r  r   r  r   r   r  mistralMISTRAL_API_KEYMISTRAL_API_BASEzhttps://api.mistral.ai/v1)r   r   r  r  r  r  rh  r  r   r  r   r   r   r  r   r  	replicateREPLICATE_API_KEYREPLICATE_API_TOKENREPLICATE_API_BASEzhttps://api.replicate.com/v1)r   r   r  r  r9  r  r  r  r  r   rh  r  r   r  rs  clarifaiCLARIFAI_API_KEYCLARIFAI_API_TOKENCLARIFAI_API_BASEzhttps://api.clarifai.com/v2)r   r   fake_streamr   r   r  r  r  r  r  r   r  r  r   rh  anthropic_textANTHROPIC_API_KEYANTHROPIC_API_BASEANTHROPIC_BASE_URLz%https://api.anthropic.com/v1/completez/v1/complete)r   r   r   r   r  r  r  r  r  r   r  r  r   rh  rd  z%https://api.anthropic.com/v1/messagesz/v1/messages)r   r   r  r   r  r  r9  r  r  r  r  r   rh  r  r   r   r  	nlp_cloudNLP_CLOUD_API_KEYNLP_CLOUD_API_BASEzhttps://api.nlpcloud.io/v1/gpu/)r   r   r  r  r9  r  r  r  r  r   rh  )r  rh  rp   ALEPH_ALPHA_API_KEYALEPHALPHA_API_KEYALEPH_ALPHA_API_BASEz$https://api.aleph-alpha.com/complete)r   r   r  r  r9  r  r  r  r  default_max_tokens_to_sampler   rh  cohereCOHERE_API_KEY
CO_API_KEYCOHERE_API_BASEz!https://api.cohere.ai/v1/generatecohere_chatzhttps://api.cohere.ai/v1/chatmaritalkMARITALK_API_KEYMARITALK_API_BASEzhttps://chat.maritaca.ai/api)r   r   r  r  r9  r  r  r  r  r   rh  r  r  huggingfaceHF_TOKENHUGGINGFACE_API_KEYru   )r   r   r  r  r9  r  r  r   r  r  rh  
databricksDATABRICKS_API_BASEDATABRICKS_API_KEY	datarobot
openrouterOPENROUTER_API_BASEz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   togethercomputerrq   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=envertex_ai_betagemini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GEMINI_API_BASE)r   r   r  r9  r  r  r  r  r:  r7  r=  gemini_api_keyrh  r   r   r  r   r  r   	vertex_aiVERTEXAI_API_BASE)r   r   r  r9  r  r  r  r  r  r:  r7  r=  rh  r   r  r  r   r   )r   r   r  r9  r  r  r  r  r:  r7  r=  rh  r   	predibase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   r  r9  r  r  r  r  rh  r   r  r  r   r  r   r  z/https://codestral.mistral.ai/v1/fim/completionsCODESTRAL_API_KEYre  )r   r   r  r9  r  r  r  r  rh  r   r  r  r   r   sagemaker_chat	sagemaker)r   r   r  r9  r  r  r  r  r  r  rh  r   bedrock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_tokenconversez	converse/r  )r   r   r  r  r  r  r  r  rh  r   r   r   r   r  r   converse_likezconverse_like/watsonx)r   r   r  r  r9  r   r  r   rh  r  r  r  r   r  r   r  r  watsonx_textapikeyWATSONX_APIKEYWATSONX_API_KEY
WX_API_KEYrD  WATSONX_API_BASEWATSONX_URLWX_URLWML_URLwx_credentialswatsonx_credentialstokenwatsonx_tokenvllm)
r   r   r  r  r9  r  r  r  r  rh  ollamaOLLAMA_API_BASEhttp://localhost:11434ollama_chatOLLAMA_API_KEYtriton
cloudflareCLOUDFLARE_API_KEYCLOUDFLARE_ACCOUNT_IDCLOUDFLARE_API_BASEz.https://api.cloudflare.com/client/v4/accounts/z/ai/run/r\   zhttps://app.baseten.coBASETEN_API_KEY)
r   r   r  r9  r  r  r  r  r   rh  petals)r   r   r  r  r9  r  r  r  r  rh  r   rv  rE  	snowflaker_  bytezBYTEZ_API_KEYcustomzGapi_base not set. Set api_base or litellm.api_base for custom endpointstop_k)promptr   r   r   rt  )r   r   )r  jsondataoutputr  custom_handler)async_fnr   
custom_llmr  r9  rh  r  r  rf  r  r   )
ValueErrorrJ   rK   r   r   r   r   boolr   updater   r-  rS   r=   r!  r"  r#  get_chat_completion_promptr   r&  rR   batch_completion_modelsr  r   r|  r3   r<   hasattrr}  rL  rW  rH   readr   register_modelrT   r   r   valuer2   get_provider_chat_config'translate_developer_role_to_system_rolerW   r   rE   add_function_to_promptr   rV   r   update_environment_variablesr  r  litellm.completion_extrasr  rt   r  r  AzureOpenAIAsyncAzureOpenAIr`   rB   r  r   AZURE_DEFAULT_API_VERSIONr   	azure_keyr  AzureOpenAIO1Configis_o_series_model
get_configr   azure_o1_chat_completionsr9  AzureOpenAIConfigazure_chat_completionsr~  azure_text_completionsbase_llm_http_handlerr'  
openai_keyrZ   +openai_text_completion_compatible_providersr  r/  r   r%  listjoinopenai_text_completionsr0  groq_keyGroqChatConfigbase_llm_aiohttp_handleropen_ai_chat_completion_modelsopenai_compatible_providersenable_preview_featuresr5   OpenAIConfigopenai_chat_completionsreplicate_modelsreplicate_keyr  replicate_chat_completionclarifai_modelsclarifai_keyClarifaiConfig_convert_model_to_urlanthropic_keyosenvironendswithanthropic_chat_completionsnlp_cloud_keynlp_cloud_chat_completionr1   aleph_alpha_keyrp   r   
cohere_keyr.   maritalk_keyopenai_like_chat_completionhuggingface_keyru   getenvdatabricks_keyopenrouter_keyOpenrouterConfigtogether_ai_modelsr7  r:  r   vertex_chat_completion%vertex_partner_models_chat_completionis_vertex_partner_model#vertex_model_garden_chat_completionr   rG  predibase_keypredibase_chat_completionsr   codestral_text_completionssagemaker_llmrM   warning_get_credentialsget_frozen_credentials
access_key
secret_keyra  metar  r*   get_bedrock_router   bedrock_converse_chat_completionwatsonx_chat_completionvllm_handler
ollama_keycloudflare_api_keybaseten_keyr\   inspectisgeneratorpetals_modelspetals_handlersnowflake_modelsr,   	bytez_keybytez_transformationmodule_level_clientpostrv  rv  rE  rj  r   r]  rz  r   _custom_providerscustom_provider_mapr   rn   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:  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  r  r  r   r   r  r  r	  r  r  r  r  mr  r  dynamic_api_keyr  r  r  optional_param_argsprocessed_non_default_paramsr  r  r  r  r  r  configr   r   r   r7  ru  rE  	_responser  r  r  r  r  r  r  
hf_headersopenrouter_site_urlopenrouter_app_nameopenrouter_headers_headersrw  r8  r;  r=  rC  
new_paramsr  _model_responsetext_completion_model_responserO  credsbedrock_router_  ra  
account_idr  resp_stringrD  respresponse_jsonstring_responsery  item
handler_fns                                                                                                                                                      r   rt   rt   e  s?   x }566/BH6;OK8Dzz*d+HJJ5Mjj!2D9O

>4(HILJJ4M

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

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

;-I

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

 #
 f#
 n#
 D#
 *#
 $%:#
 *#
 *#
 U#
  0#
  !2#
  *!#
" D##
& U'#
( "#6)#
* +#
, D-#
. U/#
0 ;1#
2 ;3#
4 5#
6 L7#
8 ;9#
: "#6;#
< =#
>  0?#
@ A#
B !"4C#
D $VZZ0G%HE#
H . 
!
%7
 (F-- 3#)::.F#G"&)-(
$ ))o.A.A)4/
 +:*=*=-+' ,!-HH
 , 1
#1
1
 (1
  	1

 1
 !41
 1
 #JJ'8$?1
 $331
  "1
 1
 "1
 "61
 .1
 1
  #8!1
" "6#1
$ $:%1
& #8'1
( ()1
* #JJ'89+1
, %+JJ/H$I-1
. #)**-D"E/1
0 "11
2 $ZZ(:;31
4  &zz*>?51
6 (71
8  291
: $ZZ(:;;1
< 6^=1
> 

=1?1
@  A1
B .C1
D "E1
F 06zz4d0G1
L %jj)<eDM1
N $O1
P "::&67Q1
R jj-S1
T jj-U1
V !**_5W1
X "::&67Y1
Z "::&67[1
\ 

=1]1
^ $_1
` a1
d 	(EE8) 3 	F 	
 O|JJ~t,"+ /'!::lD9$7)   7-@

E >>&![0F'22!-!'# /-$7! 3  $ ') #N!66#5#5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 $ .,-  '5&8&8)4'# 0G(3@0&1<.**,>>U>K 44??A"LLNDAq0-.*	 + 5??%##% +#1#1#1"/$3#1' ' +#!(;% @ , !22==?"LLNDAq0-.*	 + 2<<%##% +%#1#1,C#1"/$3#1' ' +#!' = , ""8U3!!"#&.#*'2$,%	 " 	~< k< !L0!"23>wHS7#3#3SzBR7SH Uw22UjAT6U 
  /??/$$/ 45/ o.  -00rBFF $ .,-  '5&8&8)4'# 0G(3@0 ..99;F1_,)*OA&	 ' .88!!'!-(?-+ /-##'% 9 H* ""8U3{d7J!!"#&.#*'2$,%	 " 	l: Y: !J.0;;%##1#% + '$3#1#!(;%!$3! < R: [9 !J. 3##312   2??2%%2 01	  0G(3@0 e#;XN0;;%##1#% + '$3#1#!(;%! < 6 ""8U3!!"#&.%.$8	 " n7 a7  #;;5(5("BBC

,-5&FO  /##//0/ /0/ /  "&F  0??0%%0 ./	  0G(3@0 77BBDF1_,)*OA&	 '
 ##&-&:&:# H!!,x{95t< "!Y/X"N'79#5"NO 0::!-+$7!'# /-# ; I$  ##He4=5(#u, $>>@ff$-^ g 	 ""8U3{d7J!!"#&/%.$8	 "  !Hn4 m4 !N20;;%##1#% + '$3#1#!(;%!$3! < f4 q3 !E)0;;%##1#% + '$3#1#!(;%!$3! < j3 u2 !F* 4##4o.4 4	   .??.##. n-	  0G ++668F1_,)*OA&	 ' -77!'!- /-$7!# 8 H@2 _1 !$44  /##//0/ /0/ /   0??0%%0 ./	  0G(3@0/::!-!'# /-$7! ; Ht0 Q0 W;;;"o5"k1"l2"l2"j0"k1"l2"j0"h."m3"h."g&I&II!U*
  /##//0/ /0/ /   ''34 	  #/F  0??0%%0 ./	  0G(3@0 //H4H.A(.K
+ ))446F1_,)*OA&	 '2==%##1"/#% + '$3#1'#'9!!-(;# > : ""8U3!!"#&.%.$8	 " \- O- !I-QQJ?P4QG /##/01/ /	  -77!!$7-!# /-' /! 8 H|, W, 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 "  &Hx* u* %"j0///L 4''4??4 014 23   1##1121 1	  --/EEeXVH,77 !'!- /-$.!$# 8 HL* k) !$44 7((7??7 ::>>"56	  "4!Qw7Q7Q ;##;23; 23; ;  #H,=,=n,MN*,77!'!- /-$4!# 8 HD) e( !K/ 7((7??7 ::>>"56	  "4!Qw7Q7Q  ;##;23; 23; ;  #H,=,=n,MN*1<<!!'#*#=#=-+ /-#!#$7# = H& ""8U3{d7J!!"#&. " 
  HF' E' !K/ #((#12# ??	   5##5235 5	  1!!-+ /-#!%#H ?*x/HD/P.(3 '	 ""8U3{d7J!!"#&. "   Hh% g% !M1 #**#34# 23# ??   :##:45: :	  )33!!-+ /-#!-4-?-?'#N ?*x/HD/P."(5 '	  %HV$ U$ !H, #%%#./# l+# ??   7##7/07 7	  66BG(}-,77!'!- /-$,!"# 8 Hf# E# !M1 #%%#!"23# ",/# ??   3##3!"343 3	  66BG(}-,77!'!- /-$1!"# 8 HV" w! !J. #''#01# ??	   2##2122 2	  9CC!!-+ /-#!$#$.#5 D N  &Hx  w  !M1 #**#::>>*-# ::>>"78# ??  !3GOOJ,77!"-'!'# /-$7! 8 Hd  C  !K/"-&11!-!+ /-#!#N ?*x/HD/P."(3 '	  %HR Q !L0 4##49923   4??4))4 23	  0G0;;!% +%#1$3#1(4##%# '! < 6 ""8U3!!"#&.%.$8	 " p c !K/,77!-!'# /-$7! /! 8 H` } !L0 2##2!"782 2	   ,??,)), 23, l+  #-]";"S?S",]";"Hy !4."
 1'//H"))(3(G --88:F1$#6'*11!4-.*o-)*OA& ' #LOLD -77!'!- /-$0!# 8 H$ (  ~ w  =0"e+333 h g !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-# ??	   T7#3#3TzBS7TH!/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   V7#3#3VzBU7VH!/2J4LLUS!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%HJ I !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(&&&H` _ !$?? 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(&&&HR Q !$442==!'!- /-$4!# > 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 ->>uEM
*k26;FF%'9#1$3#1'% '"/# +!%# G D c /1&6;0;;!% +%#1$3#1(1##%# '! < ^ { 1;;!% +%#1$3#1(1##%# '! < z Y !I-.99!-+!'# /-##5!$-# : HV q !N2 0"&&x60!"230 ""340 ",/   
-"&&#''"O$7$7
D$I
- ""45
- "-0
- "(+
- "),  -00 ##)4N $(E))--eX>(,,n00GD '**"&&'  +0(,77!'!- /-$2!# 8 HT s !F*!3!Qw7Q7Q)44!#5-+ /-#!#N O+0IT0Q /"(. '	   &Hz
 y
 !H,   ,,/0, ,	  -77!'!- /-$,!# 8 Hj
 G
 !M1   ,,/0, ,	   #%%#::>>"23# ??	  -77!'!- /-$1!# 8 Hh	 E	 !H,''38H,77!'!- /-$7!# 8 H@	 a !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O+0IT0Q /"(1 '	  %HZ Y !H,9N9N0N37#3#3H"*$((59F+66!!-+ /-#!#N ~,Y7:9EiP.(0 '	  %H` _ !K/5G<T<T3T4:eOK0  1;;%##1#% + '$3#1#!(;%! < T ] !G+ #$$#!/2# ??	  -77!-!'# /-$7! 4! 8 H& f c !H,""4h4"C{cRi ] " XXJgwy1JKF..33"#)(&0'2!&!'G!4
 jjr2
 4 D !IIKM ,F3A6x@CO8GN""1%--5%(%5N"#(N %Hl g  7#<#<< 37N33
#'::%)*:%;N 4 %,5H 
 0$VJ 0G " !    .	
 ,   " ( $ !0  . $   $6   "!H$ ~*&.(; '	   )1D KIJG
X  !!"#&)!f%.$8	 "  h  !!"#&)!f%.$8	 "  L #Ox  !!"#&)!f%.$8	 "  <  !!"#&)!f%.$8	 "  R  !!"#&)!f%.$8	 "  l  !!"#&)!f%.$8	 "  X  !!"#&)!f%.$8	 "  ~ Kt  
 3 "
 	

s  +CH CH CBCB#CH =I+CH (CB;M	CH ACH F/CH A+CH /ACH D+CH ;A"CH CH $)CB CH BCH (CC <*CH 'DCH C*A3CH ECDE)BCH H	CH H)CD
 H8CH H:CH I )CD= I)CH I+B)CH L0CH MB.CH O5E(CH UCH U&*CE0 V*CH V;A5CH X1C CH \CCH _"CCH b5DCH g
CCH jB<CH m
CH mCCH pCCH sB
CH uB*CH x	A
CH yCH yA8CH {(CF# {9*CH |$0CH }DCH A3ACH C CH C0E8CH I)HCH RCH RDCH V#CH V'B?CH Y'CH Y+2CH Z4CH [ECH `ACH a*CH b
8CH cE,CH h0ACH jCH jACH k,B CH nACH oB0CH rCCH uCH uBCH wCH wCH w8<CG x4CH x6A+CH z"ACH {&CH	{2CCH ~>2CH 1BCH BCH BCH B	CCB("CC
C
CCCCH C	CDC"CC=C=CDDCH D
	CD:D"CD5D5CD:D:CH D=	CE-E"CE(E(CE-E-CH E0	CF E9"CFFCF F CH F#	CGF,"CGGCGGCH G	CHG"CHHCHHCH H	CH.HCH)H)CH.c                     	 ddl }|j                  dd      }d|d<   d|d<   |j                  dd      }|j                  d	t              }|d
k(  r5|j	                  |j                  dd      |j                  |      d      }n"|j	                  |j                  |      d      } ||g| i |S # t        $ r}t        d|       d}~ww xY w)z8
    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_retryrL   
   
multipliermaxTr   r  reraiser  r  )tenacityr'  r   rt   Retryingwait_exponentialstop_after_attemptr:  r   r   r7  r   r  r  retryers           r   completion_with_retriesr  l  s   
 **]A.KF=F=MSZZ*NN 

#6
C44##**aR*@,,[9 $ 
 ##,,[94 $ 
 $6t6v66/  
MaSQ
 	

s   B2 2	C;C		Cc                    K   	 ddl }|j                  dd      }d|d<   d|d<   |j                  dd      }|j                  d	t              }|d
k(  r5|j	                  |j                  dd      |j                  |      d      }n"|j	                  |j                  |      d      } ||g| i | d{   S # t        $ r}t        d|       d}~ww xY w7 #w)z{
    [DEPRECATED]. Use 'acompletion' or router.acompletion instead!
    Executes a litellm.completion() with 3 retries
    r   Nr  r   r  r   r  r  r  r  rL   r  r  Tr  r  )r   r'  r   rt   AsyncRetryingr  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B< B/C7C8C<	CCCCc                    K   t        j                         }t        |       dkD  r| d   n|d   }d|d<   d}	 t        t        g| i |}t        j                         }t        |j                  |      }t        ||j                  dd            \  }}}}|j                  d|       d{   }	d}
t        |	t              rt        di |	}
n2t        |	t              r|	}
nt        j                  |	      r
|	 d{   }
|
+t        |
t              rt        |
d      r||
j                   d	<   |
t#        d
      |
S 7 7 B# t$        $ r}|xs d}t'        |||| |      d}~ww xY ww)ay  
    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  zCUnable to get Embedding Response. Please pass a valid llm_provider.r  r  r   )r  r   r%  r   	embeddingr)  r*  r+  r<   r   r,  r!  r-  r   r.  r  r}  r|  r'  r   r:  r   r  r   r  r3  r4  r5  r2  r6  r   r7  s               r   r  r    s     !!#D4y1}DG&/EF<*
y24262 &&(#CGGT2'7&**Z">(
$1
 #2249JKK04mT*(9=9H'89$H  /**H 8%67"23=PH##$9:U  ) L +  
1=X 3 "
 	

sN   4E'A4E  +D<,AE  ;D><?E  ;E'<E  >E   	E$	EE$$E'r   
dimensionsencoding_formatr  r  cachingr  Tc                     y r   r   r   rc  r  r  r   r  r   r   r  r  r   r  r  r  r  r   s                   r   r  r        , r   )r  c                     y r   r   r  s                   r   r  r    r  r   c                    |j                  dd      }|j                  dd      }|j                  dd      }|j                  d      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  d	d      }|j                  d
d      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }g d}dd	gt        z   }||z   }|j                         D  ci c]  \  }} ||vs||  }!}} t	        | |||      \  } }}"}|"|"}t        d| |
|||d|!}#|"| t        j                  | d|  |||di       |&|xs d}t        j                  | d|  |||di       t        di |}$|}%|%j                  | |
|#|$|       |t        | |      S 	 d}&|du s|dk(  r|xs t        j                  xs t        d      }|xs/ t        j                  xs t        d      xs t        j                  }|#j                  dd      xs t        d      }'|xs/ t        j                  xs t        j                   xs t        d      }|t#        d      t$        j'                  | |||||'||%|t)               |#||||xs ||$      }&
n| t        j*                  v s|d k(  s|d!k(  s
|d"k(  s|d#k(  r|xs. t        j                  xs t        d$      xs t        d%      xs d&}t        j,                  xs t        d'      xs dt.        _        |xs/ t        j                  xs t        j0                  xs t        d(      }|||#d	<   d}t2        j'                  | ||||%|t)               |#|||)      }&	n|d*k(  r}|xs t        j                  xs t5        d+      }|xs/ t        j                  xs t        j6                  xs t5        d,      }t8        j'                  | ||||%|t)               |#||-
      }&n|d.k(  s|d/k(  s|d0k(  s
|d1k(  s|d2k(  r|xs t        j                  xs t        d3      }|3|xs/ t        j                  xs t        j:                  xs t        d4      }t<        j'                  | ||||%|t)               |#||-
      }&n|d5k(  s|d6k(  r|xs< t        j>                  xs* t        d7      xs t        d8      xs t        j                  }(|tA        |tB              r|}ni }tD        j'                  | ||||(|%|t)               |#|||$|9      }&nr|d:k(  ra|xs/ t        jF                  xs t5        d;      xs t        j                  }tH        j'                  | |tJ        |||%t)               |#|||$<      }&n|d=k(  rKtA        |tL              r|g})n|})tN        jQ                  | |)tJ        |%|#t)               |||i |tR        ||>      }&n|d?k(  r8|t#        d@      tD        j'                  | |||||%|t)               |#||i A      }&n|dBk(  rx|xs t        dC      xs t        j                  }*|xs t        j                  xs t        dD      }tT        jW                  | |tJ        |%|#t)               ddd|tR        dB|*||E      }&n|dFk(  r|#j                  dGd      xs> |#j                  dHd      xs* t        jX                  xs t        dI      xs t        dJ      }+|#j                  dKd      xs> |#j                  dLd      xs* t        jZ                  xs t        dM      xs t        dN      },|#j                  dOd      xs, |#j                  dPd      xs t        dQ      xs t        dR      }-|xs* t        j                  xs t        dS      xs t        dT      }dU|#v sdV|#v s| t\        j^                  v r6t\        ja                  | |tJ        |%|#|$t)               |+|,|-|tR        dF||W      }&ntb        j'                  | |tJ        |%|#t)               |+|,|-dF||tR        |||X      }&nc|dYk(  r+te        j&                  | |tJ        ||%|#t)               |Z      }&n3|d[k(  rt        j                  xs |xs t        d\      xs d]}tA        |tL              r|g}tg        d^ |D              st        jh                  d_| | d[`      |du rtj        jl                  ntj        jn                  }. |.|| |tJ        |%|#t)               a      }&n|dbk(  r.tp        j'                  | |tJ        |%|#t)               tR        c      }&nU|ddk(  rJ|xs t        j                  xs t        de      }t2        j'                  | ||||%|t)               |#||-
      }&n|dfk(  rJ|xs t        j                  xs t        dg      }t2        j'                  | ||||%|t)               |#||-
      }&n|dhk(  ro|xs t        j                  xs t        di      }|xs! t        j                  xs t        dj      xs dk}t2        j'                  | ||||%|t)               |#||-
      }&nC|dlk(  r+tD        j'                  | |||||%|t)               |#||i A      }&n|dmk(  r+tD        j'                  | |||||%|t)               |#||i A      }&n|dnk(  rYts        jt                  |#||o      }/|/dp   }|/dq   }dr|/v r|/dr   |#dr<   tD        j'                  | |||||%|t)               |#i ||s      }&n|dtk(  rs|xs! t        j                  xs t        du      xs dv}|xs! t        j                  xs t        dw      xs dx}t2        j'                  | ||||%|t)               |#||-
      }&n|dyk(  r||xs t        j                  xs t        dz      }|xs/ t        j                  xs t        j0                  xs t        d{      }tv        j'                  | ||||%|t)               |#||-
      }&n|t        jx                  v rmd}0t        jz                  D ]  }1|1d|   |k(  s|1d}   }0 |0t}        | |~      |s|0j&                  n|0j~                  }2 |2| ||%||||#t)               tR        |$
      }&nt}        | |~      |&+t        |&d      rtA        |&t(              r||&j                  d<   |&t}        | |~      |&S c c} }w # t        $ r1}3|j                  ||tM        |3             t        | |3||      d}3~3ww xY w)aw  
    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.
    rH  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  )r   r   r  r  r  r  r  g        r  r  )r   r  Tr  r  r  r  r  zPNo API Base provided for Azure OpenAI LLM provider. Set 'AZURE_API_BASE' in .env)r   rc  r  r   r   r  r  rh  r   r  r  r   r  r   r  r  r  r  r  litellm_proxyr  r  r  r  r  )r   rc  r  r   rh  r   r  r  r   r  r   r)  r*  r+  )
r   rc  r  r   rh  r   r  r  r   r  openai_likejina_aihosted_vllm	llamafile	lm_studioOPENAI_LIKE_API_BASEOPENAI_LIKE_API_KEYr  r"  r  r   )r   rc  r  r  r   rh  r   r  r  r   r  r  r  r&  r(  )r   rc  r  r   r  rh  r  r  r   r  r  rN  )r   rc  r  rh  r  r  r   r   r  r  r  r9  r   r   ri  z7api_base is required for triton. Please pass `api_base`)r   rc  r  r  r   rh  r   r  r  r   r  r  r6  r@  rB  )r   rc  r  rh  r  r  r7  r:  r=  r  r9  r  r   r  r   rD  r7  r8  r9  VERTEX_PROJECTr:  r;  r<  VERTEX_LOCATIONr=  r>  r?  VERTEX_CREDENTIALSrE  VERTEX_API_BASEimagevideo)r   rc  r  rh  r  r  r  r7  r:  r=  r  r9  r  r   r  )r   rc  r  rh  r  r  r7  r:  r=  r  r   r  r9  r   r  r   ru   )r   rc  r  r  rh  r  r  r   rd  re  rf  c              3   <   K   | ]  }t        |t                y wr   )r!  r   ).0r  s     r   	<genexpr>zembedding.<locals>.<genexpr>  s     ?z$,?s   z+Invalid input for ollama embeddings. input=rE  r   rA  )r  r   promptsr  rh  r  r  rM  )r   rc  r  rh  r  r  r9  r  r  r  FIREWORKS_AI_API_KEYr  NEBIUS_API_KEYNEBIUS_API_BASEzapi.studio.nebius.ai/v1voyageinfinityrU  )r  r   r  r   r  ra  )r   rc  r  r  r   rh  r   r  r  r  r   r  
xinferenceXINFERENCE_API_KEYzstub-xinference-keyXINFERENCE_API_BASEzhttp://127.0.0.1:9997/v1r  r  r  r  ry  r  )
r   rc  rh  r  r   r   r  r  r9  r  r}  r  rs  )r   r  r  r  r   )Er   r   r   r   r<   r?   r   r  r   r  r%   r  r.   r   r  r   r  r|  r  r  r   open_ai_embedding_modelsr   r  r  r  rB   r  databricks_embeddingopenai_like_keyopenai_like_embeddingr  r!  r-  r  r  huggingface_embedr  r   bedrock_embedding
embeddingsr9  google_batch_embeddingsbatch_embeddingsr7  r:  vertex_multimodal_embedding%SUPPORTED_MULTIMODAL_EMBEDDING_MODELSmultimodal_embeddingvertex_embeddingru   allBadRequestErrorrd  ollama_aembeddingsollama_embeddingsr  r   get_watsonx_credentialsazure_ai_embeddingr  r  r   r  r  r}  r'  r~  r   )4r   rc  r  r  r   r  r   r   r  r  r   r  r  r  r   rH  r   r   r  r  r  r  r   r  r  r  r  r  openai_paramsr  default_paramsr   r   r  r  r  litellm_params_dictr  r   r  r  transformed_inputrC  r8  r;  r=  ollama_embeddings_fncredentialsry  r  r  r7  s4                                                       r   r  r  !  s   Z JJw%EZZ$'F**]D1K-3ZZ8M-N+1::ot+LM$jj)BDI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 ',A,M&'q0,@-B(;3	
 (!7!>3&'q0-B.D(;3	
 -6v6*G(('*/ )   EGG`	
  	 D=/7:  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=2! 8 H& W555"h."m3"l2"o5  /##/!"34/ ""34/ /  $$ !"78   4??4%%4 ""23	  (3@0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"k1"k1 VG,,V?U0V 
  ==..= &&;<	  -66!#02 /% 7 H !H,0C}0T #%%#!"23# ",/# ??  (Zt-L',66$7!"#02 /%2 7 H !M1 #**#34# ??	  )22!!#02 /%2 3 H !I-%%%*G!$)!(33'!# /02%!!++ 4 H  !H, M  -66$7!#02 /%! 7 H !H,N>*:;Nw   X7#3#3X~FW7XH.??!# /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	   5##5!"565 ""34	  ?*o-.TTU 7KK% '$3#6#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,TTNCS4TG -##-!"34- -	  /88!#02 /% 9 H !H,,66$7!#02 /%! 7 H !J.,66$7!#02 /%! 7 H !I-)AA /8K "),G":.H+%+6w+?(,66$7!#02 /!% 7 H !L0 )??)!"67) )	   .##.!"78. .	  /88!#02 /% 9 H !J. 7##7!"56   6??6%%6 ""45	  *33!#02 /% 4 H !G$=$==26N33
#'::%)*:%;N 4 %,5H  " ((#..  "#! /02+2H )1D   "238%67=PH##$9:(1D  [\  
%%!!f 	& 	
   3	
 	

s,   s>s>jt $Bt 	t>,t99t>c                    K   t        j                         }t        |       dkD  r| d   n|d   }d|d<   d}	 t        t        g| i |}t        j                         }t        |j                  |      }|j                  d|       d{   }t        |t              st        |t              rt        |t              rt        di |}	n%|}	n"t        j                  |      r| d{   }	n|}	|j                  dd      du s t        |	t              st        |	t              r+t        t!        |	|||       |||j                  d	      
      S t        |	t              r|	S t        j                  |	      r
|	 d{   }	t               }
t"        j$                  j&                  j)                  |
|	|      }
|
S 7 .7 7 A# t*        $ r}|xs d}t-        |||| |      d}~ww xY ww)zP
    Implemented to handle async streaming for the text completion endpoint
    r   r   Tr   Nr   F)r   r   r  r:  r   )rg  r   r  r   )text_completion_responser   r  r  r  r   )r  r   r%  r   r  r)  r*  r+  r,  r!  r-  r   r.  r   r   r1   r<  r   rx  LiteLLMResponseObjectHandlerconvert_chat_to_text_completionr'  r   )r:  r   r  r   r  r3  r4  r5  r6  r   rK  r7  s               r   r  r    s     !!#D4y1}DG&/E F=;
888 &&(#CGGT2"2249JKKmT*j1/
 -.1BMB(  /**H$H JJx'4/($?@($78."2%(;	# $7%zz*:;
 
 ($:;$$X.!)>'='?$'.}}'Q'Q'q'q)A!$7 (r ($
 ,+U L +2 *  
1=X 3 "
 	

sy   4G%AF> 	F7
AF> 'F:(A%F> G%F> G% F> :F<;;F> 6G%7F> :F> <F> >	G"GG""G%ru  best_ofechor  suffixc           
        )*+ dd l }	 dv r*d   }t        |t              r|j                  d       t	               *i )||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d	<   |	|	)d
<   |
|
)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   ||)d<   t        ||      \  }}}}|dk(  r	|du r	dvrdd<   t        | t              rdd l}t        j                  d      +t        |       dkD  rt        | d   t              r| D cg c]  }d  }})*+fd}|j                  j                         5 } t        |       D !"cg c]  \  }!}"| j                  ||!|"       }#}!}"t        |j                  j                  |#            D ]  \  }!}$|$j!                         ||!<    |*_        d d d        *S g }%t        | t              r?t        |       dkD  r1t        | d   t              r| D ]  }&d|&d}'|%j%                  |'        nt        | t              rd| dg}%nv|dk(  s|dk(  s|d k(  s
|d!k(  s|d"k(  rNt        | t              r>t        |       dkD  r0t        | d   t              rt'        j(                  d#$       d| dg}%nt+        d%|  d&      j                  d'd        |.|dk(  r)|t,        j.                  vrd(|z   )j                  dd        t1        d)      dd*<   t3        |%d+)}(j5                  d,d-      du r|(S |du s$j5                  dd-      du st        |(t6              rt9        |(||.      }(|(S t        |(t8              r|(S t        |(t              r|(S t,        j:                  j<                  j?                  |(*/      **S c c}w c c}"}!w # 1 sw Y   *S xY w)0Nr   enginerN  rO  r   r   r   r   r   r   r  r   r   rP  r   r   r   r  r   r   r  r   r  r  r&  Ttop_n_tokensr  ztext-davinci-003c                     
j                  |      }i }t        |dd|}|j                  dd       	d<   d	d<   |j                  dd       	d<   |j                  dd       	d<   |d   d	   S )
Nr  )r   ru  r   r  r  objectrz  r   rv  r   )decoder  r   )r  individual_promptdecoded_prompt
all_paramsr   r:  r   r   r  rK  	tokenizers        r   process_promptz'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   )rk  rj  r  rH  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/issuesru  ztext-completion-openai/z;model is not set. Set either via 'model' or 'engine' param.r  r   r   F)rg  r   r   r  )r   rK  ) copyr!  r   r   r   r<   r  concurrent.futurestiktokenencoding_for_modelr%  r   r   	enumeratesubmitas_completedresultrv  ry  rM   r  r'  r   r  r|  rt   r   r1   r   rx  rL  rM  ),ru  r   rN  rO  r   r   r   r   r   r   r  r   r   rP  r   r   r   r  r   r   r   r  r:  r   r^  _engine_modelr  
concurrentxr  r\  executorr  rX  completed_futuresfuturer   prE  r   r  rK  r[  s,    `                    ``                 @@@r   r  r  Z  s   j 4 6"=Z5E

857&(O%,	""&$/@+,(2%&.
#(2%} #.>*+"&$*!!,:()$*!)4&#( "&&.
#)4&%,	"&1D-. >N/>:F( m+4<V+)*~& fd#% 334FGI6{Q:fQi#>+12aT2	22 2"  ''::< 	A 5>f4E)0A0 !;LM)% ) &/"**778IJ&	6 (.}}	!& 8A,4	A 0/ H&$CK!O
6!9c8R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.&) 3	
 	H9	: (23 	22RR%= 	S 	
  $#a 3()	A 0/s%   ?	O.O=OA	OOO$
adapter_idc                   K   	 d}t         j                  D ]  }|d   | k(  s|d   } |)t        dj                  | t         j                              |j	                  |      }t        di | d{   }d}t        |t              r|j                  |      }t        |t              r|j                  |      }|S 7 L# t        $ r}|d}~ww xY ww)	zD
    Implemented to handle async calls for adapter_completion()
    Nr  adapterHNo matching adapter given. Received 'adapter_id'={}, litellm.adapters={}r  r   rg  r   )r   adaptersr|  r  !translate_completion_input_paramsr   r!  r   "translate_completion_output_paramsr1   ,translate_completion_output_params_streamingr'  )rn  r   translation_objr  
new_kwargsr   translated_responser7  s           r   aadapter_completionr{  h  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LL&. M    #" ?^   sA   CC AC 4C5AC  CC 	CCCCc                    d }t         j                  D ]  }|d   | k(  s|d   } |)t        dj                  | t         j                              |j	                  |      }t        di |}d }t        |t              r|j                  |      }|S t        |t              st        j                  |      r|j                  |      }|S )Nr  rp  rq  r  rr  rs  r   )r   rt  r|  r  ru  rt   r!  r   rv  r1   r  r  rw  )rn  r   rx  r  ry  r   rz  s          r   adapter_completionr}    s     /3O  :#"9oO ! V]]G,,
 	
 !BB&BQJ:D:Rz:RH  (M*-PP Q 
  
H1	2g6I6I(6SHH"* I  	 r   rc  c                    |xs/ t         j                  xs t         j                  xs t        d      }|j	                  dd       }|t        j                  |      }||j                  j                  | |      }n|j                  j                  |       }|j                         }t         j                  j                  j                  |      S )Nr  r   )r   rc  r   rc  r  )r   r   r  r.   r   r  OpenAImoderationsr   
model_dumprx  rL  convert_to_moderation_response)rc  r   r   r   openai_clientr   response_dicts          r   
moderationr    s    
 	 	,??	,	, *+	  JJx.M
  ,,33%u3M ,,33%3@"--/M==55TT% U  r   c                   K   ddl m} |xs/ t        j                  xs t        j                  xs t        d      }|j                  dd       }|t        ||      st        j                  d|      }n|}t        di |}|j                  dd       }		 t        j                  |xs d||j                  |j                  	      \  }}}
}|xs$ t        j                  j                  j                   }|	(|	j#                  ||j                  d
d       i i ||       |&|j$                  j'                  | |       d {   }n$|j$                  j'                  |        d {   }|j)                         }t        j*                  j,                  j/                  |      S # t        j                  $ r Y w xY w7 |7 Yw)Nr   )AsyncOpenAIr  r   T)is_asyncr   r  r  r  r   r  r  r  r  r   )r  r  r   r   r  r.   r   r!  r  _get_openai_clientr/   r<   r  r?  r   OPENAIr  r  r  r   r  rx  rL  r  )rc  r   r   r  r   r  r  _openai_clientr  r  _dynamic_api_key_dynamic_api_baser   r  s                 r   amoderationr    s     # 	 	,??	,	, *+	  JJx.MJ}k$J '>&P&P 'Q '

 '*4V4O7=zzt8 $$+2 3$--#++	
	
 .R1E1E1L1L1R1R&88FD) !4 	9 	
 '33::e:TT'33:::GG"--/M==55TT% U  - "" $ UGsI   BF?6F" 
A4F?>F;?$F?#F=$>F?"F85F?7F88F?=F?c                    K   t        j                         }t        |       dkD  r| d   n|d   }d|d<   d}	 t        t        g| i |}t        j                         }t        |j                  |      }t        ||j                  dd            \  }}}}|j                  d|       d{   }	t        |	t              rt        di |	}
nMt        |	t              r|	}
n:t        j                  |	      r|	 d{   }
n|j                  d|       d{   }
t        |
t              st        dt!        |
             |
S 7 7 J7 1# t"        $ r}|xs d	}t%        |||| |
      d}~ww xY ww)a
    Calls openai + azure whisper endpoints.

    Allows router to load balance between them
    r   r   TatranscriptionNr  r  zVInvalid response from transcription provider, expected TranscriptionResponse, but got r  r  r   )r  r   r%  r   transcriptionr)  r*  r+  r<   r   r,  r!  r-  r   r.  r|  typer'  r   r  s               r   r  r    s     !!#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($9:himnviwhxy   L + K  
1=X 3 "
 	

s`   4E/A4E +E,AE 9E:E E,E E/E E E 	E,E''E,,E/filelanguage)rv  r@  srtverbose_jsonvtttimestamp_granularities)wordsegmentr   c                 0   |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  d      }|j                  d	d      }|j                  d
g        t        |      }|j                  dd      }|rt        |      |j                  d<   |t
        j                  }t        j                  j                         }t        | ||
      \  } }}}
||}	t        d!| ||||||d|}t        d!i |}|j                  | |i ||||di d||       d}t        j                  | t!        |            }|dk(  r|
xs t        j"                  xs t%        d      }
|xs t        j&                  xs t%        d      }|j                  dd      xs t%        d      }|	xs/ t        j(                  xs t        j*                  xs t%        d      }	||d	<   t,        j/                  | ||||||||
|	||||      }nG|dk(  s|t        j0                  v r|
xs. t        j"                  xs t3        d      xs t3        d      xs d}
t        j4                  xs t3        d      xs dt
        _        |	xs/ t        j(                  xs t        j6                  xs t3        d      }	t8        j/                  | |||||||||
|	||      }n~|t         j:                  j<                  t         j>                  j<                  fv rHt@        j/                  | ||||||"tC        |tD              stC        |tF              r|nd||||
|	|i |      }|tI        d       |S )"r  r  Nr  r  r  r  Fr  r   tagsr   rS  )r   r  ru  r   r  r   r  r  r  r  r  r  stream_responser  r  rH  r  r  r  r  r  )r   
audio_filer  r  r  r   r   rh  r  r   r   r  r   r  r  r  r  r  r  r  )r   r  r  r  r  r   r   rh  r   r  r   r  r  )r   r  r  r  r  r  r   r   r   rh  r  r   r  r  r  z8Unmapped provider passed in. Unable to get the response.r   )%r   r   r>   r   model_call_detailsr  DEFAULT_MAX_RETRIESr   rx  r   r<   rA   r   r  r2   'get_provider_audio_transcription_configr   r  r.   r   r   r  azure_audio_transcriptionsaudio_transcriptionsr  rB   r   r  openai_audio_transcriptionsDEEPGRAMr  
ELEVENLABSr  r!  r,   r+   r|  )r   r  r  ru  r   r  r   r   r   r   r  r   r   r  r   r  r  r  r  r  r  r   r  r   r  r  r  rF  r   r  r  s                                  r   r  r  P  s>   6 jj!2D9O!::&<dCL$/Jzz*d+HZZ 0%8NZZ 0%8N-3ZZ8M-NJJ5M
JJvr=fE 	

8T"  ;>v;..x800]]88:N<L)<x=9E "!7 	' 7/	 	O -6v644.$8$  $!
 
 0 5 $ 	  ,SS12O
 g%Sw//S>BR3S U7..U.AT2U 	  $4d; 
~@

  //  / o.	 	 ,9(-BB+))+#)#. C 
" 	x''"E"EE  +++,+ +,+ + 	    /0 	 bW__b0B0BbjQaFb.CC+))+#+. D 
 
##%%! 
 )==+.)) %v{3!&*:;	  #+ 3+/ > 
2 STTOr   c                  X  K   t        j                         }t        |       dkD  r| d   n|d   }d|d<   |j                  dd      }	 t	        t
        g| i |}t        j                         }t	        |j                  |      }t        ||j                  dd            \  }}}}|j                  d|       d{   }	t        j                  |	      r|	 d{   }
|
S |j                  d|       d{   }
|
S 7 A7 $7 
# t        $ r}|xs d	}t        |||| |
      d}~ww xY ww)z%
    Calls openai tts endpoints.
    r   r   Taspeechr  Nr  r  r  r  )r  r   r%  r   r   speechr)  r*  r+  r<   r,  r.  r'  r   r  s               r   r  r    sB    
 !!#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D*A4D ;C=<D C?D  D*!D 6D7D <D*=D ?D D 	D'D""D''D*voicer   projectr  speedinstructionsr  r  c                 f	   |j                  dd       }|j                  dd       }|j                  dd       }|j                  dd       }|j                  dd       }t        | ||      \  } }}}|j                  dg        i }|||d<   |||d	<   |||d
<   |
t        j                  }
|"t        j
                  xs t        j                  }t        d0i |}|j                  dd       }|j                  | |i ||||	d i d||       d }|dk(  s|t        j                  v r|t        |t              st        j                  d| |      |xs. t        j                  xs t        d      xs t        d      xs d}|xs/ t        j                   xs t        j"                  xs t        d      }|xs! t        j$                  xs t        d      xs d }|xs! t        j&                  xs t        d      xs d }|xs t        j(                  }t*        j-                  | |||||||||
||      }nS|dk(  r|t        |t              st        j                  d| |      |xs t        j                  xs t        d      }|xs t        j.                  xs t        d      }|xs< t        j                   xs* t        j0                  xs t        d      xs t        d      }|j                  di       j                  dd       xs t        d       }|j                  d!d       }|r||d<   t2        j-                  | |||||||||||
|||"      }n3|d#k(  s|d$k(  r t5        d0i |}|j                  xs d%}|j6                  xs t        j6                  xs t9        d&      } |j:                  xs t        j:                  xs t9        d'      }!|j<                  xs t9        d(      }"|+t        |t>              st        j                  d)| | |      d*| v r#d+d,l m!}# |#jE                  | |||||xs i ||-      S tF        j-                  ||"| |!|
|| |||||.      }n(|d*k(  r#d+d,l m!}# |#jE                  | |||||xs i ||-      S |)tI        d/jK                  |t        jL                              |S )1Nr   r  r  r   r  rS  r  r   r  r  r  r  r  r  z;'voice' is required to be passed as a string for OpenAI TTSr'  r  r  r  r  r  OPENAI_PROJECT)r   rc  r  r  r   r  r   r  r   r   r   r  rH  z:'voice' is required to be passed as a string for Azure TTSr  r  r  r  r  r  r  r  )r   rc  r  r  r   r  r   r  r  r   r   r   r   r  r  rD  r5  r  r9  r<  r?  zN'voice' is required to be passed as a dict for Vertex AI TTS, passed in voice=r6  rL   )#speech_to_completion_bridge_handler)r   rc  r  r  r  r  rh  r  )	_is_asyncr=  r7  r:  r   r  r   rc  r  r  r   rh  z@Unable to map the custom llm provider={} to a known provider={}.r   )'r   r<   r   r   r  r   r  r  r   r  r  r!  r   r?  r  rB   r   r  r   r  r  r  audio_speechr   r  r  r/   r7  r.   r:  r=  r-  4endpoints.speech.speech_to_completion_bridge.handlerr  r  vertex_text_to_speechr'  r  provider_list)$r   rc  r  r   r  r   r   r  r   r  r   r   r  r  r   r  r  r  r   r   r  r  r   r  r  r  rF  rh  r   r  r  generic_optional_paramsr8  r;  r=  r  s$                                       r   r  r  D  s   , ::fd#D%+ZZ0A4%HO!::&<dCJJ5ML$/J<L)<x=9E JJvrO"-<)*#( *6'))))GV-G-G,6v6**2D9K,,.$8$  $!
 
 0 -  6:Hx''"E"EE=E3!7))U0   +++,+ +,+ + 	  ,,!!, *+	 	  ##/0 	 	  *+ 	 	 ,W__*77+%# 8 
 
	'=E3!7))T0 
 Ow//O:>N3O![W%8%8[JGZ<[  ++  + 01+ /* 	 )8(;(;L"(M(Q(Qd)
 )

 	
 #)**-F"M/<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 
 u 7== /22'$7 > 	 	 )551,.+# 6 
 
	(	
 399+.Mr# 3 : 	
 		
 NUU#W%:%:
 	

 Or   model_paramsr  )	r   rt   r  r  audio_transcriptionimage_generationbatchrerankrealtimec           
      \   K   ddl m} t        dg dddt        j                  j	                         dd      }| d	<   |j                   
       	  j                  dd      t        d      t        j                  v r$|"t        j                     j                  d      }t              \  }}t        j                  v r$|"t        j                     j                  d      }ddi d<   |xs d}dv r|j                   |       d{   S  fd fd fd fd fd fd fd fd fdd	}||v r> ||           d{   }t        |di       j                  d i       xs i }	t        |	      S t        d!| d"      7 7 A# t        $ r~}
t        j                         }t!        |t"              r|dd# }|d$d%t#        |
       d&| icY d}
~
S t#        |
      d'z   |z   }|j$                  j                  d(      }||d)cY d}
~
S d}
~
ww xY ww)*a   
    Support health checks for different providers. Return remaining rate limit, etc.

    Returns:
        {
            "x-ratelimit-remaining-requests": int,
            "x-ratelimit-remaining-tokens": int,
            "x-ms-region": str,
        }
    r   )HealthCheckHelpersr  Fr   1234T)r   r   r   	call_typer  
start_timefunction_idlog_raw_request_responser  r  r   Nzmodel not setr  rr  zno-cachecacher   *)r   r  r  r  c                  .    t        j                  di  S Nr   )r   r   r  s   r   <lambda>zahealth_check.<locals>.<lambda>  s    G// r   c                  P    t        j                  di t               dxs diS )Nru  testr   )r   r  r$   r  ru  s   r   r  zahealth_check.<locals>.<lambda>  s*    '":": #&|4#'#r   c                  R    t        j                  di t              d xs dgiS )Nrc  r  r   )r   r  r$   )rc  r  s   r   r  zahealth_check.<locals>.<lambda>  s,    !3!3 "&|4"'x"r   c                  R    t        j                  di t               xs dddS )Nr  alloy)rc  r  r   )r   r  r$   r  s   r   r  zahealth_check.<locals>.<lambda>  s+    GOO %&|4%&%r   c                  X    t        j                  di t               dt               iS )Nr  r   )r   r  r$   r!   r  s   r   r  zahealth_check.<locals>.<lambda>  s(    7+A+A ,&|4,46,r   c                  H    t        j                  di t               diS )Nru  r   )r   aimage_generationr$   r  s   r   r  zahealth_check.<locals>.<lambda>  s%    (A(A )&|4))r   c                  T    t        j                  di t               xs ddgdS )Nr  zmy sample text)query	documentsr   )r   arerankr$   r  s   r   r  zahealth_check.<locals>.<lambda>  s-    goo &|4l+,r   c            
          t         j                  dd       j                  dd       j                  dd             S )Nr  r   r   )r   r  r  r   r   )r-   r   )r  r   r  s   r   r  zahealth_check.<locals>.<lambda>  sA     6$7%))*d;$((D9(,,]DA!r   c                  @    t        j                  di t               S r  )r   alist_batchesr$   r  s   r   r  zahealth_check.<locals>.<lambda>  s    W22 &|4r   )	r   rt   r  r  r  r  r  r  r  r}  r  zMode zI not supported. See modes here: https://docs.litellm.ai/docs/proxy/healthi  errorzerror:zz. Missing `mode`. Set the `mode` for the model - https://docs.litellm.ai/docs/proxy/health#embedding-models  
stacktrace: z
stack trace: raw_request_typed_dict)r  r  )/litellm.litellm_core_utils.health_check_helpersr  r   datetimenow;_update_model_params_with_health_check_tracking_informationr   r'  r   
model_costr<   ahealth_check_wildcard_modelsrK  r#   	traceback
format_excr!  r   r  )r  r  ru  rc  r  r  r2  mode_handlersr  _response_headersr7  stack_traceerror_to_returnr  r  r   s   ` ``          @@r   ahealth_checkr  9  s    8 S "$$((*!%	 +>L&'%aao{a|L`
+//>=O,,G&&&4<%%e,008D+;%+H("AqG&&&4<%%e,008D !
W ~v%<+II$7)$7	 J   
$!
K(
T = 1mD133I 	#3R8<<YKQr  11BCCvfg sd 4  
**,k3'%et,K<6#a&  *e  fq  er  s  a&#44{B!4!G!G!K!K$"

 %&<
 	
!
sy   AH,CF" FF" H,?F" F /F" H,F"  F" "	H)+=H$(H))H,.0H$H)H,$H))H,c                     	 t        j                  |        t        j                  rt	        |        y y # t
        $ r Y y w xY wr   )rM   r  r   set_verboseprintr'  )print_statements    r   r9  r9    s=    _-/"  s   04 	A A c                      t         j                  &t        t         j                        }t        di | |S t	        d      )Nz`No config path set, please set a config path using `litellm.config_path = 'path/to/config.json'`r   )r   config_pathrF   rt   r|  )r   config_argss     r   config_completionr    sA    &&w':':;2F2k22n
 	
r   chunksc           
         | d   d   }| d   d   }| d   d   }| d   d   }| d   j                  dd       }| d   d   d   d	   }| d   d   d   d
   }|||||d d||dgd d d dd}	g }
| D ]R  }|d   }|D ]F  }|t        |d      s|j                  d      %|j                  d      }|
j                  |       H T dj                  |
      }||	d   d   d<   t	        |      dkD  rn	 	 t        ||      |	d   d<   t        ||d      |	d   d<   |	d   d   |	d   d   z   |	d   d<   t        di |	S # t        $ r t        d       d|	d   d<   Y Tw xY w)Nr   r  rV  rz  r   system_fingerprintrv  finish_reasonr   )r@  rl  r   r  rn  )r  rV  rz  r   r  rv  rm  r@  r  r   rm  ro  z1token_counter failed, assuming prompt tokens is 0T)r   r@  count_response_tokensrp  rq  r   )	r   r  ry  r  r%  rI   r'  r9  r   )r  r   r  rV  rz  r   r  r  r   r   content_listchunkrv  choicer  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|, &6HY6"
q /-:(.
/* .;".HW)* 	/*Xg->?R-SS Wn% "-H-- 	/ 	IJ-./*	/s   ,D5 5EEc                 p   	 | t        j                  dddd      | sy t        | |      }|j                  } t	        |       dk(  ry t        | d   d   d   t         j                  j                        rt        | |      S | d   d   }|j                  |       }| D cg c]0  }t	        |d         dkD  rd	|d   d   d
   v r|d   d   d
   d	   |2 }}t	        |      dkD  rP|j                  |      }	t        t        |j                  d         }
d |
j                  _        |	|
j                  _        | D cg c]0  }t	        |d         dkD  rd|d   d   d
   v r|d   d   d
   d   |2 }}t	        |      dkD  rNt        t        |j                  d         }
d |
j                  _        |j#                  |      |
j                  _        | D cg c]0  }t	        |d         dkD  rd|d   d   d
   v r|d   d   d
   d   |2 }}t	        |      dkD  r|j'                  |      |d   d   d   d<   | D cg c]0  }t	        |d         dkD  rd|d   d   d
   v r|d   d   d
   d   |2 }}t	        |      dkD  r|j)                  |      |d   d   d   d<   | D cg c]0  }t	        |d         dkD  rd|d   d   d
   v r|d   d   d
   d   |2 }}t	        |      dkD  r|j+                  |      |d   d   d   d<   | D cg c]0  }t	        |d         dkD  rd|d   d   d
   v r|d   d   d
   d   |2 }}t	        |      dkD  r=t        t        |j                  d         }
|j-                  |      |
j                  _        t1        |      }|j3                  |      }|j5                  | ||||      }t7        |d|       |S c c}w c c}w c c}w c c}w c c}w c c}w # t8        $ rK}t;        j<                  dj?                  tA        |                   t        j                  dddd      d }~ww xY w)Nr?  z=Error building chunks for logging/streaming usage calculationr  )r>  rE  rA  r   r   rv  )r  r   r   r{  deltar   rj  rE  thinking_blocksreasoning_contentr   )r  r   completion_outputr   reasoning_tokensrm  zAlitellm.main.py::stream_chunk_builder() - Exception occurred - {})!r   rI  r[   r  r%  r!  rx  r   r   build_base_responseget_combined_tool_contentr   r   rv  rE  rj  r{  "get_combined_function_call_contentr   get_combined_contentget_combined_thinking_contentget_combined_reasoning_contentget_combined_audio_contentr   r'   count_reasoning_tokenscalculate_usager|  r'  rM   	exceptionr  r   )r  r   r  end_time	processorr   r   r  tool_call_chunkstool_calls_listr  function_call_chunkscontent_chunksr  reasoning_chunksaudio_chunksr  r  rm  r7  s                       r   stream_chunk_builderr  +  sO   G
>""W	  "684	!! v;!1Ii #W]]%>%>
 8  q	'"008  
5#$q(i 0 3G <<i #G,\:F	 
 
  1$'AABRSO7H$4$4Q$78G&*GOO#)8GOO&   
5#$q(5#3A#6w#??i #G,_=I	  
  
 #$q(7H$4$4Q$78G&*GOO#<<=QR OO)  
5#$q(U9-a099i #G,Y7C	 
 
 ~"..~> Y"9-i8  
5#$q(!U9%5a%8%AAi #G,->?K	 
 
 !#77H Y"9-.?@  
5#$q(#uY'7':7'CCi #G,-@AM	 
 
  1$889IJ Y"9-.AB  
5#$q(5+A.w77i #G,W5A	 
 
 |q 7H$4$4Q$78G$-$H$H$VGOO!;HE$;;HE))/- * 
 	'5)}
 




6  
  OVVA	

 S	
 	

sz   O! &O! 9O! O! 5OA$O! 75O,A"O! 5O1O! 45O)1O! 5O1O!  5O5BO! O! !	P5*AP00P5r   )FNrb  NFNNN)NNNNNNNNNNNNNNNNNNNNN)NN)NNN)NNNNNNr   NNNNN)NNNNNNNNNNNNNNNN)r   NN(S  r  r)  r  r  rv  r  randomsysr]  r  uuidrh  r   r_  r   r   r   r^  r   	functoolsr   typingr	   r
   r   r   r   r   r   r   r   r   r   r   r   dotenvrL  r  r`  pydanticr   typing_extensionsr   r   r   r   r   r   r   litellm.constantsr   r   litellm.exceptionsr   "litellm.integrations.custom_loggerr    ,litellm.litellm_core_utils.audio_utils.utilsr!   %litellm.litellm_core_utils.dd_tracingr"   -litellm.litellm_core_utils.health_check_utilsr#   r$   *litellm.litellm_core_utils.litellm_loggingr"  )litellm.litellm_core_utils.mock_functionsr%   r&   8litellm.litellm_core_utils.prompt_templates.common_utilsr'   litellm.llms.base_llmr(   r)   !litellm.llms.bedrock.common_utilsr*   &litellm.llms.custom_httpx.http_handlerr+   r,   litellm.realtime_api.mainr-   litellm.secret_managers.mainr.   litellm.types.routerr/   litellm.types.utilsr0   litellm.utilsr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   _loggingrM   caching.cachingrN   rO   rP   !litellm_core_utils.fallback_utilsrQ   rR   0litellm_core_utils.prompt_templates.common_utilsrS   rT   +litellm_core_utils.prompt_templates.factoryrU   rV   rW   rX   rY   rZ   0litellm_core_utils.streaming_chunk_builder_utilsr[   llmsr\   llms.anthropic.chatr]   llms.azure.audio_transcriptionsr^   llms.azure.azurer_   r`    llms.azure.chat.o_series_handlerra   llms.azure.completion.handlerrb   llms.azure_ai.embedrc   llms.bedrock.chatrd   re   llms.bedrock.embed.embeddingrf    llms.bedrock.image.image_handlerrg   llms.bytez.chat.transformationrh   !llms.codestral.completion.handlerri   llms.cohere.embedrj   cohere_embed!llms.custom_httpx.aiohttp_handlerrk   "llms.custom_httpx.llm_http_handlerrl   llms.custom_llmrm   rn   llms.databricks.embed.handlerro   llms.deprecated_providersrp   rq   llms.groq.chat.handlerrr   "llms.huggingface.embedding.handlerrs   llms.nlp_cloud.chat.handlerrt   r  llms.ollama.completionrd  llms.oobabooga.chatru   llms.openai.completion.handlerrv   $llms.openai.image_variations.handlerrw   llms.openai.openairx   "llms.openai.transcriptions.handlerry   llms.openai_like.chat.handlerrz   "llms.openai_like.embedding.handlerr{   llms.petals.completionr  llms.predibase.chat.handlerr|   llms.replicate.chat.handlerr  llms.sagemaker.chat.handlerr}   !llms.sagemaker.completion.handlerr~   llms.vertex_air   8llms.vertex_ai.gemini.vertex_and_google_ai_studio_geminir   <llms.vertex_ai.gemini_embeddings.batch_embed_content_handlerr   8llms.vertex_ai.image_generation.image_generation_handlerr   6llms.vertex_ai.multimodal_embeddings.embedding_handlerr   4llms.vertex_ai.text_to_speech.text_to_speech_handlerr   ,llms.vertex_ai.vertex_ai_partner_models.mainr   2llms.vertex_ai.vertex_embeddings.embedding_handlerr   'llms.vertex_ai.vertex_model_garden.mainr   llms.vllm.completionr  llms.watsonx.chat.handlerr   llms.watsonx.common_utilsr   types.llms.anthropicr   types.llms.openair   r   r   r   r   r   r   r   types.utilsr   r   r   r   r   r   r   r   r   get_encodingr  r   r   r   r   r   r   r   r   r  r  r  openai_image_variationsgroq_chat_completionsrC  r  r  r  r  r  r5  r  r  r  r6  bedrock_image_generationr  r=  r:  vertex_image_generationr8  r  r  r  r  r  r4  r  r2  r  r  sagemaker_chat_completionr  r   r   r   r   wrapr   r   r   r}  r-  r  r   r<  r'  rS  rW  rY  r  rV  r[  r  r  r  r	  r  r  r  r  r{  r}  r  r  r  r  r  r  r  r9  r  r   r  r   r   r   <module>rr     s        	  
     H H            &   6 ; X 8 T H > P < 7 5 3       < % F F  M  8 D N I > 1 = : D ; F 6 D B > E 8 6 D P 5 * @ N 4 H @ J = @ P = ; 0 O X O O N 9 9 6 8	 	 	
 
 
 !8  /	 	 	 	 	 /0 .0 68 68 *, %' 46 ,. 79 ,. 46 (* 46 46 #5#7  $& 13 " "$ 79 /1 /1 (=(? %&?&A #-/ ,. 24 35 13 *, 02 02 &( 7 7	O 	O $ $   $#'+/#'!!%)	 $+/9=AE04(,)-!%>B .2*.#"&CG"!%!!%$(15;?Qs
s
 s
 ~	s

 C=s
 eE3J'(s
 %s
 E?s
 }s
 TNs
 TNs
 s
 $C=s
 456s
  =>!s
" ,-#s
$ uo%s
&  's
( )s
* 3-+s
. eD$y/$9:;/s
0 3-1s
2 D>3s
4 %T	*+5s
6 "$7s
8 tn9s
: 3-;s
> w'>?@?s
B smCs
D #Es
F c]Gs
H Is
J D>Ks
N -.Os
P !!78Qs
T =--.Us
  s
l
( *.8
i-.8
8
 "#8
v
4.
eE3567
 

4.
eE3567
 
$eS%--&? @ $-E%emm2K,L - #1I&*#(:>TJTJTJ TNTJ }	TJ
 i-.TJ d^TJ 4.TJ eE3567TJn 498  :>#'!!%)	+/ $9=AE04(,)-!%CG>B .2#"&*.;?$( $#'"!%!!%15SB(
B(
 B(
 eE3567	B(

 %B(
 E?B(
 }B(
 TNB(
 TNB(
 $C=B(
 B(
 456B(
 =>B(
 ,-B(
  uo!B(
"  #B(
$ %B(
& 3-'B(
* w'>?@+B(
, eD$y/$9:;-B(
. 3-/B(
0 D>1B(
2 %T	*+3B(
4 tn5B(
6 3-7B(
8 "$9B(
: !!78;B(
> D>?B(
B ~CB(
D C=EB(
H smIB(
J #KB(
L c]MB(
N OB(
R -.SB(
V =--.WB(
  B(
JP7@=> :
): :
 :
@ 
  $%)"!%!"! 	
 c] sm # c] sm  3-$ %( sC**+) 
2 
  $%)"!%!"!$ "'% 	
 c] sm # c] sm  3-$ %( ) 
4   $%)"!%!"!j
 	j

 c]j
 smj
 #j
 c]j
 smj
 j
 3-j
$ iS2C(CDDE%j
 j
\ F

!#>>?F
 F
R 
   	 	 	 	 	 	 	 	 	!%) 	#'! 	"!%!!%)-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8   !)-	CCC=C c]C "#	C C CR /
-B /
 /
d 
 #  	JN!%!"!%!%%GG
G sm	G
 SMG <=G &d73D+E&FGG #G 3-G c]G smG  #!G" ##G(  )C6K,K"LLM)G GT %
&@ %
 %
P  )-!"!%"&!!%#59%)"&")-"%ooo E#t)$%o c]	o
 smo #o 3-o c]o #o tno eE5==012o c]o C=o 3-o  d^!o" "##o$ d^%o(  )o oD 	  !O
O


	
O
 SMO
  D>!O
h
 .2G.G.$TNG.G.V NRJ
J
$TNJ
eM#99:;J
r   