mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix: return the helpful error for a bare provider name in get_llm_provider
Passing a bare provider name (e.g. get_llm_provider('mistral')) hit the elif
that assumes a '/' and did model.split('/', 1)[1], raising IndexError that got
wrapped into 'GetLLMProvider Exception - list index out of range'. The sibling
if above it already guards this with len(model.split('/')) > 1 (added for issue
1351); the elif was missing the same guard. Add it so a bare provider name
falls through to the intended 'LLM Provider NOT provided' guidance.
This commit is contained in:
parent
cd6e8cdf23
commit
71007e0f0e
2 changed files with 13 additions and 1 deletions
|
|
@ -218,7 +218,7 @@ def get_llm_provider(
|
|||
dynamic_api_key=dynamic_api_key,
|
||||
litellm_params=litellm_params,
|
||||
)
|
||||
elif model.split("/", 1)[0] in litellm.provider_list:
|
||||
elif model.split("/", 1)[0] in litellm.provider_list and len(model.split("/")) > 1:
|
||||
custom_llm_provider = model.split("/", 1)[0]
|
||||
model = model.split("/", 1)[1]
|
||||
if api_base is not None and not isinstance(api_base, str):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
import pytest
|
||||
|
||||
import litellm
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", ["mistral", "openai", "anthropic", "groq", "deepseek"])
|
||||
def test_get_llm_provider_bare_provider_name_raises_helpful_error(model):
|
||||
with pytest.raises(litellm.BadRequestError) as exc_info:
|
||||
litellm.get_llm_provider(model=model)
|
||||
message = str(exc_info.value)
|
||||
assert "LLM Provider NOT provided" in message
|
||||
assert "list index out of range" not in message
|
||||
Loading…
Add table
Reference in a new issue