forked from Aider-AI/aider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_exceptions.py
65 lines (49 loc) · 1.96 KB
/
test_exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from aider.exceptions import ExInfo, LiteLLMExceptions
def test_litellm_exceptions_load():
"""Test that LiteLLMExceptions loads without errors"""
ex = LiteLLMExceptions()
assert len(ex.exceptions) > 0
def test_exceptions_tuple():
"""Test that exceptions_tuple returns a non-empty tuple"""
ex = LiteLLMExceptions()
assert isinstance(ex.exceptions_tuple(), tuple)
assert len(ex.exceptions_tuple()) > 0
def test_get_ex_info():
"""Test get_ex_info returns correct ExInfo"""
ex = LiteLLMExceptions()
# Test with a known exception type
from litellm import AuthenticationError
auth_error = AuthenticationError(
message="Invalid API key", llm_provider="openai", model="gpt-4"
)
ex_info = ex.get_ex_info(auth_error)
assert isinstance(ex_info, ExInfo)
assert ex_info.name == "AuthenticationError"
assert ex_info.retry is False
assert "API key" in ex_info.description
# Test with unknown exception type
class UnknownError(Exception):
pass
unknown = UnknownError()
ex_info = ex.get_ex_info(unknown)
assert isinstance(ex_info, ExInfo)
assert ex_info.name is None
assert ex_info.retry is None
assert ex_info.description is None
def test_rate_limit_error():
"""Test specific handling of RateLimitError"""
ex = LiteLLMExceptions()
from litellm import RateLimitError
rate_error = RateLimitError(message="Rate limit exceeded", llm_provider="openai", model="gpt-4")
ex_info = ex.get_ex_info(rate_error)
assert ex_info.retry is True
assert "rate limited" in ex_info.description.lower()
def test_context_window_error():
"""Test specific handling of ContextWindowExceededError"""
ex = LiteLLMExceptions()
from litellm import ContextWindowExceededError
ctx_error = ContextWindowExceededError(
message="Context length exceeded", model="gpt-4", llm_provider="openai"
)
ex_info = ex.get_ex_info(ctx_error)
assert ex_info.retry is False