forked from cardosofelipe/fast-next-template
refactor(safety): apply consistent formatting across services and tests
Improved code readability and uniformity by standardizing line breaks, indentation, and inline conditions across safety-related services, models, and tests, including content filters, validation rules, and emergency controls.
This commit is contained in:
@@ -69,7 +69,9 @@ class BudgetTracker:
|
||||
else 0
|
||||
)
|
||||
|
||||
is_warning = max(token_usage_ratio, cost_usage_ratio) >= self.warning_threshold
|
||||
is_warning = (
|
||||
max(token_usage_ratio, cost_usage_ratio) >= self.warning_threshold
|
||||
)
|
||||
is_exceeded = (
|
||||
self._tokens_used >= self.tokens_limit
|
||||
or self._cost_used_usd >= self.cost_limit_usd
|
||||
@@ -94,12 +96,16 @@ class BudgetTracker:
|
||||
reset_at=reset_at,
|
||||
)
|
||||
|
||||
async def check_budget(self, estimated_tokens: int, estimated_cost_usd: float) -> bool:
|
||||
async def check_budget(
|
||||
self, estimated_tokens: int, estimated_cost_usd: float
|
||||
) -> bool:
|
||||
"""Check if there's enough budget for an operation."""
|
||||
async with self._lock:
|
||||
self._check_reset()
|
||||
|
||||
would_exceed_tokens = (self._tokens_used + estimated_tokens) > self.tokens_limit
|
||||
would_exceed_tokens = (
|
||||
self._tokens_used + estimated_tokens
|
||||
) > self.tokens_limit
|
||||
would_exceed_cost = (
|
||||
self._cost_used_usd + estimated_cost_usd
|
||||
) > self.cost_limit_usd
|
||||
@@ -241,13 +247,13 @@ class CostController:
|
||||
session_tracker = await self.get_or_create_tracker(
|
||||
BudgetScope.SESSION, session_id
|
||||
)
|
||||
if not await session_tracker.check_budget(estimated_tokens, estimated_cost_usd):
|
||||
if not await session_tracker.check_budget(
|
||||
estimated_tokens, estimated_cost_usd
|
||||
):
|
||||
return False
|
||||
|
||||
# Check agent daily budget
|
||||
agent_tracker = await self.get_or_create_tracker(
|
||||
BudgetScope.DAILY, agent_id
|
||||
)
|
||||
agent_tracker = await self.get_or_create_tracker(BudgetScope.DAILY, agent_id)
|
||||
if not await agent_tracker.check_budget(estimated_tokens, estimated_cost_usd):
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user