Merge pull request #22740 from BerriAI/litellm_fix_file_wild_card
Add support for wildcards models for files api
This commit is contained in:
commit
db0d5588fa
@ -7105,6 +7105,17 @@ class Router:
|
||||
model_group_name=model_id
|
||||
)
|
||||
|
||||
# If still not found, check for wildcard pattern matches
|
||||
if deployment is None:
|
||||
potential_wildcard_models = self.pattern_router.route(model_id) or []
|
||||
if potential_wildcard_models:
|
||||
# Use the first matching wildcard deployment
|
||||
deployment_dict = potential_wildcard_models[0]
|
||||
if isinstance(deployment_dict, dict):
|
||||
deployment = Deployment(**deployment_dict)
|
||||
elif isinstance(deployment_dict, Deployment):
|
||||
deployment = deployment_dict
|
||||
|
||||
if deployment is None:
|
||||
return None
|
||||
|
||||
|
||||
@ -502,6 +502,53 @@ def test_router_get_deployment_credentials_with_provider():
|
||||
assert credentials3 is None
|
||||
|
||||
|
||||
def test_router_get_deployment_credentials_with_provider_wildcard():
|
||||
"""
|
||||
Test that get_deployment_credentials_with_provider handles wildcard patterns.
|
||||
|
||||
When a model like openai/gpt-4o is requested and the config has openai/*,
|
||||
the method should resolve the wildcard pattern and return credentials.
|
||||
"""
|
||||
router = Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "openai/*",
|
||||
"litellm_params": {
|
||||
"model": "openai/*",
|
||||
"api_key": "sk-wildcard-123",
|
||||
"api_base": "https://api.openai.com/v1",
|
||||
},
|
||||
"model_info": {"id": "openai-wildcard-deployment"},
|
||||
},
|
||||
{
|
||||
"model_name": "anthropic/*",
|
||||
"litellm_params": {
|
||||
"model": "anthropic/*",
|
||||
"api_key": "sk-ant-wildcard-456",
|
||||
},
|
||||
"model_info": {"id": "anthropic-wildcard-deployment"},
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
# Test wildcard pattern matching for OpenAI
|
||||
credentials = router.get_deployment_credentials_with_provider(model_id="openai/gpt-4o")
|
||||
assert credentials is not None
|
||||
assert credentials["api_key"] == "sk-wildcard-123"
|
||||
assert credentials["custom_llm_provider"] == "openai"
|
||||
assert credentials["api_base"] == "https://api.openai.com/v1"
|
||||
|
||||
# Test wildcard pattern matching for Anthropic
|
||||
credentials2 = router.get_deployment_credentials_with_provider(model_id="anthropic/claude-3-opus")
|
||||
assert credentials2 is not None
|
||||
assert credentials2["api_key"] == "sk-ant-wildcard-456"
|
||||
assert credentials2["custom_llm_provider"] == "anthropic"
|
||||
|
||||
# Test with non-matching model
|
||||
credentials3 = router.get_deployment_credentials_with_provider(model_id="vertex_ai/gemini-pro")
|
||||
assert credentials3 is None
|
||||
|
||||
|
||||
def test_router_get_deployment_model_info():
|
||||
router = Router(
|
||||
model_list=[
|
||||
|
||||
Loading…
Reference in New Issue
Block a user