mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-06 07:48:06 +00:00
fix(anthropic): keep system blocks with a non-string type instead of raising
This commit is contained in:
parent
2cf332c995
commit
812834f402
2 changed files with 9 additions and 1 deletions
|
|
@ -89,7 +89,8 @@ def _as_sequence(value: object) -> tuple[object, ...] | None:
|
|||
|
||||
def _is_tool_change_block(block: object) -> bool:
|
||||
mapping: Final = _as_mapping(block)
|
||||
return mapping is not None and mapping.get("type") in _TOOL_CHANGE_BLOCK_TYPES
|
||||
block_type: Final = mapping.get("type") if mapping is not None else None
|
||||
return isinstance(block_type, str) and block_type in _TOOL_CHANGE_BLOCK_TYPES
|
||||
|
||||
|
||||
def _header_beta_values(headers: Mapping[str, str]) -> frozenset[str]:
|
||||
|
|
|
|||
|
|
@ -159,6 +159,13 @@ def test_inline_tools_beta_also_unlocks_system_tool_changes() -> None:
|
|||
]
|
||||
|
||||
|
||||
def test_system_block_with_unhashable_type_is_kept_for_the_provider_to_reject() -> None:
|
||||
messages: Final = [{"role": "system", "content": [{"type": [], "text": "x"}]}]
|
||||
result: Final = strip_beta_gated_system_messages(messages, frozenset(), drop_params=True)
|
||||
assert result.messages is messages
|
||||
assert result.stripped == ()
|
||||
|
||||
|
||||
def test_system_message_emptied_by_the_strip_is_dropped() -> None:
|
||||
messages: Final = [
|
||||
{"role": "user", "content": "hi"},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue