mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
Co-authored-by: yuneng <yuneng@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
29 lines
894 B
Python
29 lines
894 B
Python
"""Tests for input-token counting shared across the reservation path's models."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from types import MappingProxyType
|
|
from typing import Final
|
|
|
|
import pytest
|
|
|
|
from litellm.proxy.spend_tracking.input_tokens import (
|
|
TOKENIZE_OFF_EVENT_LOOP_MIN_CHARS,
|
|
count_input_tokens,
|
|
count_input_tokens_for_model,
|
|
)
|
|
|
|
CL100K_MODEL: Final = "gpt-4"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_large_input_is_still_counted() -> None:
|
|
request_body: Final = {
|
|
"model": CL100K_MODEL,
|
|
"messages": [{"role": "user", "content": "x" * (TOKENIZE_OFF_EVENT_LOOP_MIN_CHARS + 1)}],
|
|
}
|
|
|
|
counts: Final = await count_input_tokens(request_body=request_body, raw_body=None, models=(CL100K_MODEL,))
|
|
|
|
assert counts[CL100K_MODEL] == count_input_tokens_for_model(request_body=request_body, model=CL100K_MODEL)
|
|
assert isinstance(counts, MappingProxyType)
|