Skip to content

Commit d27d5fe

Browse files
fix: require litellm provider registry for unverified provider parsing
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 86273f2 commit d27d5fe

File tree

2 files changed

+2
-48
lines changed

2 files changed

+2
-48
lines changed

openhands-sdk/openhands/sdk/llm/utils/unverified_models.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ def _split_is_actually_version(split: list[str]) -> bool:
8989

9090

9191
def _get_litellm_provider_names() -> set[str]:
92-
try:
93-
provider_list = litellm.provider_list
94-
except AttributeError:
95-
return set()
92+
provider_list = litellm.provider_list
9693

9794
result: set[str] = set()
9895

@@ -111,10 +108,6 @@ def _get_litellm_provider_names() -> set[str]:
111108
_LITELLM_PROVIDER_NAMES = _get_litellm_provider_names()
112109

113110

114-
def _has_provider_registry() -> bool:
115-
return bool(_LITELLM_PROVIDER_NAMES)
116-
117-
118111
def _extract_model_and_provider(model: str) -> tuple[str, str, str]:
119112
"""Extract provider and model information from a model identifier.
120113
@@ -151,10 +144,7 @@ def _extract_model_and_provider(model: str) -> tuple[str, str, str]:
151144
provider = split[0]
152145
model_id = separator.join(split[1:])
153146

154-
# If we have a provider registry, only accept known LiteLLM providers.
155-
# If not, fall back to the historical behavior to avoid dropping all
156-
# provider groupings in older LiteLLM versions.
157-
if _has_provider_registry() and provider not in _LITELLM_PROVIDER_NAMES:
147+
if provider not in _LITELLM_PROVIDER_NAMES:
158148
return "", model, ""
159149

160150
return provider, model_id, separator

tests/sdk/llm/test_model_list.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,6 @@ def test_organize_models_and_providers():
4444
assert "1024-x-1024/gpt-image-1.5" in result["other"]
4545

4646

47-
def test_unverified_models_fallback_when_no_provider_list():
48-
models = [
49-
"openai/gpt-4o", # treated as unverified (provider validation disabled)
50-
"anthropic/claude-sonnet-4-20250514", # treated as unverified
51-
"o3", # openhands model -> excluded
52-
"custom-provider/custom-model",
53-
"us.anthropic.claude-3-5-sonnet-20241022-v2:0",
54-
"1024-x-1024/gpt-image-1.5",
55-
]
56-
57-
with (
58-
patch(
59-
"openhands.sdk.llm.utils.unverified_models.get_supported_llm_models",
60-
return_value=models,
61-
),
62-
patch(
63-
"openhands.sdk.llm.utils.unverified_models._LITELLM_PROVIDER_NAMES",
64-
set(),
65-
),
66-
):
67-
result = get_unverified_models()
68-
69-
# Without provider validation, openai/anthropic entries are treated as
70-
# verified and therefore are excluded from the unverified mapping.
71-
assert "openai" not in result
72-
assert "anthropic" not in result
73-
74-
# When LiteLLM doesn't expose a provider registry, we keep historical behavior
75-
# (split on '/' or '.') rather than bucketing everything under "other".
76-
assert result == {
77-
"custom-provider": ["custom-model"],
78-
"us": ["anthropic.claude-3-5-sonnet-20241022-v2:0"],
79-
"1024-x-1024": ["gpt-image-1.5"],
80-
}
81-
82-
8347
def test_list_bedrock_models_without_boto3(monkeypatch):
8448
"""Should warn and return empty list if boto3 is missing."""
8549
# Pretend boto3 is not installed

0 commit comments

Comments
 (0)