From dc062059649f2c3e7d966045349115ace118cf46 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 21 Feb 2024 13:25:52 -0800 Subject: [PATCH 1/3] (fix) ui allow users to make ui chat requests --- litellm/proxy/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 3cad1777c..34a77a973 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -1465,6 +1465,20 @@ def _is_user_proxy_admin(user_id_information=None): and _user.get("user_role") == "proxy_admin" ): return True + + # if user_id_information contains litellm-proxy-budget + # get first user_id that is not litellm-proxy-budget + for user in user_id_information: + if user.get("user_id") != "litellm-proxy-budget": + _user = user + break + + if ( + _user.get("user_role", None) is not None + and _user.get("user_role") == "proxy_admin" + ): + return True + return False From 6a7250a84c9048a1eb799d2dfac73ccf0ce595e7 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 21 Feb 2024 13:29:55 -0800 Subject: [PATCH 2/3] (fix) admin ui with UI_Username --- litellm/proxy/proxy_server.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index f615232b7..2006683b0 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -5008,10 +5008,19 @@ async def login(request: Request): # checks if user is admin user_role = "app_admin" key_user_id = os.getenv("PROXY_ADMIN_ID", "default_user_id") + # Admin is Authe'd in - generate key for the UI to access Proxy + + # ensure this user is set as the proxy admin, in this route there is no sso, we can assume this user is only the admin + await user_update( + data=UpdateUserRequest( + user_id=key_user_id, + user_role="proxy_admin", + ) + ) if os.getenv("DATABASE_URL") is not None: response = await generate_key_helper_fn( - **{"duration": "1hr", "key_max_budget": 0, "models": [], "aliases": {}, "config": {}, "spend": 0, "user_id": key_user_id, "team_id": "litellm-dashboard"} # type: ignore + **{"user_role": "proxy_admin", "duration": "1hr", "key_max_budget": 5, "models": [], "aliases": {}, "config": {}, "spend": 0, "user_id": key_user_id, "team_id": "litellm-dashboard"} # type: ignore ) else: response = { @@ -5027,7 +5036,7 @@ async def login(request: Request): "user_id": user_id, "key": key, "user_email": user_id, - "user_role": user_role, + "user_role": "app_admin", # this is the path without sso - we can assume only admins will use this }, "secret", algorithm="HS256", From 62b415a7d5c4e13ac11b2cee5e482e64a645cd3b Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 21 Feb 2024 13:35:06 -0800 Subject: [PATCH 3/3] (fix) use UI USERNAME --- litellm/proxy/proxy_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 2006683b0..f086ebc70 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -5028,7 +5028,7 @@ async def login(request: Request): "user_id": "litellm-dashboard", } key = response["token"] # type: ignore - litellm_dashboard_ui = os.getenv("PROXY_BASE_URL", "/") + "ui/" + litellm_dashboard_ui = os.getenv("PROXY_BASE_URL", "") + "/ui/" import jwt jwt_token = jwt.encode(