Skip to content

Fix CI: add API test deps to requirements.txt, make torch imports lazy - #3

Merged
CoreyLeath-code merged 3 commits into
mainfrom
copilot/update-code-files-fix-ci
Apr 9, 2026
Merged

Fix CI: add API test deps to requirements.txt, make torch imports lazy#3
CoreyLeath-code merged 3 commits into
mainfrom
copilot/update-code-files-fix-ci

Conversation

Copilot AI commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

CI python-test job was failing with pytest: command not found and import errors because requirements.txt only listed data/viz libs, not the API or test dependencies. Additionally, api/inference.py imported torch and instantiated SentinelModel at module level, causing ImportError when the FastAPI app was imported in any environment without PyTorch.

Changes

  • requirements.txt — added pytest>=7.0.0, fastapi>=0.100.0, httpx>=0.24.0, slowapi>=0.1.7, pydantic>=2.0.0 with minimum version constraints

  • api/inference.py — replaced module-level torch/model initialization with a lazy _get_model() singleton; torch is only imported on the first actual inference call:

    # before: torch imported at module load time
    import torch
    device = torch.device(...)
    model = SentinelModel().to(device)  # fails in CI
    
    # after: deferred until first call
    def _get_model():
        global _device, _model
        if _model is None:
            import torch
            from api.core.model import SentinelModel
            ...
        return _model, _device
  • api/routes/inference.py — moved import torch and from transformers import ... from module level into _load_model(); run_inference() retrieves the already-loaded module via sys.modules["torch"] instead of a redundant local import

Copilot AI changed the title [WIP] Update code files and fix CI for deployment readiness Fix CI: add API test deps to requirements.txt, make torch imports lazy Apr 9, 2026
Copilot AI requested a review from CoreyLeath-code April 9, 2026 01:59
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.

2 participants