mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
test(utils): mock the prompt-cache token count at its current seam
is_prompt_caching_valid_prompt no longer calls token_counter, so the test's patch of litellm.utils.token_counter never fired and call_args was None. Patch the counter the function actually reaches now and keep asserting use_default_image_token_count is True.
This commit is contained in:
parent
fe683ea139
commit
7e564e108a
1 changed files with 6 additions and 3 deletions
|
|
@ -1343,12 +1343,15 @@ def test_is_prompt_caching_enabled_error_handling():
|
|||
|
||||
def test_is_prompt_caching_enabled_return_default_image_dimensions():
|
||||
"""
|
||||
Assert that `is_prompt_caching_valid_prompt` calls token_counter with use_default_image_token_count=True
|
||||
Assert that `is_prompt_caching_valid_prompt` counts tokens with use_default_image_token_count=True
|
||||
when processing messages containing images
|
||||
|
||||
IMPORTANT: Ensures Get token counter does not make a GET request to the image url
|
||||
"""
|
||||
with patch("litellm.utils.token_counter") as mock_token_counter:
|
||||
mock_token_counter = MagicMock(return_value=False)
|
||||
with patch(
|
||||
"litellm.utils._get_messages_reach_token_count", return_value=mock_token_counter
|
||||
):
|
||||
litellm.utils.is_prompt_caching_valid_prompt(
|
||||
messages=[
|
||||
{
|
||||
|
|
@ -1370,7 +1373,7 @@ def test_is_prompt_caching_enabled_return_default_image_dimensions():
|
|||
model="gpt-4o-mini",
|
||||
)
|
||||
|
||||
# Assert token_counter was called with use_default_image_token_count=True
|
||||
# Assert the token count was taken with use_default_image_token_count=True
|
||||
args_to_mock_token_counter = mock_token_counter.call_args[1]
|
||||
print("args_to_mock", args_to_mock_token_counter)
|
||||
assert args_to_mock_token_counter["use_default_image_token_count"] is True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue