From e20b540dac8547b73815aca2dec825df550943c2 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 10 Jul 2024 10:10:32 -0700 Subject: [PATCH] add validation on slack --- litellm/integrations/slack_alerting.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index 04195705a06..437e8ce135f 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -1538,7 +1538,11 @@ Model Info: final_value = response_s total_tokens = 0 - if isinstance(response_obj, litellm.ModelResponse): + if isinstance(response_obj, litellm.ModelResponse) and ( + hasattr(response_obj, "usage") + and response_obj.usage is not None + and hasattr(response_obj.usage, "completion_tokens") + ): completion_tokens = response_obj.usage.completion_tokens if completion_tokens is not None and completion_tokens > 0: final_value = float( @@ -1557,8 +1561,7 @@ Model Info: ) except Exception as e: verbose_proxy_logger.error( - "[Non-Blocking Error] Slack Alerting: Got error in logging LLM deployment latency: ", - e, + f"[Non-Blocking Error] Slack Alerting: Got error in logging LLM deployment latency: {str(e)}" ) pass