mlforge / adapters /base.py
senthil2421
fix: remove project dependencies and redundant imports to fix server startup
8302f42
"""
adapters/base.py — Abstract base class every source adapter must implement.
Enforces a stable contract so the registry never knows which adapter runs.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from models.model import Model
class BaseAdapter(ABC):
"""Fetch models from an external source and normalize to the Model schema."""
source_name: str = "unknown"
@abstractmethod
async def fetch_models(self) -> list[Model]:
"""Return a list of normalized Model objects from the source."""
...
def _format_size(self, bytes_: int) -> str:
"""Human-readable file size."""
for unit in ("B", "KB", "MB", "GB", "TB"):
if bytes_ < 1024:
return f"{bytes_:.1f} {unit}"
bytes_ //= 1024
return f"{bytes_} PB"