mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
fix(anthropic): annotate thought-signature helpers with Final (LIT010)
Satisfy type_discipline_gate LIT010 on the five assignments this PR introduced: pad, base_id, signature/function_signature, and parts.
This commit is contained in:
parent
8d182ccae4
commit
f1adc665d2
2 changed files with 7 additions and 7 deletions
|
|
@ -1792,7 +1792,7 @@ def encode_thought_signature_for_anthropic_tool_id(signature: str) -> str:
|
|||
|
||||
def decode_thought_signature_from_anthropic_tool_id(encoded: str) -> str:
|
||||
"""Inverse of ``encode_thought_signature_for_anthropic_tool_id``."""
|
||||
pad = (-len(encoded)) % 4
|
||||
pad: Final = (-len(encoded)) % 4
|
||||
return base64.urlsafe_b64decode(encoded + ("=" * pad)).decode("utf-8")
|
||||
|
||||
|
||||
|
|
@ -1806,7 +1806,7 @@ def format_anthropic_tool_use_id_with_signature(raw_id: str, thought_signature:
|
|||
signature after ``__thought__`` lets those clients round-trip the real
|
||||
signature the same way OpenAI-compatible clients do via ``tool_calls[].id``.
|
||||
"""
|
||||
base_id = normalize_anthropic_tool_use_id(raw_id)
|
||||
base_id: Final = normalize_anthropic_tool_use_id(raw_id)
|
||||
if not thought_signature:
|
||||
return base_id
|
||||
return f"{base_id}{THOUGHT_SIGNATURE_SEPARATOR}{encode_thought_signature_for_anthropic_tool_id(thought_signature)}"
|
||||
|
|
|
|||
|
|
@ -367,19 +367,19 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
"""
|
||||
fields: Final = _optional_attr(tool_call, "provider_specific_fields")
|
||||
if fields:
|
||||
signature = _thought_signature(fields)
|
||||
signature: Final = _thought_signature(fields)
|
||||
if signature:
|
||||
return signature
|
||||
|
||||
function_fields: Final = _optional_attr(_optional_attr(tool_call, "function"), "provider_specific_fields")
|
||||
if function_fields:
|
||||
signature = _thought_signature(function_fields)
|
||||
if signature:
|
||||
return signature
|
||||
function_signature: Final = _thought_signature(function_fields)
|
||||
if function_signature:
|
||||
return function_signature
|
||||
|
||||
raw_id: Final = _optional_attr(tool_call, "id")
|
||||
if isinstance(raw_id, str) and THOUGHT_SIGNATURE_SEPARATOR in raw_id:
|
||||
parts = raw_id.split(THOUGHT_SIGNATURE_SEPARATOR, 1)
|
||||
parts: Final = raw_id.split(THOUGHT_SIGNATURE_SEPARATOR, 1)
|
||||
if len(parts) == 2 and parts[1]:
|
||||
return parts[1]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue