mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
Merge 3d7d8f69f4 into bd7e9c1997
This commit is contained in:
commit
1da04b93f9
2 changed files with 48 additions and 2 deletions
|
|
@ -13,7 +13,7 @@ from litellm.router import Router
|
|||
from litellm.router_utils.fallback_event_handlers import get_fallback_model_group
|
||||
from litellm.types.router import CredentialLiteLLMParams, LiteLLM_Params
|
||||
from litellm.types.utils import LlmProviders
|
||||
from litellm.utils import get_valid_models
|
||||
from litellm.utils import ProviderConfigManager, get_valid_models
|
||||
|
||||
_CREDENTIAL_LITELLM_PARAM_FIELDS = set(CredentialLiteLLMParams.model_fields)
|
||||
|
||||
|
|
@ -45,7 +45,18 @@ def get_provider_models(provider: str, litellm_params: LiteLLM_Params | None = N
|
|||
if provider in litellm.models_by_provider:
|
||||
provider_models: Final = get_valid_models(custom_llm_provider=provider, litellm_params=litellm_params)
|
||||
return provider_models
|
||||
return None
|
||||
|
||||
# Providers with no static catalog (litellm_proxy, hosted_vllm, ollama, ...) are absent
|
||||
# from models_by_provider by design: their model list only exists behind the provider's
|
||||
# own endpoint. ProviderConfigManager still knows about them, so admit them here instead
|
||||
# of returning None before endpoint discovery is ever attempted.
|
||||
try:
|
||||
llm_provider: Final = LlmProviders(provider)
|
||||
except ValueError:
|
||||
return None
|
||||
if ProviderConfigManager.get_provider_model_info(model=None, provider=llm_provider) is None:
|
||||
return None
|
||||
return get_valid_models(custom_llm_provider=provider, litellm_params=litellm_params)
|
||||
|
||||
|
||||
def _get_models_from_access_groups(
|
||||
|
|
|
|||
|
|
@ -803,3 +803,38 @@ def test_get_complete_model_list_sentinel_only_grants_nothing():
|
|||
infer_model_from_keys=False,
|
||||
)
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_get_provider_models_admits_providers_without_a_static_catalog():
|
||||
"""litellm_proxy and hosted_vllm have no entry in litellm.models_by_provider
|
||||
(their model list only exists behind the provider's own endpoint), so the
|
||||
static-dict gate must not reject them before endpoint discovery runs.
|
||||
|
||||
Regression check only, not a discovery test: with check_provider_endpoint
|
||||
left at its default (off), get_valid_models never reaches the network and
|
||||
falls back to models_by_provider.get(provider, []) -- an empty list, not
|
||||
None. Before the fix, the gate itself returned None for these providers.
|
||||
"""
|
||||
import litellm
|
||||
from litellm.proxy.auth.model_checks import get_provider_models
|
||||
from litellm.types.router import LiteLLM_Params
|
||||
|
||||
assert "litellm_proxy" not in litellm.models_by_provider
|
||||
assert "hosted_vllm" not in litellm.models_by_provider
|
||||
|
||||
result = get_provider_models(
|
||||
"litellm_proxy",
|
||||
litellm_params=LiteLLM_Params(
|
||||
model="litellm_proxy/*",
|
||||
api_base="http://upstream:4000",
|
||||
api_key="sk-upstream",
|
||||
),
|
||||
)
|
||||
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_get_provider_models_returns_none_for_an_unknown_provider():
|
||||
from litellm.proxy.auth.model_checks import get_provider_models
|
||||
|
||||
assert get_provider_models("not-a-real-provider") is None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue