
    ^h                     B   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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rS S
KJr  S SK7  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K0J1r1  S r2 " S S\3\5      r4 " S S5      r5\6Rn                  SSS/ SQ4S\\6   S\\3   S\\3   S \\3   S!\\
\8      4
S" jjr9\6Rn                  SSS/ SQ4S\\6   S\\3   S\\3   S \\3   S!\\
\8      4
S# jjr:S$ r;g)%    N)Enum)AnyDictListOptionalSetUnion)TranscriptionCreateParams)"CompletionCreateParamsNonStreamingCompletionCreateParamsStreaming)r   )r   )EmbeddingCreateParams)	BaseModel)verbose_logger)*)RerankRequest)all_litellm_params   )	BaseCache)	DiskCache)	DualCache)InMemoryCache)QdrantSemanticCache)
RedisCache)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/home/james-whalen/.local/lib/python3.13/site-packages/litellm/caching/caching.pyprint_verboser$   0   s=    _-/"  s   6: 
AAc                       \ rS rSrSrSrSrg)	CacheMode9   
default_ondefault_off N)__name__
__module____qualname____firstlineno__r(   r)   __static_attributes__r*       r#   r&   r&   9   s    JKr0   r&   c            :       z   \ 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4 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"\\	   48S# jjrS$\	4S% jrS&\	S'\S$\\	   4S( jrS'\S$\	4S) jrS*\S+\\	   S$\\	   4S, jrS'\S$\	4S- jrS$\\	   4S. jrS/\	S$S4S0 jrS$\\	   4S1 jrS$\\	   4S2 jrS$\\	   4S3 jrS$\\	   4S4 jrS$\\	   4S5 jrS$\\	   4S6 jr S$\\	   4S7 jr!\"S8\	S$\	4S9 j5       r#S:\	S$\	4S; jr$S< r%S=\\   S>\\
   4S? jr&S@ r'SA r(SB r)SC r*SD r+SE r,SF r-SG r.SH r/SI r0SJ r1S$\4SK jr2SLr3g)MCache?   N

