Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/models/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from __future__ import annotations
from functools import lru_cache

import importlib
import logging
Expand Down Expand Up @@ -42,6 +43,8 @@ def _build_from_module(module_name: str, func_name: str, **kwargs) -> BaseChatMo
}


@lru_cache(maxsize=16)
# Cache model instances to avoid recreating them on every call
def get_model(
provider: Optional[Provider] = None,
model_name: Optional[str] = None,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/models/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def mock_modules():
"src.models.gemini": MagicMock(),
"src.models.claude": MagicMock(),
"src.models.openai": MagicMock(),
"langchain_core": MagicMock(),
"langchain_core.language_models": MagicMock(),
"pydantic": MagicMock(),
"pydantic_settings": MagicMock(),
},
):
yield
Expand Down