File size: 892 Bytes
09d4173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
"""The small contract between response formatting and inference transport."""

from dataclasses import dataclass
from typing import Protocol


class AdapterError(Exception):
    def __init__(self, code: str, message: str, field: str = "", status: int = 422):
        super().__init__(message)
        self.code, self.field, self.status = code, field, status


@dataclass(frozen=True)
class ScoringResult:
    logprobs: tuple[float, ...]
    input_tokens: int


class ScoringBackend(Protocol):
    model: str

    async def start(self) -> None: ...

    async def close(self) -> None: ...

    def labels(self, count: int) -> tuple[tuple[str, ...], tuple[int, ...]]: ...

    async def evaluate(
        self,
        prompt: str,
        images: list[str],
        labels: tuple[str, ...],
        token_ids: tuple[int, ...],
        assistant_prefix: str | None,
    ) -> ScoringResult: ...