mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(lint): fix remaining PLR0913 (too-many-args) violations
- Extract highest_risk_percentage from response_payload in _log_guardrail_result instead of passing as a param - Introduce DataSourceConfig dataclass to bundle name/enabled/priority for URLDataSource, VectorStoreDataSource, FactCheckDataSource Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fd01774412
commit
240afd4724
2 changed files with 31 additions and 14 deletions
|
|
@ -192,7 +192,6 @@ class BiasHallucinationEstimatorGuardrail(CustomGuardrail):
|
|||
response_payload=response_payload,
|
||||
status=status,
|
||||
start_time=start_time,
|
||||
highest_risk_percentage=highest_risk.risk.overall_risk_percentage,
|
||||
)
|
||||
|
||||
if decision == "blocked":
|
||||
|
|
@ -276,8 +275,16 @@ class BiasHallucinationEstimatorGuardrail(CustomGuardrail):
|
|||
response_payload: dict[str, object],
|
||||
status: GuardrailStatus,
|
||||
start_time: datetime,
|
||||
highest_risk_percentage: int,
|
||||
) -> None:
|
||||
risk_scores = response_payload.get("risk_scores") or []
|
||||
highest_risk_percentage: int = max(
|
||||
(
|
||||
int(r["overall_risk_percentage"]) # type: ignore[index]
|
||||
for r in risk_scores
|
||||
if isinstance(r, dict) and "overall_risk_percentage" in r
|
||||
),
|
||||
default=0,
|
||||
)
|
||||
detection_methods = self._detection_methods(response_payload)
|
||||
tracing_detail = GuardrailTracingDetail(
|
||||
guardrail_id=self.guardrail_id or self.guardrail_name,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,15 @@ from pathlib import Path
|
|||
from typing import Any, cast
|
||||
|
||||
|
||||
@dataclass
|
||||
class DataSourceConfig:
|
||||
"""Common configuration shared by all DataSource subclasses."""
|
||||
|
||||
name: str = ""
|
||||
enabled: bool = True
|
||||
priority: int = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
class FetchConfig:
|
||||
"""HTTP fetch settings for URL-backed data sources."""
|
||||
|
|
@ -162,12 +171,11 @@ class URLDataSource(DataSource):
|
|||
def __init__(
|
||||
self,
|
||||
urls: list[str],
|
||||
name: str = "url_source",
|
||||
enabled: bool = True,
|
||||
priority: int = 0,
|
||||
source_config: DataSourceConfig | None = None,
|
||||
fetch_config: FetchConfig | None = None,
|
||||
) -> None:
|
||||
super().__init__(name=name, enabled=enabled, priority=priority)
|
||||
_sc = source_config or DataSourceConfig(name="url_source")
|
||||
super().__init__(name=_sc.name, enabled=_sc.enabled, priority=_sc.priority)
|
||||
self.urls = urls
|
||||
_fetch = fetch_config or FetchConfig()
|
||||
self.cache_ttl = _fetch.cache_ttl
|
||||
|
|
@ -241,14 +249,15 @@ class VectorStoreDataSource(DataSource):
|
|||
def __init__(
|
||||
self,
|
||||
provider: str,
|
||||
name: str = "",
|
||||
enabled: bool = True,
|
||||
priority: int = 0,
|
||||
source_config: DataSourceConfig | None = None,
|
||||
client_config: VectorStoreClientConfig | None = None,
|
||||
**config: str,
|
||||
) -> None:
|
||||
_sc = source_config or DataSourceConfig()
|
||||
super().__init__(
|
||||
name=name or f"vectorstore_{provider}", enabled=enabled, priority=priority
|
||||
name=_sc.name or f"vectorstore_{provider}",
|
||||
enabled=_sc.enabled,
|
||||
priority=_sc.priority,
|
||||
)
|
||||
self.provider = provider
|
||||
self.config = config
|
||||
|
|
@ -403,14 +412,15 @@ class FactCheckDataSource(DataSource):
|
|||
def __init__(
|
||||
self,
|
||||
provider: str = "snopes",
|
||||
name: str = "",
|
||||
enabled: bool = True,
|
||||
priority: int = 0,
|
||||
source_config: DataSourceConfig | None = None,
|
||||
api_key: str | None = None,
|
||||
**config: str,
|
||||
) -> None:
|
||||
_sc = source_config or DataSourceConfig()
|
||||
super().__init__(
|
||||
name=name or f"factcheck_{provider}", enabled=enabled, priority=priority
|
||||
name=_sc.name or f"factcheck_{provider}",
|
||||
enabled=_sc.enabled,
|
||||
priority=_sc.priority,
|
||||
)
|
||||
self.provider = provider
|
||||
self.api_key = api_key
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue