mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix: mark test_caching_with_reasoning_content as flaky and handle InternalServerError (#17603)
- Add @pytest.mark.flaky(retries=3, delay=1) decorator to handle intermittent Anthropic API failures - Add error handling to skip test when Anthropic API returns InternalServerError - Prevents false test failures due to external API 500 errors
This commit is contained in:
parent
497856e1e3
commit
09dcd381d7
1 changed files with 19 additions and 15 deletions
|
|
@ -2634,6 +2634,7 @@ def test_redis_caching_multiple_namespaces():
|
|||
), f"Expected different response ID for no namespace vs namespaced. Got {response_1.id} and {response_4.id}"
|
||||
|
||||
|
||||
@pytest.mark.flaky(retries=3, delay=1)
|
||||
def test_caching_with_reasoning_content():
|
||||
"""
|
||||
Test that reasoning content is cached
|
||||
|
|
@ -2641,24 +2642,27 @@ def test_caching_with_reasoning_content():
|
|||
|
||||
from litellm._uuid import uuid
|
||||
|
||||
messages = [{"role": "user", "content": f"what is litellm? {uuid.uuid4()}"}]
|
||||
litellm.cache = Cache()
|
||||
try:
|
||||
messages = [{"role": "user", "content": f"what is litellm? {uuid.uuid4()}"}]
|
||||
litellm.cache = Cache()
|
||||
|
||||
response_1 = completion(
|
||||
model="anthropic/claude-3-7-sonnet-latest",
|
||||
messages=messages,
|
||||
thinking={"type": "enabled", "budget_tokens": 1024},
|
||||
)
|
||||
response_1 = completion(
|
||||
model="anthropic/claude-3-7-sonnet-latest",
|
||||
messages=messages,
|
||||
thinking={"type": "enabled", "budget_tokens": 1024},
|
||||
)
|
||||
|
||||
response_2 = completion(
|
||||
model="anthropic/claude-3-7-sonnet-latest",
|
||||
messages=messages,
|
||||
thinking={"type": "enabled", "budget_tokens": 1024},
|
||||
)
|
||||
response_2 = completion(
|
||||
model="anthropic/claude-3-7-sonnet-latest",
|
||||
messages=messages,
|
||||
thinking={"type": "enabled", "budget_tokens": 1024},
|
||||
)
|
||||
|
||||
print(f"response 2: {response_2.model_dump_json(indent=4)}")
|
||||
assert response_2._hidden_params["cache_hit"] == True
|
||||
assert response_2.choices[0].message.reasoning_content is not None
|
||||
print(f"response 2: {response_2.model_dump_json(indent=4)}")
|
||||
assert response_2._hidden_params["cache_hit"] == True
|
||||
assert response_2.choices[0].message.reasoning_content is not None
|
||||
except litellm.InternalServerError as e:
|
||||
pytest.skip(f"Anthropic API returned InternalServerError - {str(e)}")
|
||||
|
||||
|
||||
def test_caching_reasoning_args_miss(): # test in memory cache
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue