mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-25 01:02:15 +00:00
Move the wave 1 phase 7 batch (fireworks_ai, gemini, gigachat, github_copilot; 20 files) from tests/test_litellm to tests/unit after judging every test function under a behaviour mutation. Seven wiring or mock-echo tests that stayed green are deleted. The fireworks cost calculator tests get a local model_cost save/restore fixture since the tests/unit tree has no shared conftest for it Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
79 lines
No EOL
2.4 KiB
Python
79 lines
No EOL
2.4 KiB
Python
"""
|
|
Tests for litellm.llms.gigachat.utils
|
|
"""
|
|
|
|
import pytest
|
|
from litellm.llms.gigachat.utils import convert_usage
|
|
from litellm.types.utils import PromptTokensDetailsWrapper, Usage
|
|
|
|
|
|
class TestConvertUsage:
|
|
def test_basic_usage_without_precached(self):
|
|
"""Test convert_usage with standard tokens, no precached prompt tokens."""
|
|
result = convert_usage(
|
|
{
|
|
"prompt_tokens": 10,
|
|
"completion_tokens": 5,
|
|
"total_tokens": 15,
|
|
}
|
|
)
|
|
|
|
assert result == Usage(
|
|
prompt_tokens=10,
|
|
completion_tokens=5,
|
|
total_tokens=15,
|
|
prompt_tokens_details=None,
|
|
)
|
|
|
|
def test_usage_with_precached_prompt_tokens(self):
|
|
"""GigaChat's prompt_tokens and total_tokens exclude cached tokens (docs example:
|
|
prompt_tokens=1, precached_prompt_tokens=37, total_tokens=5), so OpenAI-convention
|
|
usage adds precached back in and surfaces it as cached_tokens."""
|
|
result = convert_usage(
|
|
{
|
|
"prompt_tokens": 10,
|
|
"completion_tokens": 5,
|
|
"precached_prompt_tokens": 3,
|
|
"total_tokens": 15,
|
|
}
|
|
)
|
|
|
|
assert result == Usage(
|
|
prompt_tokens=13,
|
|
completion_tokens=5,
|
|
total_tokens=18,
|
|
prompt_tokens_details=PromptTokensDetailsWrapper(cached_tokens=3),
|
|
)
|
|
|
|
def test_zero_precached_prompt_tokens(self):
|
|
"""Test convert_usage with zero precached_prompt_tokens does not create details wrapper."""
|
|
result = convert_usage(
|
|
{
|
|
"prompt_tokens": 10,
|
|
"completion_tokens": 5,
|
|
"precached_prompt_tokens": 0,
|
|
"total_tokens": 15,
|
|
}
|
|
)
|
|
|
|
assert result == Usage(
|
|
prompt_tokens=10,
|
|
completion_tokens=5,
|
|
total_tokens=15,
|
|
prompt_tokens_details=None,
|
|
)
|
|
|
|
def test_missing_optional_fields(self):
|
|
"""Test convert_usage with missing optional fields defaults to zero."""
|
|
result = convert_usage(
|
|
{
|
|
"prompt_tokens": 10,
|
|
"completion_tokens": 5,
|
|
"total_tokens": 15,
|
|
}
|
|
)
|
|
|
|
assert result.prompt_tokens == 10
|
|
assert result.completion_tokens == 5
|
|
assert result.total_tokens == 15
|
|
assert result.prompt_tokens_details is None |