From b7cd4cef07b789a1bf59c1a922aae775f5d6614c Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 4 Apr 2025 21:32:55 -0700 Subject: [PATCH] test_get_exception_class_name --- .../test_prometheus_unit_tests.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/logging_callback_tests/test_prometheus_unit_tests.py b/tests/logging_callback_tests/test_prometheus_unit_tests.py index c24bb276910..ddfce710d7e 100644 --- a/tests/logging_callback_tests/test_prometheus_unit_tests.py +++ b/tests/logging_callback_tests/test_prometheus_unit_tests.py @@ -1500,3 +1500,33 @@ def test_set_team_budget_metrics_with_custom_labels(prometheus_logger, monkeypat "metadata_organization": None, "metadata_environment": None, } + + +def test_get_exception_class_name(prometheus_logger): + """ + Test that _get_exception_class_name correctly formats the exception class name + """ + # Test case 1: Exception with llm_provider + rate_limit_error = litellm.RateLimitError( + message="Rate limit exceeded", + llm_provider="openai", + model="gpt-3.5-turbo" + ) + assert prometheus_logger._get_exception_class_name(rate_limit_error) == "Openai.RateLimitError" + + # Test case 2: Exception with empty llm_provider + auth_error = litellm.AuthenticationError( + message="Invalid API key", + llm_provider="", + model="gpt-4" + ) + assert prometheus_logger._get_exception_class_name(auth_error) == "AuthenticationError" + + # Test case 3: Exception with None llm_provider + context_window_error = litellm.ContextWindowExceededError( + message="Context length exceeded", + llm_provider=None, + model="gpt-4" + ) + assert prometheus_logger._get_exception_class_name(context_window_error) == "ContextWindowExceededError" +