1
0

fix: make model fallback chains configurable (#53)

Move hardcoded model fallback lists from module-level constants into
settings.fallback_models and settings.vision_fallback_models (pydantic
Settings fields). Can now be overridden via env vars
FALLBACK_MODELS / VISION_FALLBACK_MODELS or config/providers.yaml.

Removed:
- OLLAMA_MODEL_PRIMARY / OLLAMA_MODEL_FALLBACK from config.py
- DEFAULT_MODEL_FALLBACKS / VISION_MODEL_FALLBACKS from agent.py

get_effective_ollama_model() and _resolve_model_with_fallback() now
walk the configurable chains instead of hardcoded constants.

5 new tests guard the configurable behavior and prevent regression
to hardcoded constants.
This commit is contained in:
2026-03-14 17:26:47 -04:00
parent f097784de8
commit 94cd1a9840
4 changed files with 120 additions and 43 deletions

View File

@@ -33,7 +33,8 @@ async def test_ollama_connection():
@pytest.mark.asyncio
async def test_model_fallback_chain():
"""Test that the model fallback chain works correctly."""
from timmy.agent import DEFAULT_MODEL_FALLBACKS, _resolve_model_with_fallback
from config import settings
from timmy.agent import _resolve_model_with_fallback
# Test with a non-existent model
model, is_fallback = _resolve_model_with_fallback(
@@ -46,7 +47,7 @@ async def test_model_fallback_chain():
# or the last resort (the requested model itself if nothing else is available).
# In tests, if no models are available in the mock environment, it might return the requested model.
if is_fallback:
assert model in DEFAULT_MODEL_FALLBACKS
assert model in settings.fallback_models
else:
# If no fallbacks were available, it returns the requested model as last resort
assert model == "nonexistent-model"