mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-10 08:28:25 +00:00
style: fix ruff lint (modernize type hints)
This commit is contained in:
parent
cb2ee9ec1f
commit
9958d92d0b
2 changed files with 7 additions and 8 deletions
|
|
@ -8,9 +8,8 @@ from __future__ import annotations
|
|||
import threading
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import date
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from .patterns import default_patterns
|
||||
|
||||
|
|
@ -31,7 +30,7 @@ class Decision:
|
|||
action: str
|
||||
reason_code: str
|
||||
correlation_id: str
|
||||
redacted_text: Optional[str] = None
|
||||
redacted_text: str | None = None
|
||||
details: dict = field(default_factory=dict)
|
||||
|
||||
def to_receipt(self) -> dict:
|
||||
|
|
@ -109,14 +108,14 @@ class TealEngine:
|
|||
limit = self._cost_policy.get("daily_limit_usd")
|
||||
if limit is None:
|
||||
return False, 0.0, 0.0
|
||||
today = date.today().isoformat()
|
||||
today = datetime.now().astimezone().date().isoformat()
|
||||
with self._lock:
|
||||
spent = self._spend_by_day.get(today, 0.0)
|
||||
return spent >= limit, spent, limit
|
||||
|
||||
def track_cost(self, tokens: int, cost_per_1k_tokens: float = 0.002) -> float:
|
||||
cost = (tokens / 1000.0) * cost_per_1k_tokens
|
||||
today = date.today().isoformat()
|
||||
today = datetime.now().astimezone().date().isoformat()
|
||||
with self._lock:
|
||||
self._spend_by_day[today] = self._spend_by_day.get(today, 0.0) + cost
|
||||
return cost
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ implementation of the same interface.
|
|||
No network calls, no LLM calls, no external API keys required.
|
||||
"""
|
||||
|
||||
from typing import TYPE_CHECKING, Final, List, Literal, Optional
|
||||
from typing import TYPE_CHECKING, Final, Literal, Optional
|
||||
|
||||
from litellm.integrations.custom_guardrail import (
|
||||
CustomGuardrail,
|
||||
|
|
@ -33,7 +33,7 @@ DEFAULT_POLICIES = [
|
|||
class TealTigerGuardrail(CustomGuardrail):
|
||||
def __init__(
|
||||
self,
|
||||
policies: Optional[list] = None,
|
||||
policies: list | None = None,
|
||||
policy_mode: str = "ENFORCE",
|
||||
**kwargs,
|
||||
):
|
||||
|
|
@ -68,7 +68,7 @@ class TealTigerGuardrail(CustomGuardrail):
|
|||
if over_budget:
|
||||
raise ValueError(f"TealTiger: blocked — DAILY_BUDGET_EXCEEDED (${spent:.2f} / ${limit:.2f})")
|
||||
|
||||
checked_texts: List[str] = []
|
||||
checked_texts: list[str] = []
|
||||
for text in inputs.get("texts") or []:
|
||||
decision = self.engine.evaluate_text(text)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue