mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
* define basic types * fix verbose_logger.exception statement * fix basic alerting * test pager duty alerting * test_pagerduty_alerting_high_failure_rate * PagerDutyAlerting * async_log_failure_event * use pre_call_hook * add _request_is_completed helper util * update AlertingConfig * rename PagerDutyInternalEvent * _send_alert_if_thresholds_crossed * use pagerduty as _custom_logger_compatible_callbacks_literal * fix slack alerting imports * fix imports in slack alerting * PagerDutyAlerting * fix _load_alerting_settings * test_pagerduty_hanging_request_alerting * working pager duty alerting * fix linting * doc pager duty alerting * update hanging_response_handler * fix import location * update failure_threshold * update async_pre_call_hook * docs pagerduty * test - callback_class_str_to_classType * fix linting errors * fix linting + testing error * PagerDutyAlerting * test_pagerduty_hanging_request_alerting * fix unused imports * docs pager duty * @pytest.mark.flaky(retries=6, delay=2) * test_model_info_bedrock_converse_enforcement
96 lines
2.5 KiB
Python
96 lines
2.5 KiB
Python
import asyncio
|
|
import os
|
|
import random
|
|
import sys
|
|
from datetime import datetime, timedelta
|
|
from typing import Optional
|
|
|
|
sys.path.insert(0, os.path.abspath("../.."))
|
|
import pytest
|
|
import litellm
|
|
from litellm.integrations.pagerduty.pagerduty import PagerDutyAlerting, AlertingConfig
|
|
from litellm.proxy._types import UserAPIKeyAuth
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pagerduty_alerting():
|
|
pagerduty = PagerDutyAlerting(
|
|
alerting_args=AlertingConfig(
|
|
failure_threshold=1, failure_threshold_window_seconds=10
|
|
)
|
|
)
|
|
litellm.callbacks = [pagerduty]
|
|
|
|
try:
|
|
await litellm.acompletion(
|
|
model="gpt-3.5-turbo",
|
|
messages=[{"role": "user", "content": "hi"}],
|
|
mock_response="litellm.RateLimitError",
|
|
)
|
|
except litellm.RateLimitError:
|
|
pass
|
|
|
|
await asyncio.sleep(2)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pagerduty_alerting_high_failure_rate():
|
|
pagerduty = PagerDutyAlerting(
|
|
alerting_args=AlertingConfig(
|
|
failure_threshold=3, failure_threshold_window_seconds=600
|
|
)
|
|
)
|
|
litellm.callbacks = [pagerduty]
|
|
|
|
try:
|
|
await litellm.acompletion(
|
|
model="gpt-3.5-turbo",
|
|
messages=[{"role": "user", "content": "hi"}],
|
|
mock_response="litellm.RateLimitError",
|
|
)
|
|
except litellm.RateLimitError:
|
|
pass
|
|
|
|
await asyncio.sleep(2)
|
|
|
|
# make 3 more fails
|
|
for _ in range(3):
|
|
try:
|
|
await litellm.acompletion(
|
|
model="gpt-3.5-turbo",
|
|
messages=[{"role": "user", "content": "hi"}],
|
|
mock_response="litellm.RateLimitError",
|
|
)
|
|
except litellm.RateLimitError:
|
|
pass
|
|
|
|
await asyncio.sleep(2)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pagerduty_hanging_request_alerting():
|
|
pagerduty = PagerDutyAlerting(
|
|
alerting_args=AlertingConfig(hanging_threshold_seconds=0.0000001)
|
|
)
|
|
litellm.callbacks = [pagerduty]
|
|
|
|
await pagerduty.async_pre_call_hook(
|
|
cache=None,
|
|
user_api_key_dict=UserAPIKeyAuth(
|
|
api_key="test",
|
|
key_alias="test-pagerduty",
|
|
team_alias="test-team",
|
|
org_id="test-org",
|
|
user_id="test-user",
|
|
end_user_id="test-end-user",
|
|
),
|
|
data={"model": "gpt-4o", "messages": [{"role": "user", "content": "hi"}]},
|
|
call_type="completion",
|
|
)
|
|
|
|
await litellm.acompletion(
|
|
model="gpt-4o",
|
|
messages=[{"role": "user", "content": "hi"}],
|
|
)
|
|
|
|
await asyncio.sleep(1)
|