(feat) create soft budget

This commit is contained in:
ishaan-jaff 2024-03-02 12:52:09 -08:00
parent b042b5dc3b
commit eb4f90115d
2 changed files with 29 additions and 0 deletions

View file

@ -324,6 +324,21 @@ class TeamRequest(LiteLLMBase):
teams: List[str] teams: List[str]
class LiteLLM_BudgetTable(LiteLLMBase):
"""Represents user-controllable params for a LiteLLM_BudgetTable record"""
max_budget: Optional[float] = None
soft_budget: Optional[float] = None
max_parallel_requests: Optional[int] = None
tpm_limit: Optional[int] = None
rpm_limit: Optional[int] = None
model_max_budget: dict
budget_duration: Optional[str] = None
budget_reset_at: Optional[datetime] = None
created_by: str
updated_by: str
class KeyManagementSystem(enum.Enum): class KeyManagementSystem(enum.Enum):
GOOGLE_KMS = "google_kms" GOOGLE_KMS = "google_kms"
AZURE_KEY_VAULT = "azure_key_vault" AZURE_KEY_VAULT = "azure_key_vault"

View file

@ -1869,6 +1869,19 @@ async def generate_key_helper_fn(
rpm_limit = rpm_limit rpm_limit = rpm_limit
allowed_cache_controls = allowed_cache_controls allowed_cache_controls = allowed_cache_controls
# TODO: @ishaan-jaff: Migrate all budget tracking to use LiteLLM_BudgetTable
if prisma_client is not None:
# create the Budget Row for the LiteLLM Verification Token
budget_row = LiteLLM_BudgetTable(
soft_budget=50,
model_max_budget=model_max_budget or {},
created_by=user_id,
updated_by=user_id,
)
new_budget = prisma_client.jsonify_object(budget_row.json(exclude_none=True))
_budget = await prisma_client.db.litellm_budgettable.create(data={**new_budget}) # type: ignore
_budget_id = getattr(_budget, "id", None)
try: try:
# Create a new verification token (you may want to enhance this logic based on your needs) # Create a new verification token (you may want to enhance this logic based on your needs)
user_data = { user_data = {
@ -1906,6 +1919,7 @@ async def generate_key_helper_fn(
"allowed_cache_controls": allowed_cache_controls, "allowed_cache_controls": allowed_cache_controls,
"permissions": permissions_json, "permissions": permissions_json,
"model_max_budget": model_max_budget_json, "model_max_budget": model_max_budget_json,
"budget_id": _budget_id,
} }
if ( if (
general_settings.get("allow_user_auth", False) == True general_settings.get("allow_user_auth", False) == True