Files
onyx/backend/danswer/server/token_rate_limits/models.py
T
Alan Hagedorn d7a704c0d9 Token Rate Limiting
WIP

Cleanup 🧹

Remove existing rate limiting logic

Cleanup 🧼

Undo nit

Cleanup 🧽

Move db constants (avoids circular import)

WIP

WIP

Cleanup

Lint

Resolve alembic conflict

Fix mypy

Add backfill to migration

Update comment

Make unauthenticated users still adhere to global limits

Use Depends

Remove enum from table

Update migration error handling + deletion

Address verbal feedback, cleanup urls, minor nits
2024-06-25 15:07:56 -07:00

26 lines
631 B
Python

from pydantic import BaseModel
from danswer.db.models import TokenRateLimit
class TokenRateLimitArgs(BaseModel):
enabled: bool
token_budget: int
period_hours: int
class TokenRateLimitDisplay(BaseModel):
token_id: int
enabled: bool
token_budget: int
period_hours: int
@classmethod
def from_db(cls, token_rate_limit: TokenRateLimit) -> "TokenRateLimitDisplay":
return cls(
token_id=token_rate_limit.id,
enabled=token_rate_limit.enabled,
token_budget=token_rate_limit.token_budget,
period_hours=token_rate_limit.period_hours,
)