File size: 910 Bytes
2edb151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import annotations

from pathlib import Path
from typing import Literal, Protocol, runtime_checkable

InputType = Literal["query", "passage"]


class OCRResult:
    __slots__ = ("text", "engine")

    def __init__(self, text: str, engine: str) -> None:
        self.text = text
        self.engine = engine


@runtime_checkable
class LLMBackend(Protocol):
    accepts_images: bool
    name: str

    def complete_json(
        self,
        *,
        system: str,
        user: str,
        image_jpeg: bytes | None = None,
    ) -> str: ...

    def health(self) -> bool: ...


@runtime_checkable
class EmbedBackend(Protocol):
    name: str
    dim: int

    def embed(self, texts: list[str], *, input_type: InputType) -> list[list[float]]: ...

    def health(self) -> bool: ...


@runtime_checkable
class OCRBackend(Protocol):
    name: str

    def ocr(self, path: Path) -> OCRResult: ...