completionacompletion	embedding
aembeddingatranscriptiontranscriptionatext_completiontext_completionarerankrerankTFztext-embedding-ada-002typemodehostportpassword	namespacettldefault_in_memory_ttldefault_in_redis_ttlsimilarity_thresholdsupported_call_types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redis_flush_sizeredis_startup_nodesqdrant_api_baseqdrant_api_keyqdrant_collection_nameqdrant_quantization_configc!                    U[         R                  :X  a  [        SUUUUUS.U!D6U l        OU[         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        OwU[         R                  :X  a  [        5       U l        OSU[         R                  :X  a  [        SUUUUUUUUUUUS.U!D6U l        O"U[         R                  :X  a  [        US9U l        S[        R                  ;  a  [        R                  R!                  S5        S[        R"                  ;  a  [        R"                  R!                  S5        S[        R$                  ;  a  [        R$                  R!                  S5        Xl        Xl        X`l        UU l        Xpl        U=(       d    [0        R2                  U l        U R(                  [         R                  :X  a	  Ub  Xl        U R(                  [         R                  :X  d  U R(                  [         R                  :X  a	  U	b  Xl        U R*                  b<  [7        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.

    # 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
)rA   rB   rC   rU   startup_nodes)rA   rB   rC   rH   	use_asyncembedding_model)rW   rX   collection_namerH   quantization_configr^   )rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   )disk_cache_dircacheNr*   )LiteLLMCacheTypeREDISr   rb   REDIS_SEMANTICr   QDRANT_SEMANTICr   LOCALr   S3r   DISKr   r   input_callbackappendsuccess_callback_async_success_callbackrI   r?   rD   rU   rE   r&   r(   r@   
isinstance)"selfr?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   redis_semantic_cache_use_async$redis_semantic_cache_embedding_modelrU   rV   ra   rW   rX   rY   rZ   %qdrant_semantic_cache_embedding_modelkwargss"                                     r#   __init__Cache.__init__@   sF   @ #)))$. %!!11% %DJ %444+ !%98 D DJ %555, /- 6%9$> EDJ %+++&DJ%(((  ---%# /%9)A%9# DJ %***".ADJ'000""))'2'222$$++G4'999++227;$8!	" 0#;y';';	99(...3H3T,H II)///yy,;;;".+H>>%*TZZ*L*L#'>>DJJ  +M%r0   returnc                 B   SnU R                   " S0 UD6nUb  [        R                  " SU5        U$ 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   '_get_relevant_args_to_use_for_cache_keyr   _get_param_valuestrr   3enable_caching_on_provider_specific_optional_paramsr2   _get_hashed_cache_key!_add_redis_namespace_to_cache_key_set_preset_cache_key_in_kwargs)	ro   rs   	cache_keyry   combined_kwargslitellm_param_kwargsparamparam_valuehashed_cache_keys	            r#   get_cache_keyCache.get_cache_key   sM    	  AAKFK'  !CEUV##FFH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AA
 &
 	,, 	
-	
17	
  r0   r   rs   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)ro   r   rs   s      r#   r|   Cache._get_param_value  s=     G..v66f_--f55}r0   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)ro   rs   r   r   metadata_in_litellm_paramsr   caching_groups          r#   r   Cache._get_model_param_value$  s      J39r%zz*:B?E2+9+=+=j"+M+SQS"%-\\&
 &;'++M: 	 //F>>vg>r0   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}   )ro   r   r   r   groups        r#   r   Cache._get_caching_group5  s7     *26F)K''u:% ( r0   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)ro   rs   r   r   r   s        r#   r   Cache._get_file_param_value?  s{     zz&!::j"-$4b9LL) /tVT*/||K(/ !!+.		
r0   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   ry   N)r   )ro   rs   s     r#   rz   'Cache._get_preset_cache_key_from_kwargsM  s,     6)./334FMMr0   ry   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   ry   Nr*   )ro   ry   rs   s      r#   r   %Cache._set_preset_cache_key_in_kwargs[  s(     6)?O'();< * r0   c                    U R                  5       nU R                  5       nU R                  5       nU R                  5       nU R	                  5       nU R                  5       nUR                  UUUU5      nUR                  U5      nU$ )z@
Gets the supported kwargs for each call type and combines them
)-_get_litellm_supported_chat_completion_kwargs-_get_litellm_supported_text_completion_kwargs'_get_litellm_supported_embedding_kwargs+_get_litellm_supported_transcription_kwargs$_get_litellm_supported_rerank_kwargs%_get_kwargs_to_exclude_from_cache_keyunion
difference)ro   chat_completion_kwargstext_completion_kwargsembedding_kwargstranscription_kwargsrerank_kwargsexclude_kwargsr   s           r#   r{   -Cache._get_relevant_args_to_use_for_cache_keyg  s     "&!S!S!U!%!S!S!UGGI#OOQAACCCE066" 	
 *44^Dr0   c                     [        [        R                  R                  5       5      R	                  [        [
        R                  R                  5       5      5      nU$ )zT
Get the litellm supported chat completion kwargs

This follows the OpenAI API Spec
)setr   __annotations__keysr   r   )ro   all_chat_completion_kwargss     r#   r   3Cache._get_litellm_supported_chat_completion_kwargs{  sJ     &).>>CCE&

%3CCHHJK
L 	# *)r0   c                     [        [        R                  R                  5       5      R	                  [        [
        R                  R                  5       5      5      nU$ )zT
Get the litellm supported text completion kwargs

This follows the OpenAI API Spec
)r   &TextCompletionCreateParamsNonStreamingr   r   r   #TextCompletionCreateParamsStreaming)ro   all_text_completion_kwargss     r#   r   3Cache._get_litellm_supported_text_completion_kwargs  sJ     &)2BBGGI&

%7GGLLNO
P 	# *)r0   c                 P    [        [        R                  R                  5       5      $ )z)
Get the litellm supported rerank kwargs
)r   r   model_fieldsr   ro   s    r#   r   *Cache._get_litellm_supported_rerank_kwargs  s     =--22455r0   c                 P    [        [        R                  R                  5       5      $ )zN
Get the litellm supported embedding kwargs

This follows the OpenAI API Spec
)r   r   r   r   r   s    r#   r   -Cache._get_litellm_supported_embedding_kwargs  s     (88==?@@r0   c                 P    [        [        R                  R                  5       5      $ )zR
Get the litellm supported transcription kwargs

This follows the OpenAI API Spec
)r   r
   r   r   r   s    r#   r   1Cache._get_litellm_supported_transcription_kwargs  s     ,<<AACDDr0   c                     [        S/5      $ )z.
Get the kwargs to exclude from the cache key
r   )r   r   s    r#   r   +Cache._get_kwargs_to_exclude_from_cache_key  s     J<  r0   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r0   r   c                     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.
r   redis_namespace:zFinal hashed key: %s)r   rD   r   r   )ro   r   rs   rD   s       r#   r   'Cache._add_redis_namespace_to_cache_key  sR     JJz2.223DEW	#AhZ0H3X>r0   c              #      #    Sn[        S[        U5      U5       H)  nSSSXX2-    S.0/0v   [        R                  " S5        M+     g 7f)N   r   choicesdelta	assistant)rolecontentg{Gz?)rangelentimesleep)ro   r   
chunk_sizeis       r#   generate_streaming_content Cache.generate_streaming_content  s[     
q#g,
3A$/'.1>'B"	 	 JJt 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)	rn   dictr   r   jsonloadsr!   astliteral_eval)ro   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/c           	          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be  UR                  S0 5      nUR                  SUR                  S[        S5      5      5      nU R                  R                  X2S	9nU R                  XeS
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   rb   	s-max-ages-maxageinf)r   r   r   An exception occurred: r*   )should_use_cacher   r   floatrb   	get_cacher   r!   r$   	traceback
format_exc)ro   rs   r   r   cache_control_argsr   r   s          r#   r   Cache.get_cache  s    	$$.v.d:zz*b1Hf$";/	 ..88	$%+ZZ%<",00!3!7!7
E%L!Q !%

 4 4Y 4 R,,"/ -   %  	3I4H4H4J3KLM	s   B1 BB1 1+CC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bq  UR                  S0 5      nUR                  SUR                  S[        S5      5      5      nU R                  R
                  " U40 UD6I Sh  vN nU R                  XTS	9$ g 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   rb   r   r   r   r   r   r*   )r   r   r   r   rb   async_get_cacher   r!   r$   r   r  )ro   rs   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 '+jj&@&@&Uf&U U,,"/ -   %
 !V  	3I4H4H4J3KLM	sE   C2C C2BC *B?+C =C2?C +C/,C2.C//C2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   NrE   rb   )r   r   zcache key is Noner*   )
r   rn   r   model_dump_jsonrE   r   r   itemsr   r!   )	ro   resultrs   r   _cache_kwargskvcached_dataes	            r#   _add_cache_logicCache._add_cache_logicD  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  rb   	set_cacher!   r   	exceptionr}   ro   r
  rs   r   r  r  s         r#   	add_cacheCache.add_cacheb  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  p4nU R
                  R                  " X440 UD6I Sh  vN   g NB 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   r?   rU   batch_cache_writer  rb   async_set_cacher!   r   r  r}   r  s         r#   async_add_cacheCache.async_add_cachew  s     	U$$.v.d:yyG#(=(=(I,,V>v>>>151F1F 2!2%+2.	 jj00R6RRR ? S 	U$$'J3q6(%STT	Ush   CB C3B BB C7B 
BB CB B 
C
"C CC

Cc                   #     U R                   " S	0 UD6SLa  gU R                  b  U R                  US'   / n[        US   5       HY  u  pEU R                  " S	0 0 UESU0ED6nXbS'   UR                  U   nU R
                  " S	SU0UD6u  pnUR                  X45        M[     U R                  R                  " S	SU0UD6I Sh  vN   g 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
TNrE   inputr   r
  
cache_listr  r*   )r   rE   	enumerater   datar  rk   rb   async_set_cache_pipeliner!   r   r  r}   )ro   r
  rs   r!  idxr   ry   embedding_responser   r  r  s              r#   async_add_cache_pipelineCache.async_add_cache_pipeline  s    	U$$.v.d: xx# $uJ#F7O4#'#5#5#O8N68N7A8N#O &6{#%+[[%5"151F1F 2-22.	 !!9":; 5 **55VVvVVV  	U$$'J3q6(%STT	UsK   DC DB*C C
C 	D
C 
D"C=8D=DD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
Trb   Nz(should_use_cache: kwargs: %s; _cache: %sz	use-cacheF)r@   r&   r(   r   r   r   rn   r   )ro   rs   _caches      r#   r   Cache.should_use_cache  sd     99	,,, GT*GXj..zz+u-5r0   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  rb   r  )ro   r
  rs   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   rb   )ro   
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  )ro   r   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)hasattrrb   r8  r   s    r#   r8  Cache.disconnect  s4     4::|,,**''))) -)s   9AAAc                 d    U R                   (       a  U R                   [        R                  :X  a  gg)z
Internal method to check if the cache type supports async get/set operations

Only S3 Cache Does NOT support async operations

FT)r?   rc   rh   r   s    r#   _supports_asyncCache._supports_async  s#     99&6&9&99r0   )rb   r@   rD   rU   rI   rE   r?   )4r+   r,   r-   r.   rc   rg   r&   r(   r   r}   r   r   CachingSupportedCallTypesboolr	   r   intrt   r   r   r|   r   r   r   rz   r   r   r{   r   r   r   r   r   r   staticmethodr   r   r   r   r   r  r  r  r  r'  r   r  r/  r4  r8  r<  r/   r*   r0   r#   r2   r2   ?   s    ,<+A+A   """&#'#150404K
 )-(,(,%)04)-.226.2#'!%',-E*..2)-(,0448.F_f2'(f2 
f2 smf2 smf2 3-f2 C=f2 e_f2  (f2 'uof2 'uof2 't,E'FGf26 !7f28 !9f2: !;f2< TN=f2> E$),-?f2@ "#Af2B 'smCf2D #+3-Ef2F 'smGf2H C=If2J #Kf2P #3-Qf2R &d^Sf2V "#Wf2X !Yf2Z !)[f2\ %-SM]f2P,  , \  
#	?T ?c ?"+3C=	#
D 
S 
Xc] 
P 
PRV 
PS (	*s3x 	*	*s3x 	*6c#h 6AS AESX E!s3x !    $# C "%}% %%N@:<U*U&"UH$M*	 	r0   r2   r4   r?   rA   rB   rC   rI   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 Cacherb   Nr?   rA   rB   rC   rI   z&LiteLLM: Cache enabled, litellm.cache=LiteLLM Cache: r*   )	r$   r   rj   rk   rl   rm   rb   r2   varsr?   rA   rB   rC   rI   rs   s         r#   enable_cacherG    s    J +,g,,,%%g.g...  ''0g555''..w7}} 
!5
 
 :7==/JKOD$7#89:r0   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 CacherC  z&LiteLLM: Cache Updated, litellm.cache=rD  Nr*   )r$   r2   r   rb   rE  rF  s         r#   update_cacherI    sg    F +, 1 GM :7==/JKOD$7#89:r0   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 Cacherb   Nz'LiteLLM: Cache disabled, litellm.cache=)

contextlibrL  r$   
ValueErrorr   rj   removerl   rm   rb   rK  s    r#   disable_cacherP  J  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	   .openai.types.audio.transcription_create_paramsr
   *openai.types.chat.completion_create_paramsr   r   %openai.types.completion_create_paramsr   r   $openai.types.embedding_create_paramsr   pydanticr   r   litellm._loggingr   litellm.types.cachinglitellm.types.rerankr   litellm.types.utilsr   
base_cacher   
disk_cacher   
dual_cacher   in_memory_cacher   qdrant_semantic_cacher   redis_cacher   redis_semantic_cacher   s3_cacher   r$   r}   r&   r2   rc   rg   r>  rG  rI  rP  r*   r0   r#   <module>rd     s]         8 8 T G   + # . 2 ! ! ! * 6 # 4  T  ^
 ^
D (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r0   