From 975ab97c4401cf1011c9216a47938bd554fb4b36 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 16 Dec 2023 14:44:39 +0530 Subject: [PATCH] (feat) proxy - set cache configs on proxy --- litellm/proxy/proxy_server.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 4bc08f2cc6..d92280df3a 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -486,6 +486,18 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str): cache_port = litellm.get_secret("REDIS_PORT", None) cache_password = litellm.get_secret("REDIS_PASSWORD", None) + cache_params = { + "type": cache_type, + "host": cache_host, + "port": cache_port, + "password": cache_password + } + + if "cache_params" in litellm_settings: + cache_params_in_config = litellm_settings["cache_params"] + # overwrie cache_params with cache_params_in_config + cache_params.update(cache_params_in_config) + # Assuming cache_type, cache_host, cache_port, and cache_password are strings print(f"{blue_color_code}Cache Type:{reset_color_code} {cache_type}") print(f"{blue_color_code}Cache Host:{reset_color_code} {cache_host}") @@ -495,10 +507,7 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str): ## to pass a complete url, or set ssl=True, etc. just set it as `os.environ[REDIS_URL] = `, _redis.py checks for REDIS specific environment variables litellm.cache = Cache( - type=cache_type, - host=cache_host, - port=cache_port, - password=cache_password + **cache_params ) print(f"{blue_color_code}Set Cache on LiteLLM Proxy: {litellm.cache.cache}{reset_color_code} {cache_password}") elif key == "callbacks": @@ -535,6 +544,10 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str): else: litellm.failure_callback.append(callback) print_verbose(f"{blue_color_code} Initialized Success Callbacks - {litellm.failure_callback} {reset_color_code}") + elif key == "cache_params": + # this is set in the cache branch + # see usage here: https://docs.litellm.ai/docs/proxy/caching + pass else: setattr(litellm, key, value)