
    AHj                     .   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
dl/m0Z0 d Z1 G d de2e      Z3 G d d      Z4e5jl                  dddg dfdee5   dee2   dee2   dee2   d ee
e7      f
d!Z8e5jl                  dddg dfdee5   dee2   dee2   dee2   d ee
e7      f
d"Z9d# Z:y)$    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                     	 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    O/root/tools/cai/cai_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(   1   s    JKr/   r(   c            R          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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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d*ee   d+ee   d,ee   fPd-Zd.efd/Zd0ed1ed.ee   fd2Zd1ed.efd3Zd4ed5ee   d.ee   fd6Zd1ed.efd7Zd.ee   fd8Zd9ed.dfd:Zed;ed.efd<       Zd=ed.efd>Zd? Zd@ee   dAee	   fdBZdWdCee   fdDZ	 dWdCee   fdEZ dF Z!dG Z"	 dWdCee   fdHZ#dIedJee   d.e$fdKZ%	 dXdLe&dMed1edNed.e'eeef   f
dOZ(	 dWdCee   fdPZ)dQ Z*dR Z+dS Z,dT Z-dU Z.d.efdVZ/y)YCacheN
completionacompletion	embedding
aembeddingatranscriptiontranscriptionatext_completiontext_completionarerankrerank	responses
aresponsesTz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!qdrant_semantic_cache_vector_sizegcp_service_accountgcp_ssl_ca_certsc)                 V   |t         j                  k(  r|s<t        j                  d      }*|*%t	        |*t
              rt        j                  |*      }|r*|||||d|)}+|'|'|+d<   |(|(|+d<   t        di |+| _	        n1t        d||||d|)| _	        n|t         j                  k(  rt        d||||
||d|)| _	        n|t         j                  k(  rt        |!|"|#|
|$|%|&      | _	        n|t         j                  k(  rt!               | _	        n|t         j"                  k(  rt%        d|||||||||||d	|)| _	        nq|t         j&                  k(  rt)        |||
      | _	        nJ|t         j*                  k(  rt-        ||      | _	        n$|t         j.                  k(  rt1        |       | _	        dt        j2                  vrt        j2                  j5                  d       dt        j6                  vrt        j8                  j;                  d       dt        j<                  vrt        j8                  j?                  d       || _         || _!        || _"        || _#        || _$        |xs tJ        jL                  | _'        | jB                  t         j                  k(  r	||| _$        | jB                  t         j                  k(  s| jB                  t         j                  k(  r	|	|	| _$        | jD                  7t	        | j                  t              r| jD                  | 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.

            # 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
        REDIS_CLUSTER_NODESN)rA   rB   rC   r\   startup_nodesre   rf   )rA   rB   rC   r\   )rA   rB   rC   rH   embedding_model
index_name)r_   r`   collection_namerH   quantization_configrj   vector_size)rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   )bucket_namepath_service_accountrY   )account_url	container)r^   cacher.   )(LiteLLMCacheTypeREDISr    
get_secret
isinstancestrjsonloadsr   rs   r   REDIS_SEMANTICr   QDRANT_SEMANTICr   LOCALr   S3r   GCSr   
AZURE_BLOBr   DISKr   input_callbackappendsuccess_callbacklogging_callback_manageradd_litellm_success_callback_async_success_callback"add_litellm_async_success_callbackrI   r?   rD   r\   rE   r(   r)   r@   ),selfr?   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\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   kwargs_env_cluster_nodescluster_kwargss,                                               r%   __init__zCache.__init__8   s*   ` #)))&%,%7%78M%N"%1j&7 +/**5G*H'" !  ((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,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_valuerx   r    3enable_caching_on_provider_specific_optional_paramsr1   _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_keyzCache.get_cache_key  sY    	 B4AAKFK'  !CEUV##*BBD1 	EE'-1-B-B5&-Q*CJ<r#k2B1C!DDI11 OOSWWe}, "(-KCJ<r#k2B1C!DDI	E  	6	B 66yA;4;;<LWPVW,,, 	
-	
17	
  r/   r   r   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)r   r   r   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)r   r   r   r   metadata_in_litellm_paramsr   caching_groups          r%   r   zCache._get_model_param_valueN  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   rx   )r   r   r   r   groups        r%   r   zCache._get_caching_group_  s>     *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)r   r   r   r   r   s        r%   r   zCache._get_file_param_valuei  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   )r   r   s     r%   r   z'Cache._get_preset_cache_key_from_kwargsw  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.   )r   r   r   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_key  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.
        rs   rD   r   redis_namespace:zFinal hashed key: %s)r   rD   r   r   )r   r   r   dynamic_cache_controlrD   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   )r   r   
chunk_sizeis       r%   generate_streaming_contentz Cache.generate_streaming_content  sf     
q#g,
3 	5A$/'.q1z>'B"	 	 JJ34	5s   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)	rw   dictr   r   ry   rz   r#   astliteral_eval)r   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dynamic_cache_objectc                     	  | 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	                  ||	      }n| 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   rs   s-maxage	s-max-ageinf)r   r   r   An exception occurred: r.   )should_use_cacher   r   float	get_cachers   r   r#   r&   	traceback
format_exc)r   r   r   r   r   cache_control_argsr   r   s           r%   r   zCache.get_cache  s0   	$t$$.v.d:zz*b1Hf$";/	.D..88	$:@**Wb:Q"&**:6 $)--k:$U| 
 (3$8$B$B!H %C %M %)JJ$8$8X$8$VM,,"/ -   %   	3I4H4H4J3KLM	s   C B8C )C=<C=c           	      $  K   	  | j                   di |dury|j                  dg        d|v r|d   }n | j                  di |}||j                  di       }|j                  d|j                  dt        d                  }| |j                  |fi | d{   }n% | j
                  j                  |fi | d{   }| j                  ||	      S y7 >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   rs   r   r   r   r   r   r.   )r   r   r   r   async_get_cachers   r   r#   r&   r   r   )r   r   r   r   r   r   r   s          r%   r   zCache.async_get_cache  sI    	$t$$.v.d:JJz2&f$";/	.D..88	$%+ZZ%<",00!3!7!7
E%L!Q (3*N*>*N*N!+%++ %M +E$***D*D!+%++ %M ,,"/ -   %%%  	3I4H4H4J3KLM	sW   DC! DBC! C%C! CC! DC! C! !)D
DDD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   NrE   rs   )r   r   zcache key is Noner.   )
r   rw   r
   model_dump_jsonrE   r   r   itemsr   r#   )	r   resultr   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. -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   rs   	set_cacher#   r   	exceptionrx   )r   r   r   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
                  ||fi | d{    y | j                  j
                  ||fi | d{    y7 c7 .7 	# 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?   r\   batch_cache_writer   async_set_cachers   r#   r   r   rx   )r   r   r   r   r   r   r   s          r%   async_add_cachezCache.async_add_cachep  s    	U$t$$.v.d:yyG#(=(=(I,d,,V>v>>>1F1F1F 2!2%+2.	; (3>.>>!;28   5$**44YVvVVV ? W 	U$$'J3q6(%STT	Us   C+B4 C+1B4 
B.B4 C+1B4 B0B4 C+!B4 (B2)B4 -C+.B4 0B4 2B4 4	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.
        r5   indexobject)r5   r  r  r   
model_dumpz,Missing expected key in embedding response: N)rw   r   r   hasattrr  varsKeyError
ValueError)r   r   r   datar   s        r%   _convert_to_cached_embeddingz"Cache._convert_to_cached_embedding  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   )r   r   r  r   r  r   r   
model_nameembedding_dictr   r   s              r%   add_embedding_response_to_cachez%Cache.add_embedding_response_to_cache  s     .4--K0J60J7E0JK.{#[[);< \\
*.*K*K
+
 *?)>)> *
!*
*
&	; +v--r/   c                   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                  dd|i| d{    y | j                  j                  dd|i| d{    y7 ,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
        TNrE   r  
cache_listr   r.   )r   rE   rw   list	enumerater  r   rx   async_set_cache_pipeliners   r#   r   r   )
r   r   r   r   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8 @FC
 <<VQPST	!#%%y+&>?@ F7OS1151U1UF7OV2.	; !!9k":;#/C*CC )-3   :djj99 )-3  	  	U$$'J3q6(%STT	Usi   ED ECD $D%D )E*!D DD ED D 	E	!E?EE		E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
        Trs   Nz(should_use_cache: kwargs: %s; _cache: %sz	use-cacheF)r@   r(   r)   r   r   r   rw   r   )r   r   _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   rs   r   )r   r   r   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   rs   )r   
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  )r   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  rs   r$  r   s    r%   r$  zCache.disconnect  s2     4::|,**''))) -)s   4?=?c                      y)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_asynczCache._supports_async  s     r/   r   )r   )0r+   r,   r-   rt   r}   r(   r)   r   rx   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  r   r$  r'  r.   r/   r%   r1   r1   7   s+    ,<+A+A   """&#'#150404K
 ,0.2(,(,(,%)04)-.226.2#'!%)-26"&4L9=*..2(,)-(,04485M;?-1*.uZ2'(Z2 
Z2 smZ2 smZ2 3-Z2 C=Z2 e_Z2  (Z2 'uoZ2 'uoZ2 't,E'FGZ2: $C=;Z2< 'sm=Z2> !?Z2@ !AZ2B !CZ2D TNEZ2F E$),-GZ2H "#IZ2J 'smKZ2L #+3-MZ2N 'smOZ2P C=QZ2R #SZ2T "#UZ2V #+3-WZ2X 3-YZ2Z /2[Z2\ *2#]Z2^ #3-_Z2` &d^aZ2b !cZ2d "#eZ2f !gZ2h !)iZ2j %-SMkZ2l 03mZ2n ,4C=oZ2r &c]sZ2t #3-uZ2x*  * 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* r/   r1   r2   r?   rA   rB   rC   rI   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 Cachers   Nr?   rA   rB   rC   rI   z&LiteLLM: Cache enabled, litellm.cache=LiteLLM Cache: r.   )r&   r    r   r   r   r   r   r   r   rs   r1   r  r?   rA   rB   rC   rI   r   s         r%   enable_cacher1    s    N +,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&   r1   r    rs   r  r0  s         r%   update_cacher3  W  sg    J +, 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 Cachers   Nz'LiteLLM: Cache disabled, litellm.cache=)

contextlibr6  r&   r  r    r   remover   r   rs   r5  s    r%   disable_cacher9    s     $,-	*	 8%%g.  ''0''..w78
 GM;GMM?KL8 8s   AB,,B5);r   r   ry   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&   rx   r(   r1   rt   r}   r(  r1  r3  r9  r.   r/   r%   <module>rM     sQ         : :   + : J # E , ! ! !  * 6 # 2 4  T  a aJ (8'='="G9;
#
$9;
3-9; 3-9; sm	9;
 #4(A#BC9;z (8'='="G/;
#
$/;
3-/; 3-/; sm	/;
 #4(A#BC/;dMr/   