
    AHj              	          d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlZddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
l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, erddl-m.Z/ neZ/ddl0m1Z1 ddl2m3Z3  G d de      Z4 e       Z5 G d d      Z6	 dde	deeedf      de
e7ef   fdZ8y)a  
This contains LLMCachingHandler

This exposes two methods:
    - async_get_cache
    - async_set_cache

This file is a wrapper around caching.py

This class is used to handle caching logic specific for LLM API requests (completion / embedding / text_completion / transcription etc)

It utilizes the (RedisCache, s3Cache, RedisSemanticCache, QdrantSemanticCache, InMemoryCache, DiskCache) based on what the user has setup

In each method it will call the appropriate method from caching.py
    N)
TYPE_CHECKINGAnyAsyncGeneratorCallableDict	GeneratorListOptionalTupleUnion)	BaseModel)print_verboseverbose_logger)InMemoryCache)S3Cache)update_response_metadata)1_assemble_complete_response_from_streaming_chunks)CachedEmbedding)ResponsesAPIResponse)RerankResponse)CachingDetails	CallTypes	EmbeddingEmbeddingResponseModelResponseTextCompletionResponseTranscriptionResponseUsage)Logging!_get_parent_otel_span_from_kwargsCustomStreamWrapperc                   H    e Zd ZU dZdZee   ed<   dZee	   ed<   dZ
eed<   y)CachingHandlerResponsea  
    This is the response object for the caching handler. We need to separate embedding cached responses and (completion / text_completion / transcription) cached responses

    For embeddings there can be a cache hit for some of the inputs in the list and a cache miss for others
    Ncached_resultfinal_embedding_cached_responseF embedding_all_elements_cache_hit)__name__
__module____qualname____doc__r&   r
   r   __annotations__r'   r   r(   bool     W/root/tools/cai/cai_env/lib/python3.12/site-packages/litellm/caching/caching_handler.pyr%   r%   H   s3     $(M8C='CG#X.?%@G-2$d2r0   r%   c                      e Zd Zdedeeef   dej                  fdZ	 d.dedede	dej                  ded	eeef   d
e
eedf      de
e   fdZ	 d.dedede	dej                  ded	eeef   d
e
eedf      defdZd	eeef   dee   fdZdeeeef      de
e   fdZde
e   dee
e      d	eeef   de	dej                  dedee
e   ef   fdZdededefdZdededej                  dej                  def
dZde	dedej                  dej                  def
dZded	eeef   d
eedf   de
e   fdZ	 d.deded	eeef   de	ded
eedf   de
e   de
eeeeee e!f      fd Z"dedede	dede!f
d!Z#	 d.d"eded	eeef   d
e
eedf      fd#Z$	 d.d"ed	eeef   d
e
eedf      fd$Z%ded	eeef   defd%Z&dedefd&Z'd'efd(Z(d'efd)Z)	 	 	 d/de	ded	eeef   ded*ed+ede
e   d,e
e*   fd-Z+y)0LLMCachingHandleroriginal_functionrequest_kwargs
start_timec                 (   ddl m}m} g | _        g | _        || _        || _        || _        t        j                  Pt        t        j                  j                  |      r, |t        j                  j                  t              | _        y d | _        y )Nr   )	DualCache
RedisCache)redis_cachein_memory_cache)litellm.cachingr8   r9   async_streaming_chunkssync_streaming_chunksr5   r4   r6   litellmcache
isinstancein_memory_cache_obj
dual_cache)selfr4   r5   r6   r8   r9   s         r1   __init__zLLMCachingHandler.__init__X   sx     	:;=#:<",!2$==$GMM4G4G)T3<#MM// 34DO 	 #DOr0   Nmodellogging_obj	call_typekwargsargs.returnc                 |  K   |j                  dd      t        j                  |j                  dd      du r|j                  di       j                  dd      dur|xs d}d}d}	d}
|j                         }t	        j
                         }d}t        |      }||d<   t        j                  a| j                  |	      rNt        j                  d
       | j                  |||       d{   }
t	        j
                         }|
xt        |
t              sgt        j                  d       d}t        j                  j                         }t        j                  ||j                  dd      |j                  dd      |j                  dd            \  }}}}||z
  dz  }| j!                  ||||
d||       |j"                  }| j%                  |
|||||j                  dd      |      }
|j                  dd      du r| j'                  ||
|||       t        j                  j(                  di |}t        |
t*              st        |
t,              rt/        |
d      r||
j0                  d<   t3        |
      S |t4        j6                  j8                  k(  rq|
ot        |
t              r_t        j                  Ot        t        j                  j                  t:              s'| j=                  ||
||||      \  }}	t3        ||	      S t        j                  d|
        t3        |
|      S y7 Hw)aC  
        Internal method to get from the cache.
        Handles different call types (embeddings, chat/completions, text_completion, transcription)
        and accordingly returns the cached response

        Args:
            model: str:
            original_function: Callable:
            logging_obj: LiteLLMLoggingObj:
            start_time: datetime.datetime:
            call_type: str:
            kwargs: Dict[str, Any]:
            args: Optional[Tuple[Any, ...]] = None:


        Returns:
            CachingHandlerResponse:
        Raises:
            None
        cachingNFTr@   zno-cacher/   parent_otel_spanr4   zChecking Async Cache)rH   rI   rJ   z
Cache Hit!custom_llm_providerapi_baseapi_keyrF   rP   rQ   rR     )rG   rF   rI   r&   is_asyncrP   cache_duration_msr&   rH   rI   rG   rF   rP   rJ   streamrG   r&   r6   end_time	cache_hit_hidden_params	cache_keyr&   )r'   r&   rI   rG   r6   rF   )r'   r(   zCACHE RESULT: )r&   r'   )getr?   r@   copytimeperf_counterr!    _is_call_type_supported_by_cacher   debug_retrieve_from_cacherA   listdatetimenowget_llm_provider'_update_litellm_logging_obj_environmentr)   (_convert_cached_result_to_model_response!_async_log_cache_hit_on_callbacksget_cache_keyr   r#   hasattrr\   r%   r   
aembeddingvaluer   (_process_async_embedding_cached_response)rD   rF   r4   rG   r6   rH   rI   rJ   r'   r(   r&   cache_check_start_timecache_check_end_timerN   r[   rZ   rP   _rV   r]   s                       r1   _async_get_cachez"LLMCachingHandler._async_get_cachen   s^    @ ZZ	4(0W]]5Nzz)U+t3JJw#''
E:$F:2DKO+5:,+/M[[]F &*%6%6%8"48 @H)9F%&}}(T-R-R"3 .S . $$%;<&*&?&?'! '@ ' !
 (,'8'8':$ ,Zt5T"((6 $I'00446H7>7O7O#,2JJ7Ld,S!'J!= &

9d ;	84E.1 -/EE)% @@$/#%&3!%,?*; A  !2 : :I$($Q$Q&3"+%$/#,2JJ7Ld,S! %R %M zz(E2e;>>(3*7'1%-&/ ?  !( ; ; Ef EI"=)<%m5HI!-1ABDM44[A1NN!5!5!;!;;%1"=$71&++W EE8W&3%$/#-# F 78 28W9Y 
   >-!AB)+0O 
 q!s   C/L<1L92IL<c                    ddl m} d }	t        j                  | j	                  |      r|xs d}|j                         }
|
j                  t        | j                  |             t        d       t        j                  j                  di |
}	|	>d|	v rn8|j                  }| j                  |	|||||j                  dd       |      }	d	}t        j                  j                         }t        j                   |xs d
|j                  dd       |j                  dd       |j                  dd             \  }}}}| j#                  || d| ||	d       |j%                  |	|||       t        j                  j&                  di |}t)        |	t*              st)        |	|      rt-        |	d      r||	j.                  d<   t1        |	      S t1        |	      S )Nr   r"   rO   r/   zChecking Sync CachedetailrP   rW   T rQ   rR   rS   /F)rG   rF   rI   r&   rU   resultr6   rZ   r[   r\   r]   r^   )litellm.utilsr#   r?   r@   rc   r`   updateconvert_args_to_kwargsr4   r   	get_cacher)   rk   r_   rg   rh   ri   rj   -handle_sync_success_callbacks_for_async_callsrm   rA   r   rn   r\   r%   )rD   rF   r4   rG   r6   rH   rI   rJ   r#   r&   
new_kwargsr[   rZ   rP   dynamic_api_keyrQ   r]   s                    r1   _sync_get_cachez!LLMCachingHandler._sync_get_cache   s    	6'+ ==$)N)N/ *O *
 :2DJ&** /0#MM33AjAM(}, 1 : :I$($Q$Q&3"+%$/#,2JJ7Ld,S! %R %M !%I'00446H  00#kr,2JJ7Ld,S!'J!= &

