mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
(feat) create soft budget
This commit is contained in:
parent
b042b5dc3b
commit
eb4f90115d
2 changed files with 29 additions and 0 deletions
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue