From 2d5543c50201eb57d00dd8c8fef930d053f262b0 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 4 Nov 2024 15:44:37 +0530 Subject: [PATCH] perf(proxy_server.py): remove db logic from _get_config_from_file was causing db calls to occur on every llm request, if team_id was set on key --- litellm/proxy/litellm_pre_call_utils.py | 4 +-- litellm/proxy/proxy_server.py | 39 ++----------------------- litellm/proxy/utils.py | 1 + 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index c7640560475..789e79f375f 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -299,8 +299,6 @@ async def add_litellm_data_to_request( # noqa: PLR0915 """ from litellm.proxy.proxy_server import llm_router, premium_user - start_time = time.time() - safe_add_api_version_from_query_params(data, request) _headers = clean_headers( @@ -479,7 +477,7 @@ async def add_litellm_data_to_request( # noqa: PLR0915 ### END-USER SPECIFIC PARAMS ### if user_api_key_dict.allowed_model_region is not None: data["allowed_model_region"] = user_api_key_dict.allowed_model_region - + start_time = time.time() ## [Enterprise Only] # Add User-IP Address requester_ip_address = "" diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index ca6befef603..3176c34e2ee 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1373,9 +1373,6 @@ class ProxyConfig: ) -> dict: """ Given a config file path, load the config from the file. - - If `store_model_in_db` is True, then read the DB and update the config with the DB values. - Args: config_file_path (str): path to the config file Returns: @@ -1401,40 +1398,6 @@ class ProxyConfig: "litellm_settings": {}, } - ## DB - if prisma_client is not None and ( - general_settings.get("store_model_in_db", False) is True - or store_model_in_db is True - ): - _tasks = [] - keys = [ - "general_settings", - "router_settings", - "litellm_settings", - "environment_variables", - ] - for k in keys: - response = prisma_client.get_generic_data( - key="param_name", value=k, table_name="config" - ) - _tasks.append(response) - - responses = await asyncio.gather(*_tasks) - for response in responses: - if response is not None: - param_name = getattr(response, "param_name", None) - param_value = getattr(response, "param_value", None) - if param_name is not None and param_value is not None: - # check if param_name is already in the config - if param_name in config: - if isinstance(config[param_name], dict): - config[param_name].update(param_value) - else: - config[param_name] = param_value - else: - # if it's not in the config - then add it - config[param_name] = param_value - return config async def save_config(self, new_config: dict): @@ -1500,8 +1463,10 @@ class ProxyConfig: - for a given team id - return the relevant completion() call params """ + # load existing config config = await self.get_config() + ## LITELLM MODULE SETTINGS (e.g. litellm.drop_params=True,..) litellm_settings = config.get("litellm_settings", {}) all_teams_config = litellm_settings.get("default_team_settings", None) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 82831b3b269..44243cab0b9 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -1400,6 +1400,7 @@ class PrismaClient: return + @log_to_opentelemetry @backoff.on_exception( backoff.expo, Exception, # base exception to catch for the backoff