Skip to content
Merged
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
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ uv run ruff format . && uv run ruff check . # Lint & format
- **Google-style docstrings**
- **Ruff** for linting/formatting
- Use `...` in `@generative` function bodies
- Use `...` in `@generative` function bodies
- Prefer primitives over classes
- **Friendly Dependency Errors**: Wraps optional backend imports in `try/except ImportError` with a helpful message (e.g., "Please pip install mellea[hf]"). See `mellea/stdlib/session.py` for examples.

## 5. Commits & Hooks
[Angular format](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit): `feat:`, `fix:`, `docs:`, `test:`, `refactor:`, `release:`
Expand Down
36 changes: 27 additions & 9 deletions mellea/stdlib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,39 @@ def backend_name_to_class(name: str) -> Any:

return OllamaModelBackend
elif name == "hf" or name == "huggingface":
from mellea.backends.huggingface import LocalHFBackend

return LocalHFBackend
try:
from mellea.backends.huggingface import LocalHFBackend

return LocalHFBackend
except ImportError as e:
raise ImportError(
"The 'hf' backend requires extra dependencies. "
"Please install them with: pip install 'mellea[hf]'"
) from e
elif name == "openai":
from ..backends.openai import OpenAIBackend

return OpenAIBackend
elif name == "watsonx":
from ..backends.watsonx import WatsonxAIBackend

return WatsonxAIBackend
try:
from ..backends.watsonx import WatsonxAIBackend

return WatsonxAIBackend
except ImportError as e:
raise ImportError(
"The 'watsonx' backend requires extra dependencies. "
"Please install them with: pip install 'mellea[watsonx]'"
) from e
elif name == "litellm":
from ..backends.litellm import LiteLLMBackend

return LiteLLMBackend
try:
from ..backends.litellm import LiteLLMBackend

return LiteLLMBackend
except ImportError as e:
raise ImportError(
"The 'litellm' backend requires extra dependencies. "
"Please install them with: pip install 'mellea[litellm]'"
) from e
else:
return None

Expand Down