9d ;	+'  @@$/!4 5Qug>%&3!& A   MM,#-!)"+	 N  !( ; ; Ef EI"=)<%m5HI!-1ABDM44[A1NN%MBBr0   c                 z    t        |d   t              r|d   gS t        |d   t              r|d   S t        d      )zO
        Handles the input of kwargs['input'] being a list or a string
        input input must be a string or a list)rA   strrf   
ValueError)rD   rI   s     r1   handle_kwargs_input_list_or_strz1LLMCachingHandler.handle_kwargs_input_list_or_strQ  sC     fWos+7O$$w.'?"?@@r0   non_null_listc                 j    |D ].  \  }}t        |t              s|j                  d      s)|d   c S  y)a	  
        Helper method to extract the model name from cached results.

        Args:
            non_null_list: List of (idx, cr) tuples where cr is the cached result dict

        Returns:
            Optional[str]: The model name if found, None otherwise
        rF   N)rA   dictr_   )rD   r   rt   crs       r1   "_extract_model_from_cached_resultsz4LLMCachingHandler._extract_model_from_cached_results\  s:     # 	#EAr"d#w'{"	# r0   r'   r&   c           	         d}g }g }	| j                  |      }
t        |      D ]/  \  }}||j                  |
|          |	j                  ||f       1 ||d<   t        |	      dkD  r| j	                  |	      }|s|j                  d      }t        |dgt        |
      z        }d|j                  d<   d}|	D ]b  }|\  }}||j                  d	      }|t        ||d	
      |j                  |<   t        |
|   t              sMddlm} | ||
|   d      z  }d t        |d|      }||_        t        |      dk(  rd}d}t         j                   j#                         }t%        j&                  ||j                  dd      |j                  dd      |j                  dd            \  }}}}| j)                  ||||dd       | j+                  |||||       ||fS ||fS )a  
        Returns the final embedding cached response and a boolean indicating if all elements in the list have a cache hit

        For embedding responses, there can be a cache hit for some of the inputs in the list and a cache miss for others
        This function processes the cached embedding responses and returns the final embedding cached response and a boolean indicating if all elements in the list have a cache hit

        Args:
            final_embedding_cached_response: Optional[EmbeddingResponse]:
            cached_result: List[Optional[Dict[str, Any]]]:
            kwargs: Dict[str, Any]:
            logging_obj: LiteLLMLoggingObj:
            start_time: datetime.datetime:
            model: str:

        Returns:
            Tuple[Optional[EmbeddingResponse], bool]:
            Returns the final embedding cached response and a boolean indicating if all elements in the list have a cache hit


        FNr   r   rF   )rF   dataTr[   	embedding)r   indexobject)token_counter)textcount_response_tokensprompt_tokenscompletion_tokenstotal_tokensrP   rQ   rR   rS   )rG   rF   rI   r&   rU   is_embeddingrY   )r   	enumerateappendlenr   r_   r   r\   r   r   rA   r   r|   r   r   usagerg   rh   r?   ri   rj   rl   )rD   r'   r&   rI   rG   r6   rF   r(   remaining_listr   kwargs_input_as_listidxr   
model_namer   valembedding_datar   r   r[   rZ   rP   r   rQ   s                           r1   rq   z:LLMCachingHandler._process_async_embedding_cached_responsem  s[   : 27(#CCFK / 	0GCz%%&:3&?@$$c2Y/		0
 )w}!@@OJ#ZZ0
.? Vc"677/+ KO+::;GM$ R>%'VVK%8N%1DM&4"%#.E7<<SA
 ""6s";SA?%!5c!:RV* " +"#*E
 5:+1~!#I/3,((,,.H (($*JJ/Dd$KJ5

9d3	# 88'=! 9  22'=%!# 3  34TTT.0PPPr0   usage1usage2c                     t        |j                  |j                  z   |j                  |j                  z   |j                  |j                  z         S )Nr   )r   r   r   r   )rD   r   r   s      r1   combine_usagezLLMCachingHandler.combine_usage  sK     ..1E1EE$669Q9QQ,,v/B/BB
 	
r0   _caching_handler_responseembedding_responserZ   c                 \   |j                   |S d}g }|j                   j                  D ]E  }|0|j                  $|j                  |j                  |          |dz  }5|j                  |       G ||j                   _        d|j                   j                  d<   ||z
  j	                         dz  |j                   _        |j                   j                  L|j                  @| j                  |j                   j                  |j                        |j                   _        |j                   S )a  
        Combines the cached embedding response with the API EmbeddingResponse

        For caching there can be a cache hit for some of the inputs in the list and a cache miss for others
        This function combines the cached embedding response with the API EmbeddingResponse

        Args:
            caching_handler_response: CachingHandlerResponse:
            embedding_response: EmbeddingResponse:

        Returns:
            EmbeddingResponse:
        r      Tr[   rT   )r   r   )r'   r   r   r\   total_seconds_response_msr   r   )rD   r   r   r6   rZ   r   final_data_listitems           r1   2_combine_cached_embedding_response_with_api_resultzDLLMCachingHandler._combine_cached_embedding_response_with_api_result  s;   ( %DDL%%-MMRR 	-D| 2 7 7 C&&'9'>'>s'CDq&&t,	- JY!AAF  	"AAPP	
 z!
