mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-14 14:26:43 +00:00
_route_user_config_request fix
This commit is contained in:
@@ -12,6 +12,21 @@ else:
|
||||
LitellmRouter = Any
|
||||
|
||||
|
||||
def _route_user_config_request(data: dict, route_type: str):
|
||||
"""Route a request using the user-provided router config."""
|
||||
router_config = data.pop("user_config")
|
||||
|
||||
# Filter router_config to only include valid Router.__init__ arguments
|
||||
# This prevents TypeError when invalid parameters are stored in the database
|
||||
valid_args = litellm.Router.get_valid_args()
|
||||
filtered_config = {k: v for k, v in router_config.items() if k in valid_args}
|
||||
|
||||
user_router = litellm.Router(**filtered_config)
|
||||
ret_val = getattr(user_router, f"{route_type}")(**data)
|
||||
user_router.discard()
|
||||
return ret_val
|
||||
|
||||
|
||||
def _is_a2a_agent_model(model_name: Any) -> bool:
|
||||
"""Check if the model name is for an A2A agent (a2a/ prefix)."""
|
||||
return isinstance(model_name, str) and model_name.startswith("a2a/")
|
||||
@@ -211,17 +226,7 @@ async def route_request(
|
||||
return llm_router.abatch_completion(models=models, **data)
|
||||
|
||||
elif "user_config" in data:
|
||||
router_config = data.pop("user_config")
|
||||
|
||||
# Filter router_config to only include valid Router.__init__ arguments
|
||||
# This prevents TypeError when invalid parameters are stored in the database
|
||||
valid_args = litellm.Router.get_valid_args()
|
||||
filtered_config = {k: v for k, v in router_config.items() if k in valid_args}
|
||||
|
||||
user_router = litellm.Router(**filtered_config)
|
||||
ret_val = getattr(user_router, f"{route_type}")(**data)
|
||||
user_router.discard()
|
||||
return ret_val
|
||||
return _route_user_config_request(data, route_type)
|
||||
|
||||
elif "router_settings_override" in data:
|
||||
# Apply per-request router settings overrides from key/team config
|
||||
|
||||
Reference in New Issue
Block a user