mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
feat(proxy_server.py): enable new /team/disable
endpoint
reject all requests from this team id, without deleting it.
This commit is contained in:
parent
ea8f6672c5
commit
4f7ba902d8
5 changed files with 35 additions and 6 deletions
|
@ -396,6 +396,7 @@ class TeamBase(LiteLLMBase):
|
||||||
rpm_limit: Optional[int] = None
|
rpm_limit: Optional[int] = None
|
||||||
max_budget: Optional[float] = None
|
max_budget: Optional[float] = None
|
||||||
models: list = []
|
models: list = []
|
||||||
|
disabled: bool = False
|
||||||
|
|
||||||
|
|
||||||
class NewTeamRequest(TeamBase):
|
class NewTeamRequest(TeamBase):
|
||||||
|
|
|
@ -30,12 +30,17 @@ def common_checks(
|
||||||
"""
|
"""
|
||||||
Common checks across jwt + key-based auth.
|
Common checks across jwt + key-based auth.
|
||||||
|
|
||||||
1. If user can call model
|
1. If team is disabled
|
||||||
2. If user is in budget
|
2. If team can call model
|
||||||
3. If end_user ('user' passed to /chat/completions, /embeddings endpoint) is in budget
|
3. If team is in budget
|
||||||
|
4. If end_user ('user' passed to /chat/completions, /embeddings endpoint) is in budget
|
||||||
"""
|
"""
|
||||||
_model = request_body.get("model", None)
|
_model = request_body.get("model", None)
|
||||||
# 1. If user can call model
|
if team_object.disabled == True:
|
||||||
|
raise Exception(
|
||||||
|
f"Team={team_object.team_id} is disabled. Update via `/team/update`."
|
||||||
|
)
|
||||||
|
# 2. If user can call model
|
||||||
if (
|
if (
|
||||||
_model is not None
|
_model is not None
|
||||||
and len(team_object.models) > 0
|
and len(team_object.models) > 0
|
||||||
|
@ -44,7 +49,7 @@ def common_checks(
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Team={team_object.team_id} not allowed to call model={_model}. Allowed team models = {team_object.models}"
|
f"Team={team_object.team_id} not allowed to call model={_model}. Allowed team models = {team_object.models}"
|
||||||
)
|
)
|
||||||
# 2. If team is in budget
|
# 3. If team is in budget
|
||||||
if (
|
if (
|
||||||
team_object.max_budget is not None
|
team_object.max_budget is not None
|
||||||
and team_object.spend is not None
|
and team_object.spend is not None
|
||||||
|
@ -53,7 +58,7 @@ def common_checks(
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Team={team_object.team_id} over budget. Spend={team_object.spend}, Budget={team_object.max_budget}"
|
f"Team={team_object.team_id} over budget. Spend={team_object.spend}, Budget={team_object.max_budget}"
|
||||||
)
|
)
|
||||||
# 3. If end_user ('user' passed to /chat/completions, /embeddings endpoint) is in budget
|
# 4. If end_user ('user' passed to /chat/completions, /embeddings endpoint) is in budget
|
||||||
if end_user_object is not None and end_user_object.litellm_budget_table is not None:
|
if end_user_object is not None and end_user_object.litellm_budget_table is not None:
|
||||||
end_user_budget = end_user_object.litellm_budget_table.max_budget
|
end_user_budget = end_user_object.litellm_budget_table.max_budget
|
||||||
if end_user_budget is not None and end_user_object.spend > end_user_budget:
|
if end_user_budget is not None and end_user_object.spend > end_user_budget:
|
||||||
|
|
|
@ -6151,6 +6151,26 @@ async def team_info(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/team/disable", tags=["team management"], dependencies=[Depends(user_api_key_auth)]
|
||||||
|
)
|
||||||
|
async def disable_team(
|
||||||
|
data: DeleteTeamRequest,
|
||||||
|
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Sets
|
||||||
|
"""
|
||||||
|
global prisma_client
|
||||||
|
|
||||||
|
if prisma_client is None:
|
||||||
|
raise Exception("No DB Connected.")
|
||||||
|
|
||||||
|
await prisma_client.db.litellm_teamtable.update_many(
|
||||||
|
where={"team_id": {"in": data.team_ids}}, data={"disabled": True}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#### ORGANIZATION MANAGEMENT ####
|
#### ORGANIZATION MANAGEMENT ####
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ model LiteLLM_TeamTable {
|
||||||
max_parallel_requests Int?
|
max_parallel_requests Int?
|
||||||
tpm_limit BigInt?
|
tpm_limit BigInt?
|
||||||
rpm_limit BigInt?
|
rpm_limit BigInt?
|
||||||
|
disabled Boolean @default(false)
|
||||||
budget_duration String?
|
budget_duration String?
|
||||||
budget_reset_at DateTime?
|
budget_reset_at DateTime?
|
||||||
created_at DateTime @default(now()) @map("created_at")
|
created_at DateTime @default(now()) @map("created_at")
|
||||||
|
|
|
@ -55,6 +55,7 @@ model LiteLLM_ModelTable {
|
||||||
team LiteLLM_TeamTable?
|
team LiteLLM_TeamTable?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Assign prod keys to groups, not individuals
|
// Assign prod keys to groups, not individuals
|
||||||
model LiteLLM_TeamTable {
|
model LiteLLM_TeamTable {
|
||||||
team_id String @id @default(uuid())
|
team_id String @id @default(uuid())
|
||||||
|
@ -72,6 +73,7 @@ model LiteLLM_TeamTable {
|
||||||
rpm_limit BigInt?
|
rpm_limit BigInt?
|
||||||
budget_duration String?
|
budget_duration String?
|
||||||
budget_reset_at DateTime?
|
budget_reset_at DateTime?
|
||||||
|
disabled Boolean @default(false)
|
||||||
created_at DateTime @default(now()) @map("created_at")
|
created_at DateTime @default(now()) @map("created_at")
|
||||||
updated_at DateTime @default(now()) @updatedAt @map("updated_at")
|
updated_at DateTime @default(now()) @updatedAt @map("updated_at")
|
||||||
model_spend Json @default("{}")
|
model_spend Json @default("{}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue