File size: 836 Bytes
8302f42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
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"