ModelEngine-Group / ModelEngine-Group/nexent
`get_model_name_from_config` raises `KeyError` instead of returning empty string
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.9k
- Forks
- 731
- Avg merge
- 19h 34m
- Merged PRs (30d)
- 172
Description
backend/utils/config_utils.py:41-49:
def get_model_name_from_config(model_config: Dict[str, Any]) -> str:
"""Get model name from model id"""
if model_config is None:
return ""
model_repo = model_config["model_repo"]
model_name = model_config["model_name"]
if not model_repo:
return model_name
return f"{model_repo}/{model_name}"
The function defends against None but not against partial dicts. Two callers — backend/utils/llm_utils.py:77 (OpenAIModel(model_id=get_model_name_from_config(llm_model_config) if llm_model_config else "")) and backend/utils/memory_utils.py:47, 55 — pass dicts that come straight from tenant_config_manager.get_model_config(). That manager returns default={} whenever the model id can't be parsed (config_utils.py:101), which means a sneaky path exists where you get an {} dict rather than None, and accessing model_config["model_repo"] then raises KeyError.
Concrete repro: configure a tenant with a non-numeric LLM_ID. get_model_config returns default which the caller may have passed as {} or as a partial dict like {"model_name": "x"}. The next call into get_model_name_from_config blows up.
Suggested fix
def get_model_name_from_config(model_config: Dict[str, Any]) -> str:
if not model_config:
return ""
model_repo = model_config.get("model_repo") or ""
model_name = model_config.get("model_name") or ""
if not model_repo:
return model_name
return f"{model_repo}/{model_name}"
Severity: Medium. The crash propagates up and the user sees a 500.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in backend/utils/config_utils.py:41-49 and trace the callers in backend/utils/llm_utils.py:77 and backend/utils/memory_utils.py:47,55. Reproduce the failure with a non-numeric LLM_ID, then verify that empty or partial model configuration dictionaries return an empty or usable model name without raising KeyError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100