Skip to content

Add augmentations service with Albumentations presets and update AI library registry#915

Merged
Smartappli merged 1 commit into
masterfrom
add-pycaret-4
May 12, 2026
Merged

Add augmentations service with Albumentations presets and update AI library registry#915
Smartappli merged 1 commit into
masterfrom
add-pycaret-4

Conversation

@Smartappli
Copy link
Copy Markdown
Owner

@Smartappli Smartappli commented May 12, 2026

Motivation

  • Expose baseline Albumentations presets and provide a small service to validate preset transforms against the installed Albumentations package.
  • Ensure the AI library registry tracks newly surfaced optional dependencies (albumentations and pycaret) so the /libraries endpoint reports them.

Description

  • Added a new augmentations microservice at MAGE/api/services/augmentations.py which provides /augmentations (presets and version) and /augmentations/{preset_name}/validate endpoints and a service-local /health route.
  • Mounted the augmentations service and exposed backward-compatible gateway routes by updating MAGE/api/main.py to import and register augmentation_presets, validate_preset, and augmentations_service on both the gateway and /services/augmentations prefix.
  • Updated the AI library registry in MAGE/api/common.py to include albumentations and pycaret mappings.
  • Added optional dependencies to MAGE/pyproject.toml for albumentations and pycaret.
  • Added unit tests: MAGE/tests/test_library_registry.py to assert registry mappings and extended MAGE/tests/test_main.py with mocks for a fake albumentations module and tests for the new augmentations endpoints and pycaret reporting.

Testing

  • Ran the project test suite with pytest, including MAGE/tests/test_main.py and the new MAGE/tests/test_library_registry.py test file.
  • The tests exercised the new routes (/augmentations, /augmentations/{preset}/validate), the updated /libraries behavior for missing and present optional deps, and existing API endpoints.
  • All automated tests completed successfully.

Codex Task

Summary by CodeRabbit

  • New Features

    • Introduced augmentation service with REST API endpoints to discover available presets and validate augmentation configurations.
    • Extended AI library registry to include Albumentations and PyCaret integrations.
  • Tests

    • Added test coverage for new augmentation service endpoints and library registry mappings.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6fa85770-a4a5-4d64-989a-5b67b4f057c6

📥 Commits

Reviewing files that changed from the base of the PR and between cfa03e2 and b4d8031.

📒 Files selected for processing (6)
  • MAGE/api/common.py
  • MAGE/api/main.py
  • MAGE/api/services/augmentations.py
  • MAGE/pyproject.toml
  • MAGE/tests/test_library_registry.py
  • MAGE/tests/test_main.py

Walkthrough

This PR integrates albumentations and pycaret into the AI library ecosystem by extending the library registry, creating an augmentations microservice with preset listing and validation endpoints, wiring it into the API gateway, and adding comprehensive test coverage for the new functionality.

Changes

Augmentations and Modeling Library Support

Layer / File(s) Summary
Library Registry and Project Dependencies
MAGE/api/common.py, MAGE/pyproject.toml, MAGE/tests/test_library_registry.py
Updated LIBRARIES_BY_CATEGORY["AI"] to register albumentations and pycaret mappings, added albumentations>=1.4.0 and pycaret==4.0.0a8 to project dependencies, and added a unit test validating the registry includes expected AI library mappings.
Augmentations Microservice Implementation
MAGE/api/services/augmentations.py
New FastAPI microservice that dynamically imports albumentations to expose a /augmentations endpoint with preset recipes and library version, and a /{preset_name}/validate endpoint that checks whether transform names exist in the albumentations library, returning validation reports or error codes (503 on import failure, 404 for unknown presets, 500 for malformed data).
API Gateway Route and Service Registration
MAGE/api/main.py
Imports augmentation handlers and the augmentations service app, registers two new GET routes for augmentations operations, and mounts the augmentations service under /services/augmentations to expose it as a microservice boundary.
Test Infrastructure and Endpoint Coverage
MAGE/tests/test_main.py
Extended test fixtures with fake implementations for albumentations and improved SMP encoders mocking, added new tests for augmentations preset listing and validation behavior (success and 404 cases), updated existing /libraries tests to treat albumentations and pycaret as optional dependencies, and added a test verifying /libraries reports the pycaret version when available.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AugmentationService as Augmentations Service
  participant Albumentations
  
  Client->>AugmentationService: GET /augmentations
  AugmentationService->>Albumentations: import dynamic
  Albumentations-->>AugmentationService: version, available
  AugmentationService-->>Client: presets + version
  
  Client->>AugmentationService: GET /augmentations/{preset_name}/validate
  AugmentationService->>Albumentations: import and inspect
  Albumentations-->>AugmentationService: available transforms
  AugmentationService-->>Client: validation report (parsed, missing, is_valid)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 The augmentations bloom so bright,
With albumentations in sight,
Presets validated, transforms clear,
New service routes the guild will cheer!
transforms library integration, hop! 🥕

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-pycaret-4

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Smartappli Smartappli marked this pull request as ready for review May 12, 2026 13:33
@Smartappli Smartappli merged commit 4d47bf5 into master May 12, 2026
8 of 21 checks passed
@Smartappli Smartappli deleted the add-pycaret-4 branch May 12, 2026 13:33
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an Augmentations service to the MAGE API, integrating the albumentations library. It adds new endpoints for retrieving and validating augmentation presets, updates project dependencies to include albumentations and pycaret, and provides corresponding unit tests. Feedback focused on improving exception handling by catching specific ImportError exceptions instead of broad ones. Additionally, the reviewer pointed out redundant logic and discouraged patterns in the validation endpoint, suggesting a refactor to use module-level constants for presets to simplify the code.

"""
try:
alb = import_module("albumentations")
except Exception as exc:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a broad Exception here is discouraged. Since the primary failure mode for import_module in this context is a missing optional dependency, it is better to catch ImportError (or ModuleNotFoundError). This prevents masking other unexpected errors during module initialization.

Suggested change
except Exception as exc:
except ImportError as exc:

Comment on lines +86 to +97
payload = await augmentation_presets()
presets = payload["presets"]
if not isinstance(presets, dict) or preset_name not in presets:
raise HTTPException(status_code=404, detail="unknown augmentation preset")

try:
alb = import_module("albumentations")
except Exception as exc:
raise HTTPException(
status_code=503,
detail="albumentations is unavailable",
) from exc
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The validate_preset function currently calls augmentation_presets() (line 86), which already performs the albumentations import check and raises a 503 HTTPException if it fails. This makes the subsequent try...except block at lines 91-97 redundant and unreachable in the failure case. Furthermore, calling an async route handler as a helper function is generally discouraged. A cleaner approach would be to extract the presets into a module-level constant and use that in both functions. This avoids the overhead of the extra function call and simplifies the validation logic. If you keep the import here, please also change Exception to ImportError for consistency.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 22 complexity

Metric Results
Complexity 22

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant