
    j?              	          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#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l.m/Z/ ddl0m1Z1  G d de      Z2 e       Z3 G d d      Z4	 dde	deeedf      de
e5ef   fdZ6y)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)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     x/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/litellm/caching/caching_handler.pyr$   r$   G   s7     $(M8C='CG#X.?%@G %d r/   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.cachingr7   r8   async_streaming_chunkssync_streaming_chunksr4   r3   r5   litellmcache
isinstancein_memory_cache_obj
dual_cache)selfr3   r4   r5   r7   r8   s         r0   __init__zLLMCachingHandler.__init__Y   sx     	:;=#:<",!2$==$GMM4G4G)T3<#MM// 34DO 	 #DOr/   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r3   zChecking Async Cache)rG   rH   rI   z
Cache Hit!custom_llm_providerapi_baseapi_keyrE   rO   rP   rQ     )rF   rE   rH   r%   is_asyncrO   cache_duration_msr%   rG   rH   rF   rE   rO   rI   streamrF   r%   r5   end_time	cache_hit_hidden_params	cache_keyr%   )r&   r%   rH   rF   r5   rE   )r&   r'   zCACHE RESULT: )r%   r&   )getr>   r?   copytimeperf_counterr     _is_call_type_supported_by_cacher   debug_retrieve_from_cacher@   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)rC   rE   r3   rF   r5   rG   rH   rI   r&   r'   r%   cache_check_start_timecache_check_end_timerM   rZ   rY   rO   _rU   r\   s                       r0   _async_get_cachez"LLMCachingHandler._async_get_cacheo   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 *>@V)VZ^(^%@@$/#%&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 
 o!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!   rN   r.   zChecking Sync CachedetailrO   rV   T rP   rQ   rR   /F)rF   rE   rH   r%   rT   resultr5   rY   rZ   r[   r\   r]   )litellm.utilsr"   r>   r?   rb   r_   updateconvert_args_to_kwargsr3   r   	get_cacher(   rj   r^   rf   rg   rh   ri   -handle_sync_success_callbacks_for_async_callsrl   r@   r   rm   r[   r$   )rC   rE   r3   rF   r5   rG   rH   rI   r"   r%   
new_kwargsrZ   rY   rO   dynamic_api_keyrP   r\   s                    r0   _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Br/   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)r@   strre   
ValueError)rC   rH   s     r0   handle_kwargs_input_list_or_strz1LLMCachingHandler.handle_kwargs_input_list_or_strR  sC     fWos+7O$$w.'?"?@@r/   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
        rE   N)r@   dictr^   )rC   r   rs   crs       r0   "_extract_model_from_cached_resultsz4LLMCachingHandler._extract_model_from_cached_results]  s5     #EAr"d#w'{" # r/   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   rE   )rE   dataTrZ   	embedding)r   indexobject)token_counter)textcount_response_tokensprompt_tokenscompletion_tokenstotal_tokensrO   rP   rQ   rR   )rF   rE   rH   r%   rT   is_embeddingrX   )r   	enumerateappendlenr   r^   r   r[   r   r   r@   r   r{   r   r   usagerf   rg   r>   rh   ri   rk   )rC   r&   r%   rH   rF   r5   rE   r'   remaining_listr   kwargs_input_as_listidxr   
model_namer   valembedding_datar   r   rZ   rY   rO   r   rP   s                           r0   rp   z:LLMCachingHandler._process_async_embedding_cached_responsen  sQ   : 27(#CCFK /GC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Pr/   usage1usage2c                     t        |j                  |j                  z   |j                  |j                  z   |j                  |j                  z         S )Nr   )r   r   r   r   )rC   r   r   s      r0   combine_usagezLLMCachingHandler.combine_usage  sK     ..1E1EE$669Q9QQ,,v/B/BB
 	
r/   _caching_handler_responseembedding_responserY   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      TrZ   rS   )r   r   )r&   r   r   r[   total_seconds_response_msr   r   )rC   r   r   r5   rY   r   final_data_listitems           r0   2_combine_cached_embedding_response_with_api_resultzDLLMCachingHandler._combine_cached_embedding_response_with_api_result  s7   ( %DDL%%-MMRRD| 2 7 7 C&&'9'>'>s'CDq&&t, S 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Hr/   rZ   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_WORKERry   )async_coroutineN))litellm.litellm_core_utils.logging_workerr   ensure_initialized_and_enqueueasync_success_handlerr   )rC   rF   r%   r5   rY   rZ   r   s          r0   rk   z3LLMCachingHandler._async_log_cache_hit_on_callbacks  sX    $ 	T<<'==$hZc >  	= 	
 	AA Z(V_ 	B 	
r/   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.   ).0rz   s     r0   	<genexpr>z9LLMCachingHandler._retrieve_from_cache.<locals>.<genexpr>g  s     BM&v~Ms   Tr   r.   )r>   r?   r_   r|   r}   r3   r   rn   ro   r@   r   re   r   r   rl   r   async_get_cacherB   asynciogatherall_supports_asyncr~   )
rC   rG   rH   rI   r   r%   tasksr   ipreset_cache_keys
             r0   rd   z&LLMCachingHandler._retrieve_from_cache4  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 	 9 #*..%"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"rO   c           	      B   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                  ||||      }n%t        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	      }nd|t        j&                  j                  k(  s|t        j(                  j                  k(  r*t        |t              rd|dd}	 ||t+               d|	      }t-        |d      r5|j.                  )t        |j.                  t              rd|j.                  d<   t1        ||||| j2                  t4        j4                  j7                                |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_objectrW   FT)r%   rG   rF   rE   )response_objectmodel_response_objectr   )r   r   response_typeNrerankz	whisper-1)rE   rO   rZ   audio_transcription)r   r   r   hidden_paramsr[   rZ   )rz   rF   rE   rH   r5   rY   r.   )r{   r   r   acompletionro   
completionr@   r   r^   _convert_cached_stream_responser   atext_completiontext_completionr   rn   r   r   arerankr   atranscriptiontranscriptionr   rm   r[   r   r5   rf   rg   )
rC   r%   rG   rH   rF   rE   rI   rO   r   r   s
             r0   rj   z:LLMCachingHandler._convert_cached_result_to_model_responseu  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 M#34,,8=77>8<M((5
 	! #&&**,	
 r/   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_streamrE   rO   rF   )r{   r"   r   r   r   r   ro   r   )	rC   r%   rG   rF   rE   r"   r   r   _stream_cached_results	            r0   r   z1LLMCachingHandler._convert_cached_stream_response  sp    	
 	
 ..444I66<<<$G -%! %B -%! #3 1#	
 	
r/   rz   c                   K   ddl m} t        j                  y|j	                         }|j                  t        ||              ||      }||d<   | j                  ||      r^t        |t        j                        s:t        |t        j                        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   NrM   r3   rH   r   )'litellm.litellm_core_utils.core_helpersr    r>   r?   r_   r|   r}   _should_store_result_in_cacher@   r   r   r   r   r   r   create_taskasync_add_cache_pipelinerB   async_add_cachemodel_dump_json)rC   rz   r3   rH   rI   r    r   rM   s           r0   async_set_cachez!LLMCachingHandler.async_set_cache  s|    *	
 == [[]
"!	
 =ZH)9
%&--/
 . 
 67#8#89fg&?&?@f&;<fn5 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}   r3   r>   r?   r   	add_cache)rC   rz   rH   rI   r   s        r0   sync_set_cachez LLMCachingHandler.sync_set_cacheU  sz     [[]
"&&	
 == --"44Z . 
 MM##F9j9r/   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^   )rC   r3   rH   s      r0   r   z/LLMCachingHandler._should_store_result_in_cachep  sy     ]]$& M22$>M&//0GMM4V4VVM GR(,,Z?tK		
r/   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(   )rC   r3   s     r0   rb   z2LLMCachingHandler._is_call_type_supported_by_cache  sB     MM%22>%../7==3U3UUr/   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rz   r5   rY   r4   streaming_chunksrT   N)rz   r3   rH   )r   r5   rf   rg   r4   r<   r   r3   rC   r   complete_streaming_responses      r0    _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)rz   rH   )r   r5   rf   rg   r4   r=   r   r   s      r0   %_sync_add_streaming_response_to_cachez7LLMCachingHandler._sync_add_streaming_response_to_cache  sn     >"&&**,..!77
 	$ '22**    3r/   rT   r   rU   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_fnNrP   rw   metadata
model_infoproxy_server_requeststream_response)r   r   rP   r   r   r   r   rO   r   usermessagesr   rQ   rW   F)
rE   r   optional_paramslitellm_paramsr   rQ   original_responseadditional_argsrW   rO   T)rZ   rU   r.   )r^   r>   r?   !_get_preset_cache_key_from_kwargsupdate_environment_variablesr   r   caching_details)
rC   rF   rE   rH   r%   rT   r   rO   rU   r   s
             r0   ri   z9LLMCachingHandler._update_litellm_logging_obj_environment  s,   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/'
#r/   r   )FNN),r(   r)   r*   r   r   r   r   rf   rD   LiteLLMLoggingObjr
   r   r$   rt   r   r	   r   intr   r   r   r-   rp   r   r   r   rk   rd   r   r   r   r   r   r"   rj   r   r   r   r   rb   r   r   floatri   r.   r/   r0   r2   r2   X   s   # S#X %%	< +/NN $N '	N
 %%N N S#XN uS#X'N 
(	)Np +/QCQC $QC '	QC
 %%QC QC S#XQC uS#X'QC 
 QCf	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
&
 
 %%	

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

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

 @
 @
 @
 &c]@
 $E?@
r/   r2   r3   rI   .rJ   c                     t        j                  |       }t        |j                  j	                               }i }|r,t        |      D ]  \  }}|t        |      k  s||   }|||<     |S r   )inspect	signaturere   
parameterskeysr   r   )r3   rI   r  param_namesargs_to_kwargsr   arg
param_names           r0   r}   r}     su    
 !!"34I y++0023K N#D/JE3s;''(/
-0z* *
 r/   r   )7r+   r   rf   r  r`   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.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$   rA   r2   r   r}   r.   r/   r0   <module>r     s             : ) + 2 /	 	 	 W MY  $o p
 p
j '+
5c?
# 
#s(^r/   