mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix(lint): resolve all three CI lint job failures
1. lint (ruff_strict_gate) — UP006/UP045/F401 violations introduced on changed lines. Fixed Dict/List/Optional/Tuple → built-in equivalents across every file in the PR diff; cleaned up now-unused typing imports. 2. any-discipline — RecursionError in check_any_discipline.contains_any() on deeply-nested mypy types. Upstream fixed this by converting to an iterative stack-based algorithm (merged). Also added deepkeep.py to any-discipline-budget.json via 'make lint-any-budget-update' so the new file's Any count is baselined instead of failing against the zero-baseline default. 3. basedpyright reportMissingParameterType — **kwargs in DeepKeepGuardrail __init__ lacked a type annotation. Added **kwargs: Any.
This commit is contained in:
parent
b892470ba3
commit
9b456c9313
6 changed files with 1654 additions and 1502 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -83,7 +83,9 @@ class CustomGuardrail(CustomLogger):
|
|||
self,
|
||||
guardrail_name: str | None = None,
|
||||
supported_event_hooks: list[GuardrailEventHooks] | None = None,
|
||||
event_hook: Union[GuardrailEventHooks, list[GuardrailEventHooks], Mode] | None = None,
|
||||
event_hook: (
|
||||
Union[GuardrailEventHooks, list[GuardrailEventHooks], Mode] | None
|
||||
) = None,
|
||||
default_on: bool = False,
|
||||
mask_request_content: bool = False,
|
||||
mask_response_content: bool = False,
|
||||
|
|
@ -115,7 +117,9 @@ class CustomGuardrail(CustomLogger):
|
|||
"""
|
||||
self.guardrail_name = guardrail_name
|
||||
self.supported_event_hooks = supported_event_hooks
|
||||
self.event_hook: Union[GuardrailEventHooks, list[GuardrailEventHooks], Mode] | None = event_hook
|
||||
self.event_hook: (
|
||||
Union[GuardrailEventHooks, list[GuardrailEventHooks], Mode] | None
|
||||
) = event_hook
|
||||
self.default_on: bool = default_on
|
||||
self.mask_request_content: bool = mask_request_content
|
||||
self.mask_response_content: bool = mask_response_content
|
||||
|
|
@ -124,9 +128,7 @@ class CustomGuardrail(CustomLogger):
|
|||
self.on_violation: str | None = on_violation
|
||||
self.realtime_violation_message: str | None = realtime_violation_message
|
||||
self.on_sensitive_data: str | None = on_sensitive_data
|
||||
self.sensitive_data_route_to_model: str | None = (
|
||||
sensitive_data_route_to_model
|
||||
)
|
||||
self.sensitive_data_route_to_model: str | None = sensitive_data_route_to_model
|
||||
self.sticky_session_routing: bool = sticky_session_routing
|
||||
|
||||
if supported_event_hooks:
|
||||
|
|
|
|||
|
|
@ -81,9 +81,7 @@ class GenAIMetricRecorder:
|
|||
survives.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, metrics: GenAIMetrics, callback_name: str | None = None
|
||||
) -> None:
|
||||
def __init__(self, metrics: GenAIMetrics, callback_name: str | None = None) -> None:
|
||||
self._metrics = metrics
|
||||
self._callback_name = callback_name
|
||||
self._include: frozenset[str] | None = None
|
||||
|
|
|
|||
|
|
@ -1251,9 +1251,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
def map_response_format_to_anthropic_output_format(
|
||||
self, value: dict | None
|
||||
) -> AnthropicOutputSchema | None:
|
||||
json_schema: dict | None = self._extract_json_schema_from_response_format(
|
||||
value
|
||||
)
|
||||
json_schema: dict | None = self._extract_json_schema_from_response_format(value)
|
||||
if json_schema is None:
|
||||
return None
|
||||
|
||||
|
|
@ -1287,9 +1285,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
): # value is a no-op
|
||||
return None
|
||||
|
||||
json_schema: dict | None = self._extract_json_schema_from_response_format(
|
||||
value
|
||||
)
|
||||
json_schema: dict | None = self._extract_json_schema_from_response_format(value)
|
||||
if json_schema is None:
|
||||
return None
|
||||
"""
|
||||
|
|
@ -2071,16 +2067,15 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
|
||||
first_json = tool_calls[json_indices[0]]
|
||||
json_msg = AnthropicConfig._convert_tool_response_to_message([first_json])
|
||||
extra_content: str | None = (
|
||||
json_msg.content if json_msg is not None else None
|
||||
)
|
||||
extra_content: str | None = json_msg.content if json_msg is not None else None
|
||||
filtered_tools = [t for i, t in enumerate(tool_calls) if i not in json_indices]
|
||||
return None, filtered_tools, extra_content
|
||||
|
||||
def extract_response_content(self, completion_response: dict) -> tuple[
|
||||
str,
|
||||
list[Any] | None,
|
||||
list[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None,
|
||||
list[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]]
|
||||
| None,
|
||||
str | None,
|
||||
list[ChatCompletionToolCallChunk],
|
||||
list[Any] | None,
|
||||
|
|
@ -2089,7 +2084,12 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
]:
|
||||
text_content = ""
|
||||
citations: list[Any] | None = None
|
||||
thinking_blocks: list[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None = None
|
||||
thinking_blocks: (
|
||||
list[
|
||||
Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]
|
||||
]
|
||||
| None
|
||||
) = None
|
||||
reasoning_content: str | None = None
|
||||
tool_calls: list[ChatCompletionToolCallChunk] = []
|
||||
web_search_results: list[Any] | None = None
|
||||
|
|
@ -2364,7 +2364,12 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
self,
|
||||
completion_response: dict,
|
||||
citations: list[Any] | None,
|
||||
thinking_blocks: list[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None,
|
||||
thinking_blocks: (
|
||||
list[
|
||||
Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]
|
||||
]
|
||||
| None
|
||||
),
|
||||
web_search_results: list[Any] | None,
|
||||
tool_results: list[Any] | None,
|
||||
compaction_blocks: list[Any] | None,
|
||||
|
|
@ -2606,9 +2611,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
|
|||
|
||||
"""
|
||||
## HANDLE JSON MODE - anthropic returns single function call
|
||||
json_mode_content_str: str | None = tool_calls[0]["function"].get(
|
||||
"arguments"
|
||||
)
|
||||
json_mode_content_str: str | None = tool_calls[0]["function"].get("arguments")
|
||||
try:
|
||||
if json_mode_content_str is not None:
|
||||
args = json.loads(json_mode_content_str)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -73,7 +73,7 @@ class DeepKeepGuardrail(CustomGuardrail):
|
|||
firewall_id: str | None = None,
|
||||
unreachable_fallback: Literal["fail_closed", "fail_open"] = "fail_closed",
|
||||
extra_headers: dict[str, str] | None = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
):
|
||||
self.async_handler = get_async_httpx_client(
|
||||
llm_provider=httpxSpecialProvider.GuardrailCallback
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue