style: apply black formatting

This commit is contained in:
Lance Hsu 2026-04-02 21:45:02 +08:00
parent 5b2b4abb6f
commit a87329d2a5
No known key found for this signature in database
GPG key ID: CFF816BB8560B8B8
2 changed files with 8 additions and 2 deletions

View file

@ -3,6 +3,7 @@ Semantic MCP Tool Filtering using semantic-router
Filters MCP tools semantically for /chat/completions and /responses endpoints.
"""
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from litellm._logging import verbose_logger

View file

@ -4,6 +4,7 @@ Semantic Tool Filter Hook
Pre-call hook that filters MCP tools semantically before LLM inference.
Reduces context window size and improves tool selection accuracy.
"""
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from litellm._logging import verbose_proxy_logger
@ -226,10 +227,14 @@ class SemanticToolFilterHook(CustomLogger):
# Separate MCP tools (prefixed) from non-MCP tools — only filter
# MCP tools, always pass non-MCP tools through untouched.
def _tool_name(t):
return t.get("name", "") if isinstance(t, dict) else getattr(t, "name", "")
return (
t.get("name", "") if isinstance(t, dict) else getattr(t, "name", "")
)
mcp_tools = [t for t in tools if is_tool_name_prefixed(_tool_name(t))]
non_mcp_tools = [t for t in tools if not is_tool_name_prefixed(_tool_name(t))]
non_mcp_tools = [
t for t in tools if not is_tool_name_prefixed(_tool_name(t))
]
if not mcp_tools:
return None