Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion litellm/proxy/management_endpoints/team_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3550,7 +3550,7 @@ async def team_info(
try:
team_info: Optional[BaseModel] = await TeamRepository(prisma_client).table.find_unique(
where={"team_id": team_id},
include={"object_permission": True},
include={"litellm_model_table": True, "object_permission": True},
)
if team_info is None:
raise Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from litellm.proxy._types import UserAPIKeyAuth # Import UserAPIKeyAuth
from litellm.proxy._types import (
LiteLLM_BudgetTableFull,
LiteLLM_ModelTable,
LiteLLM_OrganizationMembershipTable,
LiteLLM_OrganizationTable,
LiteLLM_OrganizationTableWithMembers,
Expand All @@ -30,6 +31,7 @@
ProxyErrorTypes,
ProxyException,
TeamMemberAddRequest,
UpdateTeamRequest,
)
from litellm.proxy.management_endpoints.team_endpoints import (
user_api_key_auth, # Assuming this dependency is needed
Expand All @@ -40,6 +42,7 @@
_persist_deleted_team_records,
_save_deleted_team_records,
_transform_teams_to_deleted_records,
_update_model_table,
_validate_and_populate_member_user_info,
_verify_team_access,
delete_team,
Expand Down Expand Up @@ -9436,6 +9439,96 @@ async def test_team_info_forwards_key_limit_to_get_data():
assert mock_prisma.get_data.await_args.kwargs["limit"] == 7


@pytest.mark.asyncio
async def test_team_info_returns_model_aliases():
"""/team/info must join LiteLLM_ModelTable so the response exposes the team's
current model aliases; without the ``litellm_model_table`` include the field
comes back null and the Admin UI can never display them.
"""
from fastapi import Request

from litellm.proxy.management_endpoints import team_endpoints

team_row = LiteLLM_TeamTable(
team_id="team-1",
litellm_model_table=LiteLLM_ModelTable(
id=1,
model_aliases={"gpt-4o": "gpt-4o-team-1"},
created_by="admin",
updated_by="admin",
),
)

mock_prisma = MagicMock()
mock_prisma.db.litellm_teamtable.find_unique = AsyncMock(return_value=team_row)
mock_prisma.get_data = AsyncMock(return_value=[])

with (
patch("litellm.proxy.proxy_server.prisma_client", mock_prisma),
patch.object(
team_endpoints, "get_all_team_memberships", AsyncMock(return_value=[])
),
):
response = await team_endpoints.team_info(
http_request=MagicMock(spec=Request),
team_id="team-1",
user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN),
)

include = mock_prisma.db.litellm_teamtable.find_unique.await_args.kwargs["include"]
assert include["litellm_model_table"] is True

litellm_model_table = response["team_info"].litellm_model_table
assert litellm_model_table is not None
assert litellm_model_table.model_aliases == {"gpt-4o": "gpt-4o-team-1"}


@pytest.mark.asyncio
async def test_update_model_table_clears_aliases_with_empty_map():
"""``model_aliases={}`` on /team/update must persist an empty map (json.dumps({}))
so existing aliases are cleared, while ``model_aliases=None`` must be a no-op that
leaves the model table untouched.
"""
mock_prisma = MagicMock()
mock_prisma.db.litellm_modeltable.create = AsyncMock()
mock_prisma.db.litellm_modeltable.upsert = AsyncMock(
return_value=MagicMock(id="model-123")
)
user_api_key_dict = UserAPIKeyAuth(
user_role=LitellmUserRoles.PROXY_ADMIN, user_id="admin"
)

returned_model_id = await _update_model_table(
data=UpdateTeamRequest(team_id="team-1", model_aliases={}),
model_id="model-123",
prisma_client=mock_prisma,
user_api_key_dict=user_api_key_dict,
litellm_proxy_admin_name="default_user_id",
)

mock_prisma.db.litellm_modeltable.upsert.assert_awaited_once()
upsert_kwargs = mock_prisma.db.litellm_modeltable.upsert.await_args.kwargs
assert upsert_kwargs["where"] == {"id": "model-123"}
assert upsert_kwargs["data"]["update"]["model_aliases"] == json.dumps({})
assert upsert_kwargs["data"]["create"]["model_aliases"] == json.dumps({})
assert returned_model_id == "model-123"

mock_prisma.db.litellm_modeltable.create.reset_mock()
mock_prisma.db.litellm_modeltable.upsert.reset_mock()

noop_model_id = await _update_model_table(
data=UpdateTeamRequest(team_id="team-1", model_aliases=None),
model_id="model-123",
prisma_client=mock_prisma,
user_api_key_dict=user_api_key_dict,
litellm_proxy_admin_name="default_user_id",
)

mock_prisma.db.litellm_modeltable.create.assert_not_called()
mock_prisma.db.litellm_modeltable.upsert.assert_not_called()
assert noop_model_id == "model-123"


class TestEmitTeamMembersMetric:
"""The _emit_team_members_metric seam between the team handlers and Prometheus."""

Expand Down
2 changes: 1 addition & 1 deletion ui/litellm-dashboard/e2e_tests/helpers/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function dismissFeedbackPopup(page: PlaywrightPage): Promise<void>
/**
* Click on a team ID in the table. Team IDs are rendered differently depending
* on the component version — try button first (Tremor Button), fall back to
* clickable span (OldTeams Typography.Text).
* clickable span (Teams Typography.Text).
*/
export async function clickTeamId(page: PlaywrightPage, teamId: string): Promise<void> {
const cell = page.locator("td").filter({ hasText: teamId }).first();
Expand Down
32 changes: 16 additions & 16 deletions ui/litellm-dashboard/eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1400,22 +1400,6 @@
"count": 1
}
},
"src/components/OldTeams.test.tsx": {
"max-nested-callbacks": {
"count": 4
}
},
"src/components/OldTeams.tsx": {
"no-nested-ternary": {
"count": 4
},
"no-restricted-imports": {
"count": 1
},
"react-hooks/set-state-in-effect": {
"count": 4
}
},
"src/components/SCIM.tsx": {
"no-restricted-imports": {
"count": 1
Expand Down Expand Up @@ -1506,6 +1490,22 @@
"count": 1
}
},
"src/components/Teams.test.tsx": {
"max-nested-callbacks": {
"count": 4
}
},
"src/components/Teams.tsx": {
"no-nested-ternary": {
"count": 4
},
"no-restricted-imports": {
"count": 1
},
"react-hooks/set-state-in-effect": {
"count": 4
}
},
"src/components/ToolDetail.tsx": {
"unused-imports/no-unused-imports": {
"count": 2
Expand Down
4 changes: 2 additions & 2 deletions ui/litellm-dashboard/src/app/(dashboard)/teams/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import OldTeams from "@/components/OldTeams";
import Teams from "@/components/Teams";
import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";

export default function TeamsPage() {
const { accessToken, userId, userRole, premiumUser } = useAuthorized();
return <OldTeams accessToken={accessToken} userID={userId} userRole={userRole} premiumUser={premiumUser ?? false} />;
return <Teams accessToken={accessToken} userID={userId} userRole={userRole} premiumUser={premiumUser ?? false} />;
}
Loading
Loading