mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
LLM: normalize_model_name – restrict Bedrock dot-prefix collapsing to anthropic.* and *.anthropic.* only; avoid unintended side-effects
- Keep 'anthropic.' if already present - Collapse region prefixes like 'us.anthropic.*' to 'anthropic.*' - Leave other vendors untouched Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
parent
f889ae4438
commit
d490b72f7f
@ -15,8 +15,10 @@ def normalize_model_name(model: str) -> str:
|
||||
and treat ':' inside that basename as an Ollama-style variant tag to be removed
|
||||
- There is no provider:model form; providers, when present, use 'provider/model'
|
||||
- Drop a trailing "-gguf" suffix if present
|
||||
- Drop embedded vendor prefixes of the form "vendor.model" in the basename
|
||||
for known vendors (e.g., Bedrock "anthropic.claude-*")
|
||||
- Only strip region prefixes before Anthropic Bedrock-style dot vendor.
|
||||
Keep 'anthropic.' if present; collapse '*.anthropic.' -> 'anthropic.'.
|
||||
Example: 'us.anthropic.claude-*' -> 'anthropic.claude-*'.
|
||||
Other vendors are left untouched to avoid unintended side-effects.
|
||||
"""
|
||||
raw = (model or '').strip().lower()
|
||||
if '/' in raw:
|
||||
@ -28,22 +30,15 @@ def normalize_model_name(model: str) -> str:
|
||||
# No '/', keep the whole raw name (we do not support provider:model)
|
||||
name = raw
|
||||
|
||||
# Drop common vendor prefixes embedded in the basename (Bedrock style),
|
||||
# including optional region prefixes like 'us.anthropic.*' -> 'claude-*'.
|
||||
vendor_prefixes = {
|
||||
'anthropic',
|
||||
'meta',
|
||||
'cohere',
|
||||
'mistral',
|
||||
'ai21',
|
||||
'amazon',
|
||||
}
|
||||
# Collapse only Bedrock-style region prefixes before Anthropic vendor.
|
||||
# Keep 'anthropic.' if it's already the prefix; collapse '*.anthropic.' -> 'anthropic.'
|
||||
if '.' in name:
|
||||
tokens = name.split('.')
|
||||
for idx, token in enumerate(tokens):
|
||||
if token in vendor_prefixes and idx + 1 < len(tokens):
|
||||
name = '.'.join(tokens[idx + 1 :])
|
||||
break
|
||||
vendor = 'anthropic.'
|
||||
i = name.find(vendor)
|
||||
if i > 0:
|
||||
# e.g., 'us.anthropic.claude-*' -> 'anthropic.claude-*'
|
||||
name = name[i:]
|
||||
# if i == 0 -> already starts with 'anthropic.', leave as-is
|
||||
|
||||
if name.endswith('-gguf'):
|
||||
name = name[: -len('-gguf')]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user