mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
refactor(anthropic): drop getattr and trim docstrings in max_tokens truncation helper
This commit is contained in:
parent
c92170cd59
commit
fbbebf5044
1 changed files with 3 additions and 7 deletions
|
|
@ -44,18 +44,14 @@ _OUTPUT_TOKEN_LIMIT_ERROR_MARKER = "max_tokens or model output limit was reached
|
|||
|
||||
|
||||
def _is_output_token_limit_error(exc: Exception) -> bool:
|
||||
"""True for the provider 400 raised when the output-token budget is too
|
||||
small to finish even one token (e.g. OpenAI GPT-5.x with ``max_tokens=1``)."""
|
||||
"""True for the provider 400 raised when the output-token budget cannot finish even one token (e.g. OpenAI GPT-5.x with ``max_tokens=1``)."""
|
||||
if not isinstance(exc, litellm.BadRequestError):
|
||||
return False
|
||||
message = getattr(exc, "message", None) or str(exc)
|
||||
return _OUTPUT_TOKEN_LIMIT_ERROR_MARKER in message.lower()
|
||||
return _OUTPUT_TOKEN_LIMIT_ERROR_MARKER in exc.message.lower()
|
||||
|
||||
|
||||
def _build_max_tokens_truncation_response(model: str) -> ModelResponse:
|
||||
"""Synthesize an empty ``finish_reason="length"`` response so the empty,
|
||||
``max_tokens``-truncated turn flows through the same translation path as a
|
||||
real completion (mapping to Anthropic ``stop_reason="max_tokens"``)."""
|
||||
"""Synthesize an empty ``finish_reason="length"`` response so the truncated turn reuses the existing translation path (mapping to Anthropic ``stop_reason="max_tokens"``)."""
|
||||
return ModelResponse(
|
||||
model=model,
|
||||
choices=[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue