mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
add _is_bedrock_tool_block
This commit is contained in:
parent
8b575f4656
commit
e6c1a656f4
1 changed files with 33 additions and 1 deletions
|
|
@ -4395,6 +4395,32 @@ def add_cache_point_tool_block(tool: dict) -> Optional[BedrockToolBlock]:
|
|||
return None
|
||||
|
||||
|
||||
def _is_bedrock_tool_block(tool: dict) -> bool:
|
||||
"""
|
||||
Check if a tool is already a BedrockToolBlock.
|
||||
|
||||
BedrockToolBlock has one of: systemTool, toolSpec, or cachePoint.
|
||||
This is used to detect tools that are already in Bedrock format
|
||||
(e.g., systemTool for Nova grounding) vs OpenAI-style function tools
|
||||
that need transformation.
|
||||
|
||||
Args:
|
||||
tool: The tool dict to check
|
||||
|
||||
Returns:
|
||||
True if the tool is already a BedrockToolBlock, False otherwise
|
||||
|
||||
Examples:
|
||||
>>> _is_bedrock_tool_block({"systemTool": {"name": "nova_grounding"}})
|
||||
True
|
||||
>>> _is_bedrock_tool_block({"type": "function", "function": {...}})
|
||||
False
|
||||
"""
|
||||
return isinstance(tool, dict) and (
|
||||
"systemTool" in tool or "toolSpec" in tool or "cachePoint" in tool
|
||||
)
|
||||
|
||||
|
||||
def _bedrock_tools_pt(tools: List) -> List[BedrockToolBlock]:
|
||||
"""
|
||||
OpenAI tools looks like:
|
||||
|
|
@ -4448,7 +4474,13 @@ def _bedrock_tools_pt(tools: List) -> List[BedrockToolBlock]:
|
|||
|
||||
tool_block_list: List[BedrockToolBlock] = []
|
||||
for tool in tools:
|
||||
# Handle regular function tools
|
||||
# Check if tool is already a BedrockToolBlock (e.g., systemTool for Nova grounding)
|
||||
if _is_bedrock_tool_block(tool):
|
||||
# Already a BedrockToolBlock, pass it through
|
||||
tool_block_list.append(tool) # type: ignore
|
||||
continue
|
||||
|
||||
# Handle regular OpenAI-style function tools
|
||||
parameters = tool.get("function", {}).get(
|
||||
"parameters", {"type": "object", "properties": {}}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue