From acd8facf9899014a76d5cb053176bb3e33cb0162 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 26 Sep 2024 10:22:14 -0700 Subject: [PATCH] fix(litellm_logging.py): don't initialize prometheus_logger if non premium user Prevents bad error messages in logs Fixes https://github.com/BerriAI/litellm/issues/5897 --- litellm/litellm_core_utils/litellm_logging.py | 22 +++++++++++++------ ...odel_prices_and_context_window_backup.json | 11 ++++++++++ litellm/proxy/utils.py | 5 +++++ litellm/utils.py | 4 ++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 1219feac9e6..23761048bf3 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -31,6 +31,7 @@ from litellm.litellm_core_utils.redact_messages import ( redact_message_input_output_from_custom_logger, redact_message_input_output_from_logging, ) +from litellm.proxy._types import CommonProxyErrors from litellm.rerank_api.types import RerankResponse from litellm.types.llms.openai import HttpxBinaryResponseContent from litellm.types.router import SPECIAL_MODEL_INFO_PARAMS @@ -2140,7 +2141,8 @@ def _init_custom_logger_compatible_class( llm_router: Optional[ Any ], # expect litellm.Router, but typing errors due to circular import -) -> CustomLogger: + premium_user: bool = False, +) -> Optional[CustomLogger]: if logging_integration == "lago": for callback in _in_memory_loggers: if isinstance(callback, LagoLogger): @@ -2174,13 +2176,19 @@ def _init_custom_logger_compatible_class( _in_memory_loggers.append(_langsmith_logger) return _langsmith_logger # type: ignore elif logging_integration == "prometheus": - for callback in _in_memory_loggers: - if isinstance(callback, PrometheusLogger): - return callback # type: ignore + if premium_user: + for callback in _in_memory_loggers: + if isinstance(callback, PrometheusLogger): + return callback # type: ignore - _prometheus_logger = PrometheusLogger() - _in_memory_loggers.append(_prometheus_logger) - return _prometheus_logger # type: ignore + _prometheus_logger = PrometheusLogger() + _in_memory_loggers.append(_prometheus_logger) + return _prometheus_logger # type: ignore + else: + verbose_logger.warning( + f"🚨🚨🚨 Prometheus Metrics is on LiteLLM Enterprise\n🚨 {CommonProxyErrors.not_premium_user.value}" + ) + return None elif logging_integration == "datadog": for callback in _in_memory_loggers: if isinstance(callback, DataDogLogger): diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 0cd996289fa..e801788ad35 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -2434,6 +2434,17 @@ "mode": "chat", "source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#partner-models" }, + "vertex_ai/meta/llama-3.2-90b-vision-instruct-maas": { + "max_tokens": 8192, + "max_input_tokens": 128000, + "max_output_tokens": 8192, + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.0, + "litellm_provider": "vertex_ai-llama_models", + "mode": "chat", + "supports_system_messages": true, + "source": "https://console.cloud.google.com/vertex-ai/publishers/meta/model-garden/llama-3.2-90b-vision-instruct-maas" + }, "vertex_ai/mistral-large@latest": { "max_tokens": 8191, "max_input_tokens": 128000, diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 80eea79fbc7..4dbacc0f4e3 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -296,6 +296,7 @@ class ProxyLogging: def __init__( self, user_api_key_cache: DualCache, + premium_user: bool = False, ): ## INITIALIZE LITELLM CALLBACKS ## self.call_details: dict = {} @@ -318,6 +319,7 @@ class ProxyLogging: alert_types=self.alert_types, internal_usage_cache=self.internal_usage_cache.dual_cache, ) + self.premium_user = premium_user def update_values( self, @@ -378,7 +380,10 @@ class ProxyLogging: callback, internal_usage_cache=self.internal_usage_cache.dual_cache, llm_router=llm_router, + premium_user=self.premium_user, ) + if callback is None: + continue if callback not in litellm.input_callback: litellm.input_callback.append(callback) # type: ignore if callback not in litellm.success_callback: diff --git a/litellm/utils.py b/litellm/utils.py index 1c9d7bde7cd..a63c25393ac 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -367,7 +367,7 @@ def function_setup( callback = litellm.litellm_core_utils.litellm_logging._init_custom_logger_compatible_class( # type: ignore callback, internal_usage_cache=None, llm_router=None ) - if any( + if callback is None or any( isinstance(cb, type(callback)) for cb in litellm._async_success_callback ): # don't double add a callback @@ -431,7 +431,7 @@ def function_setup( ) # don't double add a callback - if not any( + if callback_class is not None and not any( isinstance(cb, type(callback_class)) for cb in litellm.callbacks ): litellm.callbacks.append(callback_class) # type: ignore