Skip to content

fix(llm): safely resolve provider and model with enum and fallback support - #51

Open
nandhakumar-murugan wants to merge 1 commit into
google:mainfrom
nandhakumar-murugan:fix/llm-resolve-endpoint-robust-types
Open

nandhakumar-murugan wants to merge 1 commit into
google:mainfrom
nandhakumar-murugan:fix/llm-resolve-endpoint-robust-types

Conversation

@nandhakumar-murugan

Copy link
Copy Markdown

Summary of Changes

  • Fixes _resolve_endpoint raises ValueError when provider/model in agent config is not a string #33: In artemis/services/llm.py, _resolve_endpoint extracted provider_val and model_val using bare getattr(cfg, "provider", "google") and getattr(cfg, "model", "gemini-2.5-flash"). When cfg had mock or non-string attributes (e.g., in unit tests), getattr returned the mock attribute instead of falling back to default values, leading to ValueError: Unknown LLM provider <MagicMock ...>.
  • Updated _resolve_endpoint to use _get_val(cfg, "provider", (str, ModelProvider, Enum)) or "google" and _get_val(cfg, "model", (str, Enum)) or "gemini-2.5-flash". This cleanly discards invalid/mocked attributes while safely retaining both string names and enum instances (e.g. ModelProvider.OPENAI).
  • Added unit tests in tests/unit/test_llm_gateway.py verifying fallback for mock attributes as well as preservation of string and enum providers.

Verification

  • uv run pytest tests/unit/test_llm_gateway.py -v: 10/10 passed.
  • uv run ruff check artemis/services/llm.py tests/unit/test_llm_gateway.py: All checks passed.
  • uv run ruff format --check artemis/services/llm.py tests/unit/test_llm_gateway.py: 0 formatting issues.
  • uv run python scripts/quality_ratchet.py: Quality ratchet passed.

…pport

Use _get_val with (str, ModelProvider, Enum) in _resolve_endpoint to safely handle mocked or non-string attributes without discarding enum provider instances.

Fixes google#33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_resolve_endpoint raises ValueError when provider/model in agent config is not a string

1 participant