
    hz                     "   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ d dlZd dlmZ d dlmZ d dlmZ d dl d d	lmZmZ d
dlmZ d
dlmZ d
dlm Z  d
dl!m"Z" d
dl#m$Z$ d
dl%m&Z& d
dl'm(Z( d
dl)m*Z* d
dl+m,Z, d
dl-m.Z. d Z/ G d de0e      Z1 G d d      Z2e3jh                  dddg dfdee3   dee0   dee0   dee0   dee
e5      f
d Z6e3jh                  dddg dfdee3   dee0   dee0   dee0   dee
e5      f
d!Z7d" Z8y)#    N)Enum)AnyDictListOptionalTupleUnion)	BaseModel)verbose_logger)CACHED_STREAMING_CHUNK_DELAY)ModelParamHelper)*)EmbeddingResponseall_litellm_params   )AzureBlobCache)	BaseCache)	DiskCache)	DualCache)InMemoryCache)QdrantSemanticCache)
RedisCache)RedisClusterCache)RedisSemanticCache)S3Cachec                     	 t        j                  |        t        j                  rt	        |        y y # t
        $ r Y y w xY w)N)r   debuglitellmset_verboseprint	Exception)print_statements    S/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/caching/caching.pyprint_verboser$   '   s=    _-/"  s   04 	A A c                       e Zd ZdZdZy)	CacheMode
default_ondefault_offN)__name__
__module____qualname__r'   r(        r#   r&   r&   0   s    JKr-   r&   c            E       F   e Zd Zej                  ej                  ddddddddg ddddddddddddddddddddddddf"dee   dee   dee   dee   d	ee   d
ee   dee	   dee	   dee	   dee	   dee
e      dee   dee   dee   dee   dee   dee   deeeef      dee   dee   dee   dee   dee   dee   dedee   dee   d ee
   d!ee   d"ee   d#ee   d$ee   d%ee   d&efDd'Zd(efd)Zd*ed+ed(ee   fd,Zd+ed(efd-Zd.ed/ee   d(ee   fd0Zd+ed(efd1Zd(ee   fd2Zd3ed(dfd4Zed5ed(efd6       Zd7ed(efd8Zd9 Zd:ee   d;ee	   fd<Zd= Zd> Zd? Z d@ Z!dA Z"dBedCee   d(e#fdDZ$	 dPdEe%dFed+edGed(e&eeef   f
dHZ'dI Z(dJ Z)dK Z*dL Z+dM Z,dN Z-d(efdOZ.y)QCacheN

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$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_modelc#                 d   |t         j                  k(  r0|rt        d
|||||d|#| _        nt	        d
||||d|#| _        n|t         j
                  k(  rt        d
||||
||d|#| _        n|t         j                  k(  rt        ||| |
|!|"      | _        n|t         j                  k(  rt               | _        nz|t         j                  k(  rt        d
|||||||||||d|#| _        nJ|t         j                  k(  rt        ||      | _        n$|t         j                  k(  rt!        |      | _        dt"        j$                  vrt"        j$                  j'                  d       dt"        j(                  vrt"        j*                  j-                  d       dt"        j.                  vrt"        j*                  j1                  d       || _        || _        || _        || _        || _        |xs t<        j>                  | _         | j4                  t         j                  k(  r	||| _        | j4                  t         j                  k(  s| j4                  t         j
                  k(  r	|	|	| _        | j6                  7tC        | j                  t              r| j6                  | j                  _        y	y	y	)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
        )r=   r>   r?   rU   startup_nodes)r=   r>   r?   rU   )r=   r>   r?   rD   embedding_model
index_name)rX   rY   collection_namerD   quantization_configr_   )rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   )account_url	container)rW   cacheNr,   )"LiteLLMCacheTypeREDISr   re   r   REDIS_SEMANTICr   QDRANT_SEMANTICr   LOCALr   S3r   
AZURE_BLOBr   DISKr   r   input_callbackappendsuccess_callbacklogging_callback_manageradd_litellm_success_callback_async_success_callback"add_litellm_async_success_callbackrE   r;   r@   rU   rA   r&   r'   r<   
isinstance)$selfr;   r<   r=   r>   r?   r@   rA   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\   kwargss$                                       r#   __init__zCache.__init__7   s   D #)))"(9 )%%5"5) )
 ( %%5	
 
 %444+ !%9 D: DJ %555, /- 6%9$> EDJ %+++&DJ%(((  ---%# /%9)A%9# 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,DH II)///yy,;;;".+DH>>%*TZZ*L#'>>DJJ  +M%r-   returnc                 2   d} | j                   di |}|t        j                  d|       |S t        j                         }t
        }|D ]w  }||v r2| j                  ||      }||t        |       dt        |       z  }9||vs>t        j                  du sQ||   W||   }|t        |       dt        |       z  }y t        j                  d|       t        j                  |      } | j                  |fi |} | j                  dd|i| |S )a
  
        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_paramsr/   _get_hashed_cache_key_add_namespace_to_cache_key_set_preset_cache_key_in_kwargs)	rv   rw   	cache_keyr|   combined_kwargslitellm_param_kwargsparamparam_valuehashed_cache_keys	            r#   get_cache_keyzCache.get_cache_key   sR    	 B4AAKFK'  !CEUV##*BBD1E'-1-B-B5&-Q*CJ<r#k2B1C!DDI11 OOSWWe}, "(-KCJ<r#k2B1C!DDI   	6	B 66yA;4;;<LWPVW,,, 	
-	
17	
  r-   r   rw   c                 d    |dk(  r| j                  |      S |dk(  r| j                  |      S ||   S )z?
        Get the value for the given param from kwargs
        modelfile)_get_model_param_value_get_file_param_value)rv   r   rw   s      r#   r   zCache._get_param_value  s?     G..v66f_--f55e}r-   c                    |j                  di       xs i }|j                  di       xs i }|j                  di       xs i }|j                  d      xs |j                  d      }| j                  ||      }|xs	 |xs |d   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)rv   rw   r   r   metadata_in_litellm_paramsr   caching_groups          r#   r   zCache._get_model_param_value)  s      J39r%zz*:B?E2+9+=+=j"+M+SQS"%-\\&
 &;'++M: 	 //+F>>vg>r-   r   r   c                 \    |j                  dg       }|r|D ]  }||v st        |      c S  y )Ncaching_groups)r   r   )rv   r   r   r   groups        r#   r   zCache._get_caching_group:  s9     *26F)K'%'u:% ( r-   c                     |j                  d      }|j                  di       }|j                  di       }|j                  d      xs3 t        |dd      xs$ |j                  d      xs |j                  d      S )zo
        Handles getting the value for the 'file' param from kwargs. Used for `transcription` requests
        r   r   r   file_checksumnameN	file_name)r   getattr)rv   rw   r   r   r   s        r#   r   zCache._get_file_param_valueD  s{     zz&!::j"-$4b9LL) /tVT*/||K(/ !!+.		
r-   c                 :    |rd|v r|d   j                  dd      S y)a  
        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   )rv   rw   s     r#   r}   z'Cache._get_preset_cache_key_from_kwargsR  s,     6)./334FMMr-   r|   c                 $    |rd|v r	||d   d<   yyy)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,   )rv   r|   rw   s      r#   r   z%Cache._set_preset_cache_key_in_kwargs`  s*     6)?O'();< * r-   r   c                     t        j                  | j                               }|j                         }t	        j
                  d|       |S )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   zCache._get_hashed_cache_keyl  s?     nnY%5%5%78((*=xHr-   r   c                     |j                  di       }|j                  d      xs/ |j                  di       j                  d      xs | j                  }|r| d| }t        j                  d|       |S )a  
        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.
        re   r@   r   redis_namespace:zFinal hashed key: %s)r   r@   r   r   )rv   r   rw   dynamic_cache_controlr@   s        r#   r   z!Cache._add_namespace_to_cache_key  s~     6<ZZ5L!%%k2 zz*b)--.?@~~ 	
 #AhZ0H3X>r-   c              #      K   d}t        dt        |      |      D ]-  }ddd||||z    digi t        j                  t               / y w)N   r   choicesdelta	assistant)rolecontent)rangelentimesleepr   )rv   r   
chunk_sizeis       r#   generate_streaming_contentz Cache.generate_streaming_content  sa     
q#g,
3A$/'.q1z>'B"	 	 JJ34 4s   A
Acached_resultmax_agec                 B   |wt        |t              rgd|v rc|d   }t        j                         }||z
  }|||kD  ry|j                  d      }	 t        |t              r	 |S t	        j
                  |      }	 |S |S # t        $ r t        j                  |      }Y |S w xY w)zL
        Common get cache logic across sync + async implementations
        N	timestampresponse)	ru   dictr   r   jsonloadsr!   astliteral_eval)rv   r   r   r   current_timeresponse_agecached_responses          r#   _get_cache_logiczCache._get_cache_logic  s     %=$/},%k2I99;L ()3L "|g'= ,//
;ODot4 #" '+jj''O
 #"  D"%"2"2?"C""Ds   A< "A< <BBc                    	  | j                   di |dury|j                  dg       }d|v r|d   }n | j                  di |}||j                  di       }|j                  d      xs |j                  d      xs t        d      }| j                  j                  ||	      }| j                  j                  ||	      }| j                  ||
      S y# t        $ r# t        dt        j                                 Y yw xY w)a&  
        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   re   s-maxage	s-max-ageinf)r   r   r   An exception occurred: r,   )should_use_cacher   r   floatre   	get_cacher   r!   r$   	traceback
format_exc)rv   rw   r   r   cache_control_argsr   r   s          r#   r   zCache.get_cache  s&   	$t$$.v.d:zz*b1Hf$";/	.D..88	$:@**Wb:Q"&**:6 $)--k:$U| 
 !%

 4 4Y 4 R $

 4 4Y 4 R,,"/ -   %  	3I4H4H4J3KLM	s   C B?C )DDc           	        K   	  | j                   di |dury|j                  dg        d|v r|d   }n | j                  di |}|u|j                  di       }|j                  d|j                  dt        d                  } | j                  j
                  |fi | d{   }| j                  ||	      S y7 # t        $ r# t        d
t        j                                 Y yw xY ww)zd
        Async get cache implementation.

        Used for embedding calls in async wrapper
        TNr   r   re   r   r   r   r   r   r,   )r   r   r   r   re   async_get_cacher   r!   r$   r   r   )rv   rw   r   r   r   r   s         r#   r   zCache.async_get_cache  s    	$t$$.v.d:JJz2&f$";/	.D..88	$%+ZZ%<",00!3!7!7
E%L!Q 'Adjj&@&@&Uf&U U,,"/ -   %
 !V  	3I4H4H4J3KLM	sE   C0C C0BC &B?'C =C0?C )C-*C0,C--C0c                    	 d|v r|d   }n | j                   di |}|t        |t              r|j                         }| j                  | j                  |d<   |j                  dd      }t        |t              r#|j                         D ]  \  }}|dk(  s||d<    t        j                         |d}|||fS t        d      # t        $ r}|d}~ww xY w)zO
        Common implementation across sync + async add_cache functions
        r   NrA   re   )r   r   zcache key is Noner,   )
r   ru   r
   model_dump_jsonrA   r   r   itemsr   r!   )	rv   resultrw   r   _cache_kwargskvcached_dataes	            r#   _add_cache_logiczCache._add_cache_logic  s    	f$";/	.D..88	$fi0#335F 88'$(HHF5M &

7D 9mT2 - 3 3 51:,-F5M !6 -1IIKVL +v55 344 	G	s$   BC "C <C 	CCCc                 
   	  | j                   di |dury | j                  dd|i|\  }}} | j                  j                  ||fi | y# t        $ r+}t        j                  dt        |              Y d}~yd}~ww xY w)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   re   	set_cacher!   r   	exceptionr   rv   r   rw   r   r   r   s         r#   	add_cachezCache.add_cache)  s    	U$t$$.v.d:-BT-B-B ..!'.*I{F !DJJ  KB6B 	U$$'J3q6(%STT	Us   A 6A 	B!A==Bc                   K   	  | j                   di |dury| j                  dk(  r(| j                   | j                  |fi | d{    y | j                  dd|i|\  }}} | j
                  j                  ||fi | d{    y7 D7 # t        $ r+}t        j                  dt        |              Y d}~yd}~ww xY ww)z3
        Async implementation of add_cache
        TNredisr   r   r,   )r   r;   rU   batch_cache_writer   re   async_set_cacher!   r   r   r   r   s         r#   async_add_cachezCache.async_add_cache>  s     	U$t$$.v.d:yyG#(=(=(I,d,,V>v>>>1F1F1F 2!2%+2.	; 1djj00KR6RRR ? S 	U$$'J3q6(%STT	Ush   C
B C
1B 
BB C
9B 	B
B C
B B 	C!C=C
CC
embedding_responser   c                    	 t        |t              r4|j                  d      |j                  d      |j                  d      |dS t        |d      rD|j	                         }|j                  d      |j                  d      |j                  d      |dS t        |      }|j                  d      |j                  d      |j                  d      |dS # t        $ r}t        d|       d}~ww xY w)zh
        Convert any embedding response into the standardized CachedEmbedding TypedDict format.
        r3   indexobject)r3   r   r   r   
model_dumpz,Missing expected key in embedding response: N)ru   r   r   hasattrr   varsKeyError
ValueError)rv   r   r   datar   s        r#   _convert_to_cached_embeddingz"Cache._convert_to_cached_embeddingQ  s    	Q,d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 	C1C,,C1r   inputidx_in_result_datac                      | j                   di i |d|i}||d<   |j                  |   }|j                  }| j                  ||      } | j                  dd|i|\  }	}
}|	|
|fS )Nr   r   r   r,   )r   r   r   r   r   )rv   r   r   rw   r   r|   r   
model_nameembedding_dictr   r   s              r#   add_embedding_response_to_cachez%Cache.add_embedding_response_to_cacheq  s     .4--K0J60J7E0JK.{#[[);< \\
*.*K*KL^`j*k)>)>)> *
!*
*
&	; +v--r-   c                 Z  K   	  | j                   di |dury| j                  | j                  |d<   g }t        |d   t              rBt	        |d         D ]0  \  }}| j                  ||||      \  }}}|j                  ||f       2 n@t        |d   t              r-| j                  ||d   |      \  }}}|j                  ||f        | j                  j                  dd|i| d{    y7 # t        $ r+}t        j                  dt        |              Y d}~yd}~ww xY ww)z
        Async implementation of add_cache for Embedding calls

        Does a bulk write, to prevent using too many clients
        TNrA   r   
cache_listr   r,   )r   rA   ru   list	enumerater   ro   r   re   async_set_cache_pipeliner!   r   r   )	rv   r   rw   r   idxr   r   r   r   s	            r#   async_add_cache_pipelinezCache.async_add_cache_pipeline  s;     	U$t$$.v.d: xx# $uJ&/40'w8FC
 <<VQPST	!#%%y+&>? 9 F7OS1151U1UF7OV2.	; !!9k":;5$**55VVvVVV  	U$$'J3q6(%STT	UsK   D+C4 D+CC4 ,C2-C4 1D+2C4 4	D(=!D#D+#D((D+c                     | j                   t        j                  k(  ry|j                  dd      }t	        j
                  d||       |r%t        |t              r|j                  dd      du ryy)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
        Tre   Nz(should_use_cache: kwargs: %s; _cache: %sz	use-cacheF)r<   r&   r'   r   r   r   ru   r   )rv   rw   _caches      r#   r   zCache.should_use_cache  sd     99	,,, GT*GQWXj.zz+u-5r-   c                    K    | j                   dd|i|\  }}} | j                  j                  ||fi | d {    y 7 w)Nr   r,   )r   re   r   )rv   r   rw   r   r   s        r#   r   zCache.batch_cache_write  sI     )>)>)>)Wf)WPV)W&	;*djj**9kLVLLLs   :AAAc                 ^   K   t        | j                  d      }|r |        d {   S y 7 w)Npingr   re   )rv   
cache_pings     r#   r
  z
Cache.ping  s,     TZZ0
#%% &s   #-+-c                 `   K   t        | j                  d      }|r ||       d {   S y 7 w)Ndelete_cache_keysr  )rv   keyscache_delete_cache_keyss      r#   r  zCache.delete_cache_keys  s1     ")$**6I"J"0666 7s   $.,.c                    K   t        | j                  d      r#| j                  j                          d {    y y 7 w)N
disconnect)r   re   r  rv   s    r#   r  zCache.disconnect  s2     4::|,**''))) -)s   4?=?c                 X    | j                   r| j                   t        j                  k(  ryy)z
        Internal method to check if the cache type supports async get/set operations

        Only S3 Cache Does NOT support async operations

        FT)r;   rf   rk   r  s    r#   _supports_asynczCache._supports_async  s#     99&6&9&99r-   )r   )/r)   r*   r+   rf   rj   r&   r'   r   r   r   r   CachingSupportedCallTypesboolr	   r   intrx   r   r   r   r   r   r   r}   r   staticmethodr   r   r   r   r   r   r   r   r   CachedEmbeddingr   r   r   r   r  r   r   r
  r  r  r  r,   r-   r#   r/   r/   6   se    ,<+A+A   """&#'#150404K
 ,0.2(,(,(,%)04)-.226.2#'!%4L9=*..2(,)-(,04485Mcv2'(v2 
v2 smv2 smv2 3-v2 C=v2 e_v2  (v2 'uov2 'uov2 't,E'FGv26 $C=7v28 'sm9v2: !;v2< !=v2> !?v2@ TNAv2B E$),-Cv2D "#Ev2F 'smGv2H #+3-Iv2J 'smKv2L C=Mv2N #Ov2P /2Qv2R *2#Sv2T #3-Uv2V &d^Wv2X !Yv2Z "#[v2\ !]v2^ !)_v2` %-SMav2b 03cv2p*  * X  
#	?T ?c ?"+3C=	#
D 
S 
Xc] 
P 
PRV 
P    $C c ,5%}% %%N!F:<U*U&Qs Q8TW= Q]l QJ #$.!. . 	.
  . 
sD$	.*&UP$M*	 	r-   r/   r0   r;   r=   r>   r?   rE   c           	         t        d       dt        j                  vrt        j                  j                  d       dt        j                  vrt        j
                  j                  d       dt        j                  vrt        j
                  j                  d       t        j                  t        d| ||||d|t        _	        t        dt        j                          t        dt        t        j                                y)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 Cachere   Nr;   r=   r>   r?   rE   z&LiteLLM: Cache enabled, litellm.cache=LiteLLM Cache: r,   )r$   r   rn   ro   rp   rq   rr   rs   rt   re   r/   r   r;   r=   r>   r?   rE   rw   s         r#   enable_cacher    s    J +,g,,,%%g.g...((EEgNg555((KKGT}} 
!5
 
 :7==/JKOD$7#89:r-   c           	          t        d       t        d| ||||d|t        _        t        dt        j                          t        dt	        t        j                                y)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 Cacher  z&LiteLLM: Cache Updated, litellm.cache=r  Nr,   )r$   r/   r   re   r   r  s         r#   update_cacher!    sg    F +, 1 GM :7==/JKOD$7#89:r-   c                  p   ddl m}  t        d        | t              5  t        j
                  j                  d       t        j                  j                  d       t        j                  j                  d       ddd       dt        _	        t        dt        j                          y# 1 sw Y   1xY w)aF  
    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 Cachere   Nz'LiteLLM: Cache disabled, litellm.cache=)

contextlibr$  r$   r   r   rn   removerp   rs   re   r#  s    r#   disable_cacher'  J  s     $,-	*	 8%%g.  ''0''..w78
 GM;GMM?KL8 8s   AB,,B5)9r   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   in_memory_cacher   qdrant_semantic_cacher   redis_cacher   redis_cluster_cacher   redis_semantic_cacher   s3_cacher   r$   r   r&   r/   rf   rj   r  r  r!  r'  r,   r-   r#   <module>r:     sN         : :   + : J # E , ! ! ! * 6 # 2 4  T  g
 g
V (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r-   