File size: 910 Bytes
a358495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Iterable

from satquery_engine.models.compatibility import CompatibilityResult, ModelCompatibility
from satquery_engine.models.manifest import ModelManifest


@dataclass(frozen=True)
class RoutedModel:
    role: str
    manifest: ModelManifest
    compatibility: CompatibilityResult


class CompatibilityRouter:
    """Select the first healthy, input-compatible model for a task role."""

    def route(
        self,
        candidates: Iterable[tuple[str, ModelManifest]],
        raster_profile: Any,
        task: str,
    ) -> RoutedModel | None:
        for role, manifest in candidates:
            result = ModelCompatibility.evaluate(manifest, raster_profile, task)
            if result.compatible:
                return RoutedModel(role=role, manifest=manifest, compatibility=result)
        return None