Merge pull request #4642 from BerriAI/litellm_safe_access_slack

[fix] slack alerting reports - add validation for safe access into attributes
This commit is contained in:
Ishaan Jaff 2024-07-10 16:46:08 -07:00 committed by GitHub
commit 0cb4dabaf0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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