Repository navigation
fix(llm): safely resolve provider and model with enum and fallback support - #51
Open
nandhakumar-murugan wants to merge 1 commit into
Open
nandhakumar-murugan wants to merge 1 commit into
nandhakumar-murugan wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
artemis/services/llm.py,_resolve_endpointextractedprovider_valandmodel_valusing baregetattr(cfg, "provider", "google")andgetattr(cfg, "model", "gemini-2.5-flash"). Whencfghad mock or non-string attributes (e.g., in unit tests),getattrreturned the mock attribute instead of falling back to default values, leading toValueError: Unknown LLM provider <MagicMock ...>._resolve_endpointto 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).tests/unit/test_llm_gateway.pyverifying 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.