
    Mi                     6   S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJrJ	r	J
r
JrJrJr  S SKJr  S SKrS SKJr  S SKJr  S SKJr  S SK7  S S	KJrJr  S
SKJr  S
SKJr  S
SKJ r   S
SK!J"r"  S
SK#J$r$  S
SK%J&r&  S
SK'J(r(  S
SK)J*r*  S
SK+J,r,  S
SK-J.r.  S
SK/J0r0  S r1 " S S\2\5      r3 " S S5      r4\5Rl                  SSS/ SQ4S\\5   S\\2   S\\2   S\\2   S \\
\7      4
S! jjr8\5Rl                  SSS/ SQ4S\\5   S\\2   S\\2   S\\2   S \\
\7      4
S" jjr9S# r:g)$    N)Enum)AnyDictListOptionalTupleUnion)	BaseModel)verbose_logger)CACHED_STREAMING_CHUNK_DELAY)ModelParamHelper)*)EmbeddingResponseall_litellm_params   )AzureBlobCache)	BaseCache)	DiskCache)	DualCache)GCSCache)InMemoryCache)QdrantSemanticCache)
RedisCache)RedisClusterCache)RedisSemanticCache)S3Cachec                      [         R                  " U 5        [        R                  (       a  [	        U 5        g g ! [
         a     g f = fN)r   debuglitellmset_verboseprint	Exception)print_statements    q/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/litellm/caching/caching.pyprint_verboser&   (   s=    _-/"  s   6: 
AAc                       \ rS rSrSrSrSrg)	CacheMode1   
default_ondefault_off N)__name__
__module____qualname____firstlineno__r*   r+   __static_attributes__r,       r%   r(   r(   1   s    JKr2   r(   c            P          \ rS rSr\R
                  \R                  SSSSSSSS/ SQSSSSSSSSSSSSSSSSSSSSSSSSSSSS4'S\\   S\\   S\\	   S	\\	   S
\\	   S\\	   S\\
   S\\
   S\\
   S\\
   S\\\      S\\	   S\\	   S\\	   S\\	   S\\	   S\\   S\\\\	4      S\\	   S\\	   S\\	   S\\	   S\\   S\\	   S\\	   S\\	   S \\	   S!\	S"\\	   S#\\   S$\\   S%\\	   S&\\	   S'\\	   S(\\	   S)\\	   S*\	S+\\	   S,\\	   4NS- jjrS.\	4S/ jrS0\	S1\S.\\	   4S2 jrS1\S.\	4S3 jrS4\S5\\	   S.\\	   4S6 jrS1\S.\	4S7 jrS.\\	   4S8 jrS9\	S.S4S: jr\S;\	S.\	4S< j5       rS=\	S.\	4S> jrS? rS@\\   SA\\
   4SB jrSXSC\\   4SD jjr  SXSC\\   4SE jjr!SF r"SG r# SXSC\\   4SH jjr$SI\SJ\\	   S.\%4SK jr& SYSL\'SM\	S1\SN\S.\(\	\\4   4
SO jjr) SXSC\\   4SP jjr*SQ r+SR r,SS r-ST r.SU r/S.\4SV jr0SWr1g)ZCache7   N

completionacompletion	embedding
aembeddingatranscriptiontranscriptionatext_completiontext_completionarerankrerankTztext-embedding-ada-002typemodehostportpassword	namespacettldefault_in_memory_ttldefault_in_redis_ttlsimilarity_thresholdsupported_call_typesazure_account_urlazure_blob_containers3_bucket_names3_region_names3_api_version
s3_use_ssl	s3_verifys3_endpoint_urls3_aws_access_key_ids3_aws_secret_access_keys3_aws_session_token	s3_configs3_pathgcs_bucket_namegcs_path_service_accountgcs_path$redis_semantic_cache_embedding_modelredis_semantic_cache_index_nameredis_flush_sizeredis_startup_nodesdisk_cache_dirqdrant_api_baseqdrant_api_keyqdrant_collection_nameqdrant_quantization_config%qdrant_semantic_cache_embedding_modelgcp_service_accountgcp_ssl_ca_certsc(                    U[         R                  :X  aJ  U(       a,  UUUUUS.U(En)U&b  U&U)S'   U'b  U'U)S'   [        S0 U)D6U l        GO+[	        SUUUUS.U(D6U l        GOU[         R
                  :X  a  [        SUUUU
UUS.U(D6U l        OU[         R                  :X  a  [        U!U"U#U
U$U%S9U l        OU[         R                  :X  a  [        5       U l        OU[         R                  :X  a  [        SUUUUUUUUUUUS.U(D6U l        OkU[         R                  :X  a  [        UUUS	9U l        OFU[         R                  :X  a  [!        UUS
9U l        O"U[         R"                  :X  a  [%        U S9U l        S[&        R(                  ;  a  [&        R(                  R+                  S5        S[&        R,                  ;  a  [&        R.                  R1                  S5        S[&        R2                  ;  a  [&        R.                  R5                  S5        Xl        Xl        X`l        UU l        Xpl        U=(       d    [@        RB                  U l"        U R8                  [         R                  :X  a	  Ub  Xl        U R8                  [         R                  :X  d  U R8                  [         R
                  :X  a	  U	b  Xl        U R:                  b<  [G        U R                  [        5      (       a  U R:                  U R                  l        ggg)a  
Initializes the cache based on the given type.

Args:
    type (str, optional): The type of cache to initialize. Can be "local", "redis", "redis-semantic", "qdrant-semantic", "s3" or "disk". Defaults to "local".

    # Redis Cache Args
    host (str, optional): The host address for the Redis cache. Required if type is "redis".
    port (int, optional): The port number for the Redis cache. Required if type is "redis".
    password (str, optional): The password for the Redis cache. Required if type is "redis".
    namespace (str, optional): The namespace for the Redis cache. Required if type is "redis".
    ttl (float, optional): The ttl for the Redis cache
    redis_flush_size (int, optional): The number of keys to flush at a time. Defaults to 1000. Only used if batch redis set caching is used.
    redis_startup_nodes (list, optional): The list of startup nodes for the Redis cache. Defaults to None.

    # Qdrant Cache Args
    qdrant_api_base (str, optional): The url for your qdrant cluster. Required if type is "qdrant-semantic".
    qdrant_api_key (str, optional): The api_key for the local or cloud qdrant cluster.
    qdrant_collection_name (str, optional): The name for your qdrant collection. Required if type is "qdrant-semantic".
    similarity_threshold (float, optional): The similarity threshold for semantic-caching, Required if type is "redis-semantic" or "qdrant-semantic".

    # Disk Cache Args
    disk_cache_dir (str, optional): The directory for the disk cache. Defaults to None.

    # S3 Cache Args
    s3_bucket_name (str, optional): The bucket name for the s3 cache. Defaults to None.
    s3_region_name (str, optional): The region name for the s3 cache. Defaults to None.
    s3_api_version (str, optional): The api version for the s3 cache. Defaults to None.
    s3_use_ssl (bool, optional): The use ssl for the s3 cache. Defaults to True.
    s3_verify (bool, optional): The verify for the s3 cache. Defaults to None.
    s3_endpoint_url (str, optional): The endpoint url for the s3 cache. Defaults to None.
    s3_aws_access_key_id (str, optional): The aws access key id for the s3 cache. Defaults to None.
    s3_aws_secret_access_key (str, optional): The aws secret access key for the s3 cache. Defaults to None.
    s3_aws_session_token (str, optional): The aws session token for the s3 cache. Defaults to None.
    s3_config (dict, optional): The config for the s3 cache. Defaults to None.

    # GCS Cache Args
    gcs_bucket_name (str, optional): The bucket name for the gcs cache. Defaults to None.
    gcs_path_service_account (str, optional): Path to the service account json.
    gcs_path (str, optional): Folder path inside the bucket to store cache files.

    # Common Cache Args
    supported_call_types (list, optional): List of call types to cache for. Defaults to cache == on for all call types.
    **kwargs: Additional keyword arguments for redis.Redis() cache

Raises:
    ValueError: If an invalid cache type is provided.

Returns:
    None. Cache is set as a litellm param
)rC   rD   rE   r^   startup_nodesNrf   rg   )rC   rD   rE   r^   )rC   rD   rE   rJ   embedding_model
index_name)ra   rb   collection_namerJ   quantization_configrj   )rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   )bucket_namepath_service_accountr[   )account_url	container)r`   cacher,   )$LiteLLMCacheTypeREDISr   rr   r   REDIS_SEMANTICr   QDRANT_SEMANTICr   LOCALr   S3r   GCSr   
AZURE_BLOBr   DISKr   r    input_callbackappendsuccess_callbacklogging_callback_manageradd_litellm_success_callback_async_success_callback"add_litellm_async_success_callbackrK   rA   rF   r^   rG   r(   r*   rB   
isinstance)*selfrA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   kwargscluster_kwargss*                                             r%   __init__Cache.__init__8   s   Z #)))" !  ((8%8" " '2<ON#89#/9IN#56(9(KN(K
' %%5	
 
 %444+ !%9 D: DJ %555, /- 6%9$> EDJ %+++&DJ%(((  ---%# /%9)A%9# DJ %)))!+%=!DJ
 %000'-.DJ %***".ADJ'000""))'2'222,,II'R'999,,OOPWX$8!	" 0#;y';';	99(...3H3T,H II)///yy,;;;".+H>>%*TZZ*L*L#'>>DJJ  +M%r2   returnc                 L   SnU R                   " S0 UD6nUb  [        R                  " SU5        U$ [        R                  " 5       n[
        nU H  nXd;   a4  U R                  Xa5      nUb  U[        U5       S[        U5       3-  nM:  M<  Xe;  d  MC  [        R                  SL d  MX  X   c  M_  X   nU[        U5       S[        U5       3-  nM     [        R                  " SU5        [        R                  U5      nU R                  " U40 UD6nU R                  " SSU0UD6  U$ )z
Get the cache key for the given arguments.

Args:
    **kwargs: kwargs to litellm.completion() or embedding()

Returns:
    str: The cache key generated from the arguments, or None if no cache key could be generated.
 z
Returning preset cache key: %sz: Tz
Created cache key: %spreset_cache_keyr,   )!_get_preset_cache_key_from_kwargsr   r   r   _get_all_llm_api_paramsr   _get_param_valuestrr    3enable_caching_on_provider_specific_optional_paramsr4   _get_hashed_cache_key_add_namespace_to_cache_key_set_preset_cache_key_in_kwargs)	r   r   	cache_keyr   combined_kwargslitellm_param_kwargsparamparam_valuehashed_cache_keys	            r%   get_cache_keyCache.get_cache_key  sG    	  AAKFK'  !CEUV##*BBD1E'-1-B-B5-Q*CJ<r#k2B1C!DDI + 1 OOSWW}, "(-KCJ<r#k2B1C!DDI   	6	B 66yA;;<LWPVW,, 	
-	
17	
  r2   r   r   c                 f    US:X  a  U R                  U5      $ US:X  a  U R                  U5      $ X!   $ )z/
Get the value for the given param from kwargs
modelfile)_get_model_param_value_get_file_param_value)r   r   r   s      r%   r   Cache._get_param_value4  s=     G..v66f_--f55}r2   c                 F   UR                  S0 5      =(       d    0 nUR                  S0 5      =(       d    0 nUR                  S0 5      =(       d    0 nUR                  S5      =(       d    UR                  S5      nU R                  X%5      nU=(       d    U=(       d    US   $ )a|  
Handles getting the value for the 'model' param from kwargs

1. If caching groups are set, then return the caching group as the model https://docs.litellm.ai/docs/routing#caching-across-model-groups
2. Else if a model_group is set, then return the model_group as the model. This is used for all requests sent through the litellm.Router()
3. Else use the `model` passed in kwargs
metadatalitellm_paramsmodel_groupr   )get_get_caching_group)r   r   r   r   metadata_in_litellm_paramsr   caching_groups          r%   r   Cache._get_model_param_valueB  s      J39r%zz*:B?E2+9+=+=j"+M+SQS"%-\\&
 &;'++M: 	 //F>>vg>r2   r   r   c                 l    UR                  S/ 5      nU(       a  U H  nX$;   d  M
  [        U5      s  $    g )Ncaching_groups)r   r   )r   r   r   r   groups        r%   r   Cache._get_caching_groupS  s7     *26F)K''u:% ( r2   c                    UR                  S5      nUR                  S0 5      nUR                  S0 5      nUR                  S5      =(       d=    [        USS5      =(       d)    UR                  S5      =(       d    UR                  S5      $ )z_
Handles getting the value for the 'file' param from kwargs. Used for `transcription` requests
r   r   r   file_checksumnameN	file_name)r   getattr)r   r   r   r   r   s        r%   r   Cache._get_file_param_value]  s{     zz&!::j"-$4b9LL) /tVT*/||K(/ !!+.		
r2   c                 H    U(       a  SU;   a  US   R                  SS5      $ g)z
Get the preset cache key from kwargs["litellm_params"]

We use _get_preset_cache_keys for two reasons

1. optional params like max_tokens, get transformed for bedrock -> max_new_tokens
2. avoid doing duplicate / repeated work
r   r   N)r   )r   r   s     r%   r   'Cache._get_preset_cache_key_from_kwargsk  s,     6)./334FMMr2   r   c                 0    U(       a  SU;   a  XS   S'   ggg)z
Set the calculated cache key in kwargs

This is used to avoid doing duplicate / repeated work

Placed in kwargs["litellm_params"]
r   r   Nr,   )r   r   r   s      r%   r   %Cache._set_preset_cache_key_in_kwargsy  s(     6)?O'();< * r2   r   c                     [         R                  " U R                  5       5      nUR                  5       n[        R
                  " SU5        U$ )z
Get the hashed cache key for the given cache key.

Use hashlib to create a sha256 hash of the cache key

Args:
    cache_key (str): The cache key to hash.

Returns:
    str: The hashed cache key.
zHashed cache key (SHA-256): %s)hashlibsha256encode	hexdigestr   r   )r   hash_objecthash_hexs      r%   r   Cache._get_hashed_cache_key  s?     nnY%5%5%78((*=xHr2   r   c                    UR                  S0 5      nUR                  S5      =(       d4    UR                  S0 5      R                  S5      =(       d    U R                  nU(       a  U SU 3n[        R                  " SU5        U$ )z
If a redis namespace is provided, add it to the cache key

Args:
    hash_hex (str): The hashed cache key.
    **kwargs: Additional keyword arguments.

Returns:
    str: The final hashed cache key with the redis namespace.
rr   rF   r   redis_namespace:zFinal hashed key: %s)r   rF   r   r   )r   r   r   dynamic_cache_controlrF   s        r%   r   !Cache._add_namespace_to_cache_key  s~     6<ZZ5L!%%k2 zz*b)--.?@~~ 	
 #AhZ0H3X>r2   c              #      #    Sn[        S[        U5      U5       H-  nSSSXX2-    S.0/0v   [        R                  " [        5        M/     g 7f)N   r   choicesdelta	assistant)rolecontent)rangelentimesleepr   )r   r   
chunk_sizeis       r%   generate_streaming_content Cache.generate_streaming_content  s\     
q#g,
3A$/'.1>'B"	 	 JJ34 4s   AAcached_resultmax_agec                 d   Ub  [        U[        5      (       ap  SU;   aj  US   n[        R                  " 5       nXC-
  nUb  XR:  a  gUR                  S5      n [        U[        5      (       a   U$ [        R
                  " U5      n U$ U$ ! [         a    [        R                  " U5      n U$ f = f)z<
Common get cache logic across sync + async implementations
N	timestampresponse)	r   dictr   r   jsonloadsr#   astliteral_eval)r   r   r   r   current_timeresponse_agecached_responses          r%   _get_cache_logicCache._get_cache_logic  s     %=$//},%k2I99;L (3L "|'= ,//
;ODot44 #" '+jj''O
 #"  D"%"2"2?"C""Ds   B 0B  B/.B/dynamic_cache_objectc                 
    U R                   " S0 UD6SLa  gUR                  S/ 5      nSU;   a  US   nOU R                  " S0 UD6nUb  UR                  S0 5      nUR                  S5      =(       d#    UR                  S5      =(       d    [        S5      nUb  UR	                  XCS	9nOU R
                  R	                  XCS	9nU R                  XvS
9$ g! [         a$    [        S[        R                  " 5        35         gf = f)z
Retrieves the cached result for the given arguments.

Args:
    *args: args to litellm.completion() or embedding()
    **kwargs: kwargs to litellm.completion() or embedding()

Returns:
    The cached result if it exists, otherwise None.
TNmessagesr   rr   s-maxage	s-max-ageinf)r   r   r   An exception occurred: r,   )should_use_cacher   r   float	get_cacherr   r   r#   r&   	traceback
format_exc)r   r   r   r   r   cache_control_argsr   r   s           r%   r   Cache.get_cache  s&   	$$.v.d:zz*b1Hf$";/	 ..88	$:@**Wb:Q"&**:6 $)--k:$U| 
 (3$8$B$B! %C %M %)JJ$8$8$8$VM,,"/ -   %   	3I4H4H4J3KLM	s   C B:C +DDc           	      *  #     U R                   " S0 UD6SLa  gUR                  S/ 5        SU;   a  US   nOU R                  " S0 UD6nUb  UR                  S0 5      nUR                  SUR                  S[        S5      5      5      nUb  UR                  " U40 UD6I Sh  vN nO%U R
                  R                  " U40 UD6I Sh  vN nU R                  XeS	9$ g N: N! [         a$    [        S
[        R                  " 5        35         gf = f7f)zL
Async get cache implementation.

Used for embedding calls in async wrapper
TNr   r   rr   r   r   r   r   r   r,   )r   r   r   r   async_get_cacherr   r   r#   r&   r   r   )r   r   r   r   r   r   r   s          r%   r   Cache.async_get_cache  s;    	$$.v.d:JJz2&f$";/	 ..88	$%+ZZ%<",00!3!7!7
E%L!Q (3*>*N*N!+%++ %M +/***D*D!+%++ %M ,,"/ -   %%%  	3I4H4H4J3KLM	sW   DC" DB	C" #C$%C" 	C 
C" DC"  C" "+DDDDc                     SU;   a  US   nOU R                   " S0 UD6nUb  [        U[        5      (       a  UR                  5       nU R                  b  U R                  US'   UR                  SS5      n[        U[        5      (       a%  UR                  5        H  u  pVUS:X  d  M  XbS'   M     [        R                  " 5       US.nX7U4$ [        S5      e! [         a  nUeSnAff = f)z?
Common implementation across sync + async add_cache functions
r   NrG   rr   )r   r   zcache key is Noner,   )
r   r   r
   model_dump_jsonrG   r   r   itemsr   r#   )	r   resultr   r   _cache_kwargskvcached_dataes	            r%   _add_cache_logicCache._add_cache_logic1  s    	f$";/	 ..88	$fi00#335F 88'$(HHF5M &

7D 9mT22 - 3 3 5:,-5M !6 -1IIKVL v55 344 	G	s$   B"C (#C C 
C(!C##C(c                     U R                   " S0 UD6SLa  gU R                  " SSU0UD6u  p4nU R                  R                  " X440 UD6  g! [         a,  n[
        R                  " S[        U5       35         SnAgSnAff = f)z
Adds a result to the cache.

Args:
    *args: args to litellm.completion() or embedding()
    **kwargs: kwargs to litellm.completion() or embedding()

Returns:
    None
TNr   #LiteLLM Cache: Excepton add_cache: r,   )r   r   rr   	set_cacher#   r   	exceptionr   )r   r   r   r   r   r   s         r%   	add_cacheCache.add_cacheO  s    	U$$.v.d:-1-B-B ..!'.*IF JJ  B6B 	U$$'J3q6(%STT	Us   A 4A 
B"A>>Bc                   #     U R                   " S0 UD6SLa  gU R                  S:X  a)  U R                  b  U R                  " U40 UD6I Sh  vN   gU R                  " SSU0UD6u  pEnUb  UR
                  " XE40 UD6I Sh  vN   gU R                  R
                  " XE40 UD6I Sh  vN   g Na N- N	! [         a,  n[        R                  " S[        U5       35         SnAgSnAff = f7f)z#
Async implementation of add_cache
TNredisr   r  r,   )r   rA   r^   batch_cache_writer   async_set_cacherr   r#   r   r  r   )r   r   r   r   r   r   r   s          r%   async_add_cacheCache.async_add_cached  s    	U$$.v.d:yyG#(=(=(I,,V>v>>>151F1F 2!2%+2.	 (3.>>!28   **44YVvVVV ? W 	U$$'J3q6(%STT	Us   C.B5 C.3B5 B/B5 C.0B5 B1B5 C.	 B5 )B3*B5 .C./B5 1B5 3B5 5
C+?"C&!C.&C++C.embedding_responser   c                     [        U[        5      (       a4  UR                  S5      UR                  S5      UR                  S5      US.$ [        US5      (       aD  UR	                  5       nUR                  S5      UR                  S5      UR                  S5      US.$ [        U5      nUR                  S5      UR                  S5      UR                  S5      US.$ ! [         a  n[        SU 35      eSnAff = f)zX
Convert any embedding response into the standardized CachedEmbedding TypedDict format.
r9   indexobject)r9   r  r  r   
model_dumpz,Missing expected key in embedding response: N)r   r   r   hasattrr  varsKeyError
ValueError)r   r  r   datar   s        r%   _convert_to_cached_embedding"Cache._convert_to_cached_embedding}  s   	Q,d33!3!7!7!D/33G<044X>"	  +\::)446!%+!6!XXg."hhx0"	  ./!%+!6!XXg."hhx0"	   	QKA3OPP	Qs%   AC AC  >C 
C<)C77C<r   inputidx_in_result_datac                     U R                   " S0 0 UESU0ED6nXSS'   UR                  U   nUR                  nU R                  Xg5      nU R                  " SSU0UD6u  pnXU4$ )Nr  r   r   r,   )r   r  r   r  r   )r   r   r  r   r  r   r  
model_nameembedding_dictr   r   s              r%   add_embedding_response_to_cache%Cache.add_embedding_response_to_cache  s      --K0J60J7E0JK.{#[[);< \\
*.*K*K+
 *.)>)> *
!*
*
&	 v--r2   c                   #     U R                   " S0 UD6SLa  gU R                  b  U R                  US'   / n[        US   [        5      (       a@  [	        US   5       H-  u  pVU R                  XX55      u  nnnUR                  Xx45        M/     OB[        US   [        5      (       a*  U R                  XS   U5      u  pxnUR                  Xx45        Ub  UR                  " SSU0UD6I Sh  vN   gU R                  R                  " SSU0UD6I Sh  vN   g N, N! [         a,  n	[        R                  " S[        U	5       35         Sn	A	gSn	A	ff = f7f)zm
Async implementation of add_cache for Embedding calls

Does a bulk write, to prevent using too many clients
TNrG   r  
cache_listr  r,   )r   rG   r   list	enumerater  r}   r   async_set_cache_pipelinerr   r#   r   r  )
r   r   r   r   r"  idxr   r   r   r   s
             r%   async_add_cache_pipelineCache.async_add_cache_pipeline  ss     	U$$.v.d: xx# $uJ&/400'w8FC
 <<VT	!#%%y&>? 9 F7OS11151U1U7OV2.	 !!9":;#/*CC )-3   jj99 )-3  	  	U$$'J3q6(%STT	Usi   ED ECD ,D-D 1E2!D DD ED D 
E'"E	EEEc                     U R                   [        R                  :X  a  gUR                  SS5      n[        R
                  " SX5        U(       a+  [        U[        5      (       a  UR                  SS5      SL a  gg)z
Returns true if we should use the cache for LLM API calls

If cache is default_on then this is True
If cache is default_off then this is only true when user has opted in to use cache
Trr   Nz(should_use_cache: kwargs: %s; _cache: %sz	use-cacheF)rB   r(   r*   r   r   r   r   r   )r   r   _caches      r%   r   Cache.should_use_cache  sd     99	,,, GT*GXj..zz+u-5r2   c                    #    U R                   " SSU0UD6u  p4nU R                  R                  " X440 UD6I S h  vN   g  N7f)Nr   r,   )r   rr   r
  )r   r   r   r   r   s        r%   r
  Cache.batch_cache_write  s@     )-)>)>)Wf)WPV)W&	jj**9LVLLLs   8AA Ac                 h   #    [        U R                  S5      nU(       a  U" 5       I S h  vN $ g  N7f)Npingr   rr   )r   
cache_pings     r%   r/  
Cache.ping  s+     TZZ0
#%% &s   (202c                 j   #    [        U R                  S5      nU(       a  U" U5      I S h  vN $ g  N7f)Ndelete_cache_keysr0  )r   keyscache_delete_cache_keyss      r%   r4  Cache.delete_cache_keys  s0     ")$**6I"J"0666 7s   )313c                    #    [        U R                  S5      (       a#  U R                  R                  5       I S h  vN   g g  N7f)N
disconnect)r  rr   r9  r   s    r%   r9  Cache.disconnect  s4     4::|,,**''))) -)s   9AAAc                     g)z}
Internal method to check if the cache type supports async get/set operations

All cache types now support async operations

Tr,   r:  s    r%   _supports_asyncCache._supports_async  s     r2   )rr   rB   rF   r^   rK   rG   rA   r   )r   )2r-   r.   r/   r0   rs   rw   r(   r*   r   r   r   r   CachingSupportedCallTypesboolr	   r   intr   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r  r  CachedEmbeddingr  r   r   r  r'  r   r
  r/  r4  r9  r=  r1   r,   r2   r%   r4   r4   7   s    ,<+A+A   """&#'#150404K
 ,0.2(,(,(,%)04)-.226.2#'!%)-26"&4L9=*..2(,)-(,04485M-1*.oN2'(N2 
N2 smN2 smN2 3-N2 C=N2 e_N2  (N2 'uoN2 'uoN2 't,E'FGN26 $C=7N28 'sm9N2: !;N2< !=N2> !?N2@ TNAN2B E$),-CN2D "#EN2F 'smGN2H #+3-IN2J 'smKN2L C=MN2N #ON2P "#QN2R #+3-SN2T 3-UN2V /2WN2X *2#YN2Z #3-[N2\ &d^]N2^ !_N2` "#aN2b !cN2d !)eN2f %-SMgN2h 03iN2l &c]mN2n #3-oN2`*  * X  
#	?T ?c ?"+3C=	#
D 
S 
Xc] 
P 
PRV 
P    $C c ,5%}% %%N%hy.A %P ;?$$,Y$7$L<U, CGU,4Y,?U2Q"%Q.6smQ	QL #$.!. . 	.
  . 
sD$	.0 CG(U,4Y,?(UT$M* r2   r4   r6   rA   rC   rD   rE   rK   c           	      $   [        S5        S[        R                  ;  a  [        R                  R                  S5        S[        R                  ;  a  [        R
                  R                  S5        S[        R                  ;  a  [        R
                  R                  S5        [        R                  c  [        SU UUUUS.UD6[        l	        [        S[        R                   35        [        S[        [        R                  5       35        g)a  
Enable cache with the specified configuration.

Args:
    type (Optional[Literal["local", "redis", "s3", "disk"]]): The type of cache to enable. Defaults to "local".
    host (Optional[str]): The host address of the cache server. Defaults to None.
    port (Optional[str]): The port number of the cache server. Defaults to None.
    password (Optional[str]): The password for the cache server. Defaults to None.
    supported_call_types (Optional[List[Literal["completion", "acompletion", "embedding", "aembedding"]]]):
        The supported call types for the cache. Defaults to ["completion", "acompletion", "embedding", "aembedding"].
    **kwargs: Additional keyword arguments.

Returns:
    None

Raises:
    None
zLiteLLM: Enabling Cacherr   NrA   rC   rD   rE   rK   z&LiteLLM: Cache enabled, litellm.cache=LiteLLM Cache: r,   )r&   r    r|   r}   r~   r   r   r   r   rr   r4   r  rA   rC   rD   rE   rK   r   s         r%   enable_cacherH    s    J +,g,,,%%g.g...((EEgNg555((KKGT}} 
!5
 
 :7==/JKOD$7#89:r2   c           	          [        S5        [        SU UUUUS.UD6[        l        [        S[        R                   35        [        S[	        [        R                  5       35        g)a  
Update the cache for LiteLLM.

Args:
    type (Optional[Literal["local", "redis", "s3", "disk"]]): The type of cache. Defaults to "local".
    host (Optional[str]): The host of the cache. Defaults to None.
    port (Optional[str]): The port of the cache. Defaults to None.
    password (Optional[str]): The password for the cache. Defaults to None.
    supported_call_types (Optional[List[Literal["completion", "acompletion", "embedding", "aembedding"]]]):
        The supported call types for the cache. Defaults to ["completion", "acompletion", "embedding", "aembedding"].
    **kwargs: Additional keyword arguments for the cache.

Returns:
    None

zLiteLLM: Updating CacherE  z&LiteLLM: Cache Updated, litellm.cache=rF  Nr,   )r&   r4   r    rr   r  rG  s         r%   update_cacherJ  I  sg    F +, 1 GM :7==/JKOD$7#89:r2   c                  z   SSK Jn   [        S5        U " [        5         [        R
                  R                  S5        [        R                  R                  S5        [        R                  R                  S5        SSS5        S[        l	        [        S[        R                   35        g! , (       d  f       N6= f)a*  
Disable the cache used by LiteLLM.

This function disables the cache used by the LiteLLM module. It removes the cache-related callbacks from the input_callback, success_callback, and _async_success_callback lists. It also sets the litellm.cache attribute to None.

Parameters:
None

Returns:
None
r   suppresszLiteLLM: Disabling Cacherr   Nz'LiteLLM: Cache disabled, litellm.cache=)

contextlibrM  r&   r  r    r|   remover~   r   rr   rL  s    r%   disable_cacherP  y  s     $,-	*	%%g.  ''0''..w7 

 GM;GMM?KL 
	s   AB,,
B:);r   r   r   r   r   enumr   typingr   r   r   r   r   r	   pydanticr
   r    litellm._loggingr   litellm.constantsr   -litellm.litellm_core_utils.model_param_helperr   litellm.types.cachinglitellm.types.utilsr   r   azure_blob_cacher   
base_cacher   
disk_cacher   
dual_cacher   	gcs_cacher   in_memory_cacher   qdrant_semantic_cacher   redis_cacher   redis_cluster_cacher   redis_semantic_cacher   s3_cacher   r&   r   r(   r4   rs   rw   r?  rH  rJ  rP  r,   r2   r%   <module>rd     sQ         : :   + : J # E , ! ! !  * 6 # 2 4  T  U Ur (8'='="G7;
#
$7;
3-7; 3-7; sm	7;
 #4(A#BC7;v (8'='="G-;
#
$-;
3--; 3--; sm	-;
 #4(A#BC-;`Mr2   