Skip to content

Commit

Permalink
[Fix] Tag Based Routing not work with wildcard routing (BerriAI#5805)
Browse files Browse the repository at this point in the history
* allow using tag routing for free

* only enforce tags for teams / keys
  • Loading branch information
ishaan-jaff authored Sep 20, 2024
1 parent 3933fba commit 036fce8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
11 changes: 2 additions & 9 deletions litellm/proxy/litellm_pre_call_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,8 @@ async def add_litellm_data_to_request(

# Enterprise Only - Check if using tag based routing
if llm_router and llm_router.enable_tag_filtering is True:
if premium_user is not True:
verbose_proxy_logger.warning(
"router.enable_tag_filtering is on %s \n switched off router.enable_tag_filtering",
CommonProxyErrors.not_premium_user.value,
)
llm_router.enable_tag_filtering = False
else:
if "tags" in data:
data[_metadata_variable_name]["tags"] = data["tags"]
if "tags" in data:
data[_metadata_variable_name]["tags"] = data["tags"]

### TEAM-SPECIFIC PARAMS ###
if user_api_key_dict.team_id is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ async def generate_key_fn(

# Set tags on the new key
if "tags" in data_json:
from litellm.proxy.proxy_server import premium_user

if premium_user is not True:
raise ValueError(
f"Only premium users can add tags to teams. {CommonProxyErrors.not_premium_user.value}"
)

if data_json["metadata"] is None:
data_json["metadata"] = {"tags": data_json["tags"]}
else:
Expand Down
12 changes: 12 additions & 0 deletions litellm/proxy/management_endpoints/team_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ async def new_team(

# Set tags on the new team
if data.tags is not None:
from litellm.proxy.proxy_server import premium_user

if premium_user is not True:
raise ValueError(
f"Only premium users can add tags to teams. {CommonProxyErrors.not_premium_user.value}"
)
if complete_team_data.metadata is None:
complete_team_data.metadata = {"tags": data.tags}
else:
Expand Down Expand Up @@ -381,6 +387,12 @@ async def update_team(

# check if user is trying to update tags for team
if "tags" in updated_kv and updated_kv["tags"] is not None:
from litellm.proxy.proxy_server import premium_user

if premium_user is not True:
raise ValueError(
f"Only premium users can add tags to teams. {CommonProxyErrors.not_premium_user.value}"
)
# remove tags from updated_kv
_tags = updated_kv.pop("tags")
if "metadata" in updated_kv and updated_kv["metadata"] is not None:
Expand Down

0 comments on commit 036fce8

Please sign in to comment.