mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-27 01:22:18 +00:00
When the trimming ratio is aggressive enough that new_length < 2,
half_length becomes 0. Python's -0 == 0 identity means:
content[-0:] == content[0:] == entire string
so the 'trimmed' result was '' + '..' + full_content — two characters
LONGER than the original on every iteration. The loop never converged
and hit MAX_TOKEN_TRIMMING_ATTEMPTS without ever shrinking the content,
causing the caller to receive an untrimmed (or larger) message and then
get a context_length_exceeded error from the provider.
Fix: when half_length == 0, fall back to a simple head-truncation
(content[:new_length]) which always produces a strictly shorter result.
Adds regression test asserting content length is monotonically
non-increasing across all trimming iterations.
|
||
|---|---|---|
| .. | ||
| base_token_counter_test.py | ||
| conftest.py | ||
| log.txt | ||
| test_aiohttp_handler.py | ||
| test_anthropic_token_counter.py | ||
| test_aws_secret_manager.py | ||
| test_azure_ai_anthropic_token_counter.py | ||
| test_bedrock_token_counter.py | ||
| test_cyberark.py | ||
| test_get_secret.py | ||
| test_hashicorp.py | ||
| test_health_check.py | ||
| test_litellm_overhead.py | ||
| test_logging_callback_manager.py | ||
| test_proxy_budget_reset.py | ||
| test_secret_manager.py | ||
| test_utils.py | ||
| test_validate_tool_choice.py | ||
| vertex_key.json | ||