
    g                     :   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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Zd d
lmZ d dl 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l0m1Z1 d Z2 G d de3e      Z4 G d d      Z5e6jn                  dddg dfdee6   dee3   dee3   d ee3   d!ee
e8      f
d"Z9e6jn                  dddg dfdee6   dee3   dee3   d ee3   d!ee
e8      f
d#Z:d$ Z;y)%    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                     	 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    L/var/www/openai/venv/lib/python3.12/site-packages/litellm/caching/caching.pyprint_verboser$   0   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&   9   s    JKr-   r&   c            :       J   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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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e   d ee   d!ee   f8d"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d+Zd&ed#efd,Zd#ee   fd-Zd.ed#dfd/Zd#ee   fd0Zd#ee   fd1Zd#ee   fd2Zd#ee   fd3Zd#ee   fd4Zd#ee   fd5Zd#ee   fd6Z e!d7ed#efd8       Z"d9ed#efd:Z#d; Z$d<ee   d=ee	   fd>Z%d? Z&d@ Z'dA Z(dB Z)dC Z*dD Z+dE Z,dF Z-dG Z.dH Z/dI Z0d#efdJZ1y)KCacheN

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!                    |t         j                  k(  rt        d|||||d|!| _        n|t         j                  k(  rt        d||||
||d|!| _        n|t         j                  k(  rt        ||||
||       | _        nw|t         j                  k(  rt               | _        nT|t         j                  k(  rt        d|||||||||||d|!| _        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$                  j!                  d       || _        || _        || _        || _        || _        |xs t0        j2                  | _        | j(                  t         j                  k(  r	||| _        | j(                  t         j                  k(  s| j(                  t         j                  k(  r	|	|	| _        | j*                  7t7        | j                  t              r| j*                  | 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?   rQ   startup_nodes)r=   r>   r?   rD   	use_asyncembedding_model)rS   rT   collection_namerD   quantization_configrZ   )rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   )disk_cache_dircacheNr,   )LiteLLMCacheTypeREDISr   r^   REDIS_SEMANTICr   QDRANT_SEMANTICr   LOCALr   S3r   DISKr   r   input_callbackappendsuccess_callback_async_success_callbackrE   r;   r@   rQ   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   redis_semantic_cache_use_async$redis_semantic_cache_embedding_modelrQ   rR   r]   rS   rT   rU   rV   %qdrant_semantic_cache_embedding_modelkwargss"                                     r#   __init__zCache.__init__@   sO   @ #)))$. %!!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,DH II)///yy,;;;".+DH>>%*TZZ*L#'>>DJJ  +M%r-   returnc                 *   d} | j                   di |}|t        j                  d|       |S | 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   '_get_relevant_args_to_use_for_cache_keyr   _get_param_valuestrr   3enable_caching_on_provider_specific_optional_paramsr/   _get_hashed_cache_key!_add_redis_namespace_to_cache_key_set_preset_cache_key_in_kwargs)	rk   ro   	cache_keyrt   combined_kwargslitellm_param_kwargsparamparam_valuehashed_cache_keys	            r#   get_cache_keyzCache.get_cache_key   sX    	 B4AAKFK'  !CEUV##FFH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A4AA
 &
 	-,, 	
-	
17	
  r-   r   ro   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)rk   r   ro   s      r#   rw   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)rk   ro   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   rx   )rk   r   r   r   groups        r#   r   zCache._get_caching_group5  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)rk   ro   r   r   r   s        r#   r   zCache._get_file_param_value?  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   rt   N)r   )rk   ro   s     r#   ru   z'Cache._get_preset_cache_key_from_kwargsM  s,     6)./334FMMr-   rt   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   rt   Nr,   )rk   rt   ro   s      r#   r|   z%Cache._set_preset_cache_key_in_kwargs[  s*     6)?O'();< * r-   c                    | j                         }| j                         }| j                         }| j                         }| j	                         }| j                         }|j                  ||||      }|j                  |      }|S )zP
        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)rk   chat_completion_kwargstext_completion_kwargsembedding_kwargstranscription_kwargsrerank_kwargsexclude_kwargsr~   s           r#   rv   z-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r-   c                     t        t        j                  j                               j	                  t        t
        j                  j                                     }|S )zl
        Get the litellm supported chat completion kwargs

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

%3CCHHJK
L 	# *)r-   c                     t        t        j                  j                               j	                  t        t
        j                  j                                     }|S )zl
        Get the litellm supported text completion kwargs

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

%7GGLLNO
P 	# *)r-   c                 P    t        t        j                  j                               S )z9
        Get the litellm supported rerank kwargs
        )r   r   model_fieldsr   rk   s    r#   r   z*Cache._get_litellm_supported_rerank_kwargs  s     =--22455r-   c                 P    t        t        j                  j                               S )zf
        Get the litellm supported embedding kwargs

        This follows the OpenAI API Spec
        )r   r   r   r   r   s    r#   r   z-Cache._get_litellm_supported_embedding_kwargs  s     (88==?@@r-   c                 P    t        t        j                  j                               S )zj
        Get the litellm supported transcription kwargs

        This follows the OpenAI API Spec
        )r   r
   r   r   r   s    r#   r   z1Cache._get_litellm_supported_transcription_kwargs  s     ,<<AACDDr-   c                     t        dg      S )z>
        Get the kwargs to exclude from the cache key
        r   )r   r   s    r#   r   z+Cache._get_kwargs_to_exclude_from_cache_key  s     J<  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#   rz   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                  }|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.
        r   redis_namespace:zFinal hashed key: %s)r   r@   r   r   )rk   r   ro   r@   s       r#   r{   z'Cache._add_redis_namespace_to_cache_key  sR     JJz2.223DEW	#AhZ0H3X>r-   c              #      K   d}t        dt        |      |      D ])  }ddd||||z    digi t        j                  d       + y w)N   r   choicesdelta	assistant)rolecontentg{Gz?)rangelentimesleep)rk   r   
chunk_sizeis       r#   generate_streaming_contentz Cache.generate_streaming_content  s`     
q#g,
3A$/'.q1z>'B"	 	 JJt 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)	rj   dictr   r   jsonloadsr!   astliteral_eval)rk   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 |}|m|j                  di       }|j                  d|j                  dt        d                  }| 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}   r^   	s-max-ages-maxageinf)r   r   r   An exception occurred: r,   )should_use_cacher   r   floatr^   	get_cacher   r!   r$   	traceback
format_exc)rk   ro   r   r}   cache_control_argsr   r   s          r#   r   zCache.get_cache  s   	$t$$.v.d:zz*b1Hf$";/	.D..88	$%+ZZ%<",00!3!7!7
E%L!Q !%

 4 4Y 4 R,,"/ -   %  	3I4H4H4J3KLM	s   B5 BB5 5)C! C!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}   r^   r   r   r   r   r   r,   )r   r   r   r   r^   async_get_cacher   r!   r$   r   r   )rk   ro   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   r^   )r   r   zcache key is Noner,   )
r   rj   r   model_dump_jsonrA   r   r   itemsr   r!   )	rk   resultro   r}   _cache_kwargskvcached_dataes	            r#   _add_cache_logiczCache._add_cache_logicD  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   r^   	set_cacher!   r   	exceptionrx   rk   r   ro   r}   r   r   s         r#   	add_cachezCache.add_cacheb  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;   rQ   batch_cache_writer   r^   async_set_cacher!   r   r   rx   r   s         r#   async_add_cachezCache.async_add_cachew  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
c                 
  K   	  | j                   d	i |dury| j                  | j                  |d<   g }t        |d         D ]\  \  }} | j                  d	i i |d|i}||d<   |j                  |   } | j
                  d	d|i|\  }}	}|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   inputr}   r   
cache_listr   r,   )r   rA   	enumerater   datar   rg   r^   async_set_cache_pipeliner!   r   r   rx   )rk   r   ro   r  idxr   rt   embedding_responser}   r   r   s              r#   async_add_cache_pipelinezCache.async_add_cache_pipeline  s*    	U$t$$.v.d: xx# $uJ#F7O4Q#54#5#5#O8N68N7A8N#O &6{#%+[[%5"1F1F1F 2-22.	; !!9k":; 5 6$**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;6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
        Tr^   Nz(should_use_cache: kwargs: %s; _cache: %sz	use-cacheF)r<   r&   r'   r   r   r   rj   r   )rk   ro   _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   r^   r   )rk   r   ro   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   r^   )rk   
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  )rk   r   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)hasattrr^   r  r   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;   r_   rd   r   s    r#   _supports_asynczCache._supports_async  s#     99&6&9&99r-   )2r)   r*   r+   r_   rc   r&   r'   r   rx   r   r   CachingSupportedCallTypesboolr	   r   intrp   r   r   rw   r   r   r   ru   r|   r   rv   r   r   r   r   r   r   staticmethodrz   r{   r   r   r   r   r   r   r  r  r   r   r  r  r  r  r,   r-   r#   r/   r/   ?   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*	 	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 Cacher^   Nr;   r=   r>   r?   rE   z&LiteLLM: Cache enabled, litellm.cache=LiteLLM Cache: r,   )	r$   r   rf   rg   rh   ri   r^   r/   varsr;   r=   r>   r?   rE   ro   s         r#   enable_cacher$    s    J +,g,,,%%g.g...  ''0g555''..w7}} 
!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   r^   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 Cacher^   Nz'LiteLLM: Cache disabled, litellm.cache=)

contextlibr)  r$   
ValueErrorr   rf   removerh   ri   r^   r(  s    r#   disable_cacher-  J  s     $,-	*	%%g.  ''0''..w7 

 GM;GMM?KL 
	s   AB,,B5)<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$   rx   r&   r/   r_   rc   r  r$  r&  r-  r,   r-   r#   <module>rA     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r-   