-/DR!!AAN &EEKKW"((4NRN`N`0PPVV)// Oa O%EEK
 )HHHr0   r[   c                     ddl m} |j                  |j                  ||||             |j	                  ||||       y)a  
        Helper function to log the success of a cached result on callbacks

        Args:
            logging_obj (LiteLLMLoggingObj): The logging object.
            cached_result: The cached result.
            start_time (datetime): The start time of the operation.
            end_time (datetime): The end time of the operation.
            cache_hit (bool): Whether it was a cache hit.
        r   )GLOBAL_LOGGING_WORKERrz   )async_coroutineN))litellm.litellm_core_utils.logging_workerr   ensure_initialized_and_enqueueasync_success_handlerr   )rD   rG   r&   r6   rZ   r[   r   s          r1   rl   z3LLMCachingHandler._async_log_cache_hit_on_callbacks  s\    $ 	T<<'==$%!#	 >  	= 	
 	AA !	 	B 	
r0   c                   K   t         j                  y|j                         }|j                  t	        | j
                  |             d}|t        j                  j                  k(  rt        |d   t              r
|d   g|d<   nt        |d   t              st        d      g }t        |d         D ]d  \  }}t        j                  j                  di i |d|i}	|j                  t         j                  j!                  |	| j"                               f t%        j&                  |  d{   }|$t        |t              rt)        d |D              rd}|S t         j                  j+                         du r5t        j                  j                   dd| j"                  i| d{   }|S t        j                  j,                  dd| j"                  i|}|S 7 7 5w)	a  
        Internal method to
        - get cache key
        - check what type of cache is used - Redis, RedisSemantic, Qdrant, S3
        - async get cache value
        - return the cached value

        Args:
            call_type: str:
            kwargs: Dict[str, Any]:
            args: Optional[Tuple[Any, ...]] = None:

        Returns:
            Optional[Any]:
        Raises:
            None
        Nr   r   )r]   dynamic_cache_objectc              3   $   K   | ]  }|d u  
 y wNr/   ).0r{   s     r1   	<genexpr>z9LLMCachingHandler._retrieve_from_cache.<locals>.<genexpr>l  s     B&v~Bs   Tr   r/   )r?   r@   r`   r}   r~   r4   r   ro   rp   rA   r   rf   r   r   rm   r   async_get_cacherC   asynciogatherall_supports_asyncr   )
rD   rH   rI   rJ   r   r&   tasksr   ipreset_cache_keys
             r1   re   z&LLMCachingHandler._retrieve_from_cache9  s    ( == [[]
"&&	
 (,	,,222*W-s3'1'':&;
7#
7 3T: !CDDE#Jw$78 	Q#*==#>#> $00Wa0$  MM11"2-1__ 2 		 #*..%"88M(Zt-LBMBB$(M  }},,.$6&-mm&C&C ')-'<F' !  !( 7 7 !)-!<F! ! 9!s%   D-G"/G0A:G"*G +4G" G"rP   c           	         ddl m} |t        j                  j                  k(  s|t        j
                  j                  k(  rLt        |t              r<|j                  dd      du r| j                  ||||      }n ||t                     }|t        j                  j                  k(  s|t        j                  j                  k(  rHt        |t              r8|j                  dd      du r| j                  ||||      }nKt        di |}n>|t        j                  j                  k(  s|t        j                  j                  k(  r$t        |t              r ||t!               d	      }n|t        j"                  j                  k(  s|t        j$                  j                  k(  rt        |t              r ||d
d	      }n|t        j&                  j                  k(  s|t        j(                  j                  k(  r+t        |t              rd|dd}	 ||t+               d|	      }n%|dk(  s|dk(  rt        |t              rt-        di |}t/        |d      r5|j0                  )t        |j0                  t              rd|j0                  d<   t3        ||||| j4                  t6        j6                  j9                                |S )aH  
        Internal method to process the cached result

        Checks the call type and converts the cached result to the appropriate model response object
        example if call type is text_completion -> returns TextCompletionResponse object

        Args:
            cached_result: Any:
            call_type: str:
            kwargs: Dict[str, Any]:
            logging_obj: LiteLLMLoggingObj:
            model: str:
            custom_llm_provider: Optional[str] = None:
            args: Optional[Tuple[Any, ...]] = None:

        Returns:
            Optional[Any]:
        r   ) convert_to_model_response_objectrX   FT)r&   rH   rG   rF   )response_objectmodel_response_objectr   )r   r   response_typeNrerankz	whisper-1)rF   rP   r[   audio_transcription)r   r   r   hidden_params
aresponses	responsesr\   r[   )r{   rG   rF   rI   r6   rZ   r/   )r|   r   r   acompletionrp   
completionrA   r   r_   _convert_cached_stream_responser   atext_completiontext_completionr   ro   r   r   arerankr   atranscriptiontranscriptionr   r   rn   r\   r   r6   rg   rh   )
rD   r&   rH   rI   rG   rF   rJ   rP   r   r   s
             r1   rk   z:LLMCachingHandler._convert_cached_result_to_model_responsez  s   J 	C ..444I00666-zz(E*d2 $ D D"/' +	 !E ! !A$1*7/!
 33999I55;;;-zz(E*d2 $ D D"/' +	 !E ! !7 G G--333I//555-< -&7&9)M **000IAQAQAWAW4W-< -&*&M 11777I33999-$':!M
 = -&;&=3+	M <'9+C4J
 1A=AM M#34,,8=77>8<M((5
 	! #&&**,	
 r0   c                     ddl m}m}m} |t        j
                  j                  k(  s|t        j                  j                  k(  r
 ||      }n	 ||      } |||d|      S )Nr   )r#   convert_to_streaming_response#convert_to_streaming_response_async)r   cached_response)completion_streamrF   rP   rG   )r|   r#   r   r   r   r   rp   r   )	rD   r&   rH   rG   rF   r#   r   r   _stream_cached_results	            r1   r   z1LLMCachingHandler._convert_cached_stream_response  sp    	
 	
 ..444I66<<<$G -%! %B -%! #3 1#	
 	
r0   r{   c                   K   ddl m} t        j                  y|j	                         }|j                  t        ||              ||      }||d<   | j                  ||      rnt        |t        j                        sJt        |t        j                        s0t        |t              s t        |t              st        |t              rt        |t              rxt        j                  ht        t        j                  j                  t              s@t        j                   t        j                  j"                  |fd| j$                  i|       yt        j                   t        j                  j&                  |j)                         fd| j$                  i|       yt        j                   t        j                  j&                  |fi |       yyw)ah  
        Internal method to check the type of the result & cache used and adds the result to the cache accordingly

        Args:
            result: Any:
            original_function: Callable:
            kwargs: Dict[str, Any]:
            args: Optional[Tuple[Any, ...]] = None:

        Returns:
            None
        Raises:
            None
        r   r    NrN   r4   rI   r   )'litellm.litellm_core_utils.core_helpersr!   r?   r@   r`   r}   r~   _should_store_result_in_cacherA   r   r   r   r   r   r   r   create_taskasync_add_cache_pipelinerC   async_add_cachemodel_dump_json)rD   r{   r4   rI   rJ   r!   r   rN   s           r1   async_set_cachez!LLMCachingHandler.async_set_cache  s    *	
 == [[]
"!	
 =ZH)9
%&--/
 . 
 67#8#89fg&?&?@f&;<fn5f&:; v'891&++W ''>>"9=LV ''55"22415 ) ##GMM$A$A&$WJ$WX?
s   GGc                 
   |j                         }|j                  t        | j                  |             t        j
                  y| j                  | j                  |      r t	        j
                  j                  |fi | y)zE
        Sync internal method to add the result to the cache
        Nr   )r`   r}   r~   r4   r?   r@   r   	add_cache)rD   r{   rI   rJ   r   s        r1   sync_set_cachez LLMCachingHandler.sync_set_cache`  sz     [[]
"&&	
 == --"44Z . 
 MM##F9j9r0   c                    t         j                  duxrs t         j                  j                  duxrU t        |j                        t         j                  j                  v xr$ |j                  di       j                  dd      duS )z
        Helper function to determine if the result should be stored in the cache.

        Returns:
            bool: True if the result should be stored in the cache, False otherwise.
        Nr@   zno-storeFT)r?   r@   supported_call_typesr   r)   r_   )rD   r4   rI   s      r1   r   z/LLMCachingHandler._should_store_result_in_cache{  sy     ]]$& M22$>M&//0GMM4V4VVM GR(,,Z?tK		
r0   c                     t         j                  Jt         j                  j                  0t        |j                        t         j                  j                  v ryy)aO  
        Helper function to determine if the call type is supported by the cache.

        call types are acompletion, aembedding, atext_completion, atranscription, arerank

        Defined on `litellm.types.utils.CallTypes`

        Returns:
            bool: True if the call type is supported by the cache, False otherwise.
        TF)r?   r@   r   r   r)   )rD   r4   s     r1   rc   z2LLMCachingHandler._is_call_type_supported_by_cache  sB     MM%22>%../7==3U3UUr0   processed_chunkc                   K   t        || j                  t        j                  j                         | j                  | j
                  d      }|1| j                  || j                  | j                         d{    yy7 w)z
        Internal method to add the streaming response to the cache


        - If 'streaming_chunk' has a 'finish_reason' then assemble a litellm.ModelResponse object
        - Else append the chunk to self.async_streaming_chunks

        Tr{   r6   rZ   r5   streaming_chunksrU   N)r{   r4   rI   )r   r6   rg   rh   r5   r=   r   r4   rD   r   complete_streaming_responses      r1    _add_streaming_response_to_cachez2LLMCachingHandler._add_streaming_response_to_cache  s      >"&&**,..!88
 	$ '2&&2"&"8"8** '    3s   A9B;B<Bc                     t        || j                  t        j                  j                         | j                  | j
                  d      }|| j                  || j                         yy)zQ
        Sync internal method to add the streaming response to the cache
        Fr   N)r{   rI   )r   r6   rg   rh   r5   r>   r   r   s      r1   %_sync_add_streaming_response_to_cachez7LLMCachingHandler._sync_add_streaming_response_to_cache  sn     >"&&**,..!77
 	$ '22**    3r0   rU   r   rV   c	                 ^   |j                  dd      ||j                  dd      |j                  di       |j                  di       |j                  dd      |j                  di       |d	}	t        j                  #t        j                  j                  di ||	d
<   nd|	d
<   |j	                  ||j                  dd      i |	|s|j                  dd      n|j                  dd      |j                  dd      t        |      d|j                  dd      |
       t        d|      |_        y)a  
        Helper function to update the LiteLLMLoggingObj environment variables.

        Args:
            logging_obj (LiteLLMLoggingObj): The logging object to update.
            model (str): The model being used.
            kwargs (Dict[str, Any]): The keyword arguments from the original function call.
            cached_result (Any): The cached result to log.
            is_async (bool): Whether the call is asynchronous or not.
            is_embedding (bool): Whether the call is for embeddings or not.
            custom_llm_provider (Optional[str]): The custom llm provider being used.

        Returns:
            None
        	logger_fnNrQ   rx   metadata
model_infoproxy_server_requeststream_response)r   r   rQ   r   r   r   r   rP   r   usermessagesr   rR   rX   F)
rF   r   optional_paramslitellm_paramsr   rR   original_responseadditional_argsrX   rP   T)r[   rV   r/   )r_   r?   r@   !_get_preset_cache_key_from_kwargsupdate_environment_variablesr   r   caching_details)
rD   rG   rF   rI   r&   rU   r   rP   rV   r   s
             r1   rj   z9LLMCachingHandler._update_litellm_logging_obj_environment  s0   6  K6#

:r2

:r2 **\26$*JJ/Et$L%zz*;R@#6	
 ==$ ??I&I " 26N-.00FD)) $ 

:r*ZZ,JJy$/!-0 ::h. 3 	1 	
" '5/'
#r0   r   )FNN),r)   r*   r+   r   r   r   r   rg   rE   LiteLLMLoggingObjr
   r   r%   ru   r   r	   r   intr   r   r   r.   rq   r   r   r   rl   re   r   r   r   r   r   r#   rk   r   r   r   r   rc   r   r   floatrj   r/   r0   r1   r3   r3   W   s   # S#X %%	< +/OO $O '	O
 %%O O S#XO uS#X'O 
(	)Or +/PCPC $PC '	PC
 %%PC PC S#XPC uS#X'PC 
 PCd	Ad38n 	Ac 	A!%_(<"=>	#"kQ)12C)DkQ H_56kQ S#X	kQ
 'kQ %%kQ kQ 
x)*D0	1kQZ
E 
5 
U 
2I#92I .2I %%	2I
 ##2I 
2Ih"
&"
 "
 %%	"

 ##"
 "
H??&*38n?<A#s(O?	#?R .2}} } S#X	}
 '} } CHo} &c]} 
"!!	
	
}~

 
 '	

 
 

J +/EYEY $EY S#X	EY
 uS#X'EYV +/	 S#X uS#X'	6
!)
37S>
	
 # 
,m 8] : #-1-1@
&@
 @
 S#X	@

 @
 @
 @
 &c]@
 $E?@
r0   r3   r4   rJ   .rK   c                     t        j                  |       }t        |j                  j	                               }i }|r,t        |      D ]  \  }}|t        |      k  s||   }|||<     |S r   )inspect	signaturerf   
parameterskeysr   r   )r4   rJ   r  param_namesargs_to_kwargsr   arg
param_names           r1   r~   r~     sz    
 !!"34I y++0023K N#D/ 	1JE3s;''(/
-0z*	1
 r0   r   )9r,   r   rg   r
  ra   typingr   r   r   r   r   r   r	   r
   r   r   pydanticr   r?   litellm._loggingr   r   r<   r   litellm.caching.cachingr   ?litellm.litellm_core_utils.llm_response_utils.response_metadatar   (litellm.litellm_core_utils.logging_utilsr   litellm.types.cachingr   litellm.types.llms.openair   litellm.types.rerankr   litellm.types.utilsr   r   r   r   r   r   r   r   *litellm.litellm_core_utils.litellm_loggingr   r  r   r!   ,litellm.litellm_core_utils.streaming_handlerr#   r%   rB   r3   r   r~   r/   r0   r1   <module>r     s             : ) + 2 : /	 	 	 W M	3Y 	3 $o |
 |
B '+
5c?
# 
#s(^r0   