pyocr-toolkit 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyocr_toolkit/__init__.py +3 -0
- pyocr_toolkit/__main__.py +3 -0
- pyocr_toolkit/api.py +603 -0
- pyocr_toolkit/cli.py +315 -0
- pyocr_toolkit/compare.py +142 -0
- pyocr_toolkit/config.py +86 -0
- pyocr_toolkit/credentials.py +108 -0
- pyocr_toolkit/documents.py +326 -0
- pyocr_toolkit/env.example +48 -0
- pyocr_toolkit/jobs.py +205 -0
- pyocr_toolkit/llm/__init__.py +44 -0
- pyocr_toolkit/llm/anthropic_provider.py +188 -0
- pyocr_toolkit/llm/base.py +126 -0
- pyocr_toolkit/llm/catalog.py +337 -0
- pyocr_toolkit/llm/gemini_provider.py +98 -0
- pyocr_toolkit/llm/openai_provider.py +183 -0
- pyocr_toolkit/llm/prompts.py +61 -0
- pyocr_toolkit/search.py +88 -0
- pyocr_toolkit/service.py +269 -0
- pyocr_toolkit/static/common.js +538 -0
- pyocr_toolkit/static/compare.js +157 -0
- pyocr_toolkit/static/document.js +89 -0
- pyocr_toolkit/static/jobs.js +13 -0
- pyocr_toolkit/static/library.js +28 -0
- pyocr_toolkit/static/models.js +98 -0
- pyocr_toolkit/static/providers.js +44 -0
- pyocr_toolkit/static/reader.js +78 -0
- pyocr_toolkit/static/search.js +34 -0
- pyocr_toolkit/static/styles.css +819 -0
- pyocr_toolkit/static/workspace.js +420 -0
- pyocr_toolkit/static/workspaces.js +81 -0
- pyocr_toolkit/templates/_doc_card.html +30 -0
- pyocr_toolkit/templates/_doctabs.html +14 -0
- pyocr_toolkit/templates/_icons.html +55 -0
- pyocr_toolkit/templates/_llm_picker.html +12 -0
- pyocr_toolkit/templates/base.html +97 -0
- pyocr_toolkit/templates/compare.html +84 -0
- pyocr_toolkit/templates/document.html +80 -0
- pyocr_toolkit/templates/error.html +11 -0
- pyocr_toolkit/templates/help.html +244 -0
- pyocr_toolkit/templates/home.html +90 -0
- pyocr_toolkit/templates/jobs.html +15 -0
- pyocr_toolkit/templates/library.html +44 -0
- pyocr_toolkit/templates/models.html +67 -0
- pyocr_toolkit/templates/providers.html +104 -0
- pyocr_toolkit/templates/reader.html +28 -0
- pyocr_toolkit/templates/search.html +22 -0
- pyocr_toolkit/templates/workspace.html +109 -0
- pyocr_toolkit/templates/workspace_detail.html +42 -0
- pyocr_toolkit/templates/workspaces.html +42 -0
- pyocr_toolkit/web.py +186 -0
- pyocr_toolkit/workspaces.py +330 -0
- pyocr_toolkit-0.3.0.dist-info/METADATA +483 -0
- pyocr_toolkit-0.3.0.dist-info/RECORD +57 -0
- pyocr_toolkit-0.3.0.dist-info/WHEEL +4 -0
- pyocr_toolkit-0.3.0.dist-info/entry_points.txt +3 -0
- pyocr_toolkit-0.3.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Claude, via the Anthropic API or via Microsoft Foundry (Azure)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
import anthropic
|
|
9
|
+
|
|
10
|
+
from ..config import Settings
|
|
11
|
+
from . import catalog
|
|
12
|
+
from .base import Provider, ProviderError, TranscriptionRequest, TranscriptionResult
|
|
13
|
+
|
|
14
|
+
# Models that accept the server-side refusal fallback (``fallbacks``). When a
|
|
15
|
+
# safety classifier declines a page (rare, but it happens with e.g. scanned
|
|
16
|
+
# lab reports or chemistry papers) the API transparently re-runs the request
|
|
17
|
+
# on a fallback model instead of returning nothing.
|
|
18
|
+
_FALLBACK_MODELS = {"claude-fable-5-2", "claude-fable-5-1", "claude-opus-5-5", "claude-opus-5", "claude-sonnet-5-5"}
|
|
19
|
+
_FALLBACK_BETA = "server-side-fallback-2026-07-01"
|
|
20
|
+
|
|
21
|
+
_VERSION_RE = re.compile(r"claude-(opus|sonnet|haiku|fable|mythos)-(\d+)(?:-(\d{1,2}))?(?:$|[-@])")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _supports_effort(model: str) -> bool:
|
|
25
|
+
"""``output_config.effort`` exists on Opus/Sonnet 4.6+, Haiku 5.5+, Fable, Mythos.
|
|
26
|
+
|
|
27
|
+
Older models reject the parameter, so we only send it where it's known to work.
|
|
28
|
+
"""
|
|
29
|
+
m = _VERSION_RE.search(model)
|
|
30
|
+
if not m:
|
|
31
|
+
return False
|
|
32
|
+
family, major, minor = m.group(1), int(m.group(2)), int(m.group(3) or 0)
|
|
33
|
+
version = (major, minor)
|
|
34
|
+
if family in ("fable", "mythos"):
|
|
35
|
+
return True
|
|
36
|
+
if family == "haiku":
|
|
37
|
+
return version >= (5, 5)
|
|
38
|
+
return version >= (4, 6)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _ClaudeBase(Provider):
|
|
42
|
+
suggested_models = catalog.recommended("anthropic") + ["claude-haiku-5-5"]
|
|
43
|
+
supports_server_fallback = True
|
|
44
|
+
|
|
45
|
+
def __init__(self, settings: Settings) -> None:
|
|
46
|
+
self.settings = settings
|
|
47
|
+
self._client: anthropic.AsyncAnthropic | None = None
|
|
48
|
+
|
|
49
|
+
def _make_client(self) -> anthropic.AsyncAnthropic:
|
|
50
|
+
raise NotImplementedError
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def client(self):
|
|
54
|
+
if self._client is None:
|
|
55
|
+
self._client = self._make_client()
|
|
56
|
+
return self._client
|
|
57
|
+
|
|
58
|
+
async def _transcribe(self, req: TranscriptionRequest, model: str) -> TranscriptionResult:
|
|
59
|
+
params: dict = {
|
|
60
|
+
"model": model,
|
|
61
|
+
"max_tokens": req.max_output_tokens,
|
|
62
|
+
"system": req.system_prompt,
|
|
63
|
+
"messages": [{
|
|
64
|
+
"role": "user",
|
|
65
|
+
"content": [
|
|
66
|
+
{
|
|
67
|
+
"type": "image",
|
|
68
|
+
"source": {
|
|
69
|
+
"type": "base64",
|
|
70
|
+
"media_type": req.mime_type,
|
|
71
|
+
"data": base64.standard_b64encode(req.image).decode("ascii"),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{"type": "text", "text": req.user_prompt},
|
|
75
|
+
],
|
|
76
|
+
}],
|
|
77
|
+
}
|
|
78
|
+
if _supports_effort(model) and self.settings.anthropic_effort:
|
|
79
|
+
params["output_config"] = {"effort": self.settings.anthropic_effort}
|
|
80
|
+
if self.supports_server_fallback and model in _FALLBACK_MODELS:
|
|
81
|
+
params["betas"] = [_FALLBACK_BETA]
|
|
82
|
+
params["fallbacks"] = "default"
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
# Streaming keeps long transcriptions (dense pages) clear of HTTP
|
|
86
|
+
# timeouts; we only need the final message.
|
|
87
|
+
async with self.client.beta.messages.stream(**params) as stream:
|
|
88
|
+
message = await stream.get_final_message()
|
|
89
|
+
except anthropic.AuthenticationError as exc:
|
|
90
|
+
raise ProviderError(f"{self.label}: authentication failed - check the API key") from exc
|
|
91
|
+
except anthropic.NotFoundError as exc:
|
|
92
|
+
raise ProviderError(f"{self.label}: model '{model}' not found") from exc
|
|
93
|
+
except anthropic.RateLimitError as exc:
|
|
94
|
+
raise ProviderError(f"{self.label}: rate limited, try again shortly") from exc
|
|
95
|
+
except anthropic.APIStatusError as exc:
|
|
96
|
+
raise ProviderError(f"{self.label}: API error {exc.status_code}: {exc.message}") from exc
|
|
97
|
+
except anthropic.APIConnectionError as exc:
|
|
98
|
+
raise ProviderError(f"{self.label}: connection error: {exc}") from exc
|
|
99
|
+
|
|
100
|
+
warnings: list[str] = []
|
|
101
|
+
if message.stop_reason == "refusal":
|
|
102
|
+
details = getattr(message, "stop_details", None)
|
|
103
|
+
category = getattr(details, "category", None) if details else None
|
|
104
|
+
raise ProviderError(f"{self.label}: the model declined this page" + (f" ({category})" if category else ""))
|
|
105
|
+
if message.stop_reason == "max_tokens":
|
|
106
|
+
warnings.append("output hit the max token limit; transcription is truncated")
|
|
107
|
+
for block in message.content:
|
|
108
|
+
if block.type == "fallback":
|
|
109
|
+
warnings.append(f"{block.from_.model} declined; answered by {block.to.model}")
|
|
110
|
+
|
|
111
|
+
text = "".join(block.text for block in message.content if block.type == "text")
|
|
112
|
+
return TranscriptionResult(
|
|
113
|
+
text=text.strip(),
|
|
114
|
+
provider=self.id,
|
|
115
|
+
model=message.model,
|
|
116
|
+
latency_ms=0,
|
|
117
|
+
input_tokens=message.usage.input_tokens,
|
|
118
|
+
output_tokens=message.usage.output_tokens,
|
|
119
|
+
stop_reason=message.stop_reason,
|
|
120
|
+
warnings=warnings,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class AnthropicProvider(_ClaudeBase):
|
|
125
|
+
id = "anthropic"
|
|
126
|
+
label = "Claude (Anthropic API)"
|
|
127
|
+
docs_url = "https://console.anthropic.com/settings/keys"
|
|
128
|
+
can_list_models = True
|
|
129
|
+
env_vars = [
|
|
130
|
+
("ANTHROPIC_API_KEY", True, "API key from the Claude Console"),
|
|
131
|
+
("ANTHROPIC_MODEL", False, "default model, e.g. claude-opus-5-5"),
|
|
132
|
+
("ANTHROPIC_EFFORT", False, "low | medium | high | xhigh | max (default medium)"),
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def default_model(self) -> str | None:
|
|
137
|
+
return self.settings.anthropic_model
|
|
138
|
+
|
|
139
|
+
def missing_settings(self) -> list[str]:
|
|
140
|
+
return [] if self.settings.anthropic_api_key else ["ANTHROPIC_API_KEY"]
|
|
141
|
+
|
|
142
|
+
def _make_client(self):
|
|
143
|
+
return anthropic.AsyncAnthropic(
|
|
144
|
+
api_key=self.settings.anthropic_api_key, timeout=self.settings.llm_timeout_s
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
async def list_models(self) -> list[str] | None:
|
|
148
|
+
try:
|
|
149
|
+
return [m.id async for m in self.client.models.list(limit=100)]
|
|
150
|
+
except anthropic.APIError as exc:
|
|
151
|
+
raise ProviderError(f"Could not list Claude models: {exc}") from exc
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class AnthropicFoundryProvider(_ClaudeBase):
|
|
155
|
+
"""Claude models deployed in Microsoft Foundry (Azure AI)."""
|
|
156
|
+
|
|
157
|
+
id = "azure_claude"
|
|
158
|
+
label = "Claude on Azure (Microsoft Foundry)"
|
|
159
|
+
model_hint = "Foundry deployment name of the Claude model"
|
|
160
|
+
docs_url = "https://learn.microsoft.com/azure/ai-foundry/"
|
|
161
|
+
env_vars = [
|
|
162
|
+
("ANTHROPIC_FOUNDRY_API_KEY", True, "key of your Microsoft Foundry resource"),
|
|
163
|
+
("ANTHROPIC_FOUNDRY_RESOURCE", True, "resource name (or set ANTHROPIC_FOUNDRY_BASE_URL)"),
|
|
164
|
+
("ANTHROPIC_FOUNDRY_BASE_URL", False, "full endpoint URL, instead of the resource name"),
|
|
165
|
+
("ANTHROPIC_FOUNDRY_MODEL", False, "deployment name, e.g. claude-opus-5-5"),
|
|
166
|
+
]
|
|
167
|
+
# Server-side fallbacks are a Claude API feature, not available on Foundry.
|
|
168
|
+
supports_server_fallback = False
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def default_model(self) -> str | None:
|
|
172
|
+
return self.settings.anthropic_foundry_model
|
|
173
|
+
|
|
174
|
+
def missing_settings(self) -> list[str]:
|
|
175
|
+
missing = []
|
|
176
|
+
if not self.settings.anthropic_foundry_api_key:
|
|
177
|
+
missing.append("ANTHROPIC_FOUNDRY_API_KEY")
|
|
178
|
+
if not (self.settings.anthropic_foundry_resource or self.settings.anthropic_foundry_base_url):
|
|
179
|
+
missing.append("ANTHROPIC_FOUNDRY_RESOURCE (or ANTHROPIC_FOUNDRY_BASE_URL)")
|
|
180
|
+
return missing
|
|
181
|
+
|
|
182
|
+
def _make_client(self):
|
|
183
|
+
kwargs = {"api_key": self.settings.anthropic_foundry_api_key, "timeout": self.settings.llm_timeout_s}
|
|
184
|
+
if self.settings.anthropic_foundry_base_url:
|
|
185
|
+
kwargs["base_url"] = self.settings.anthropic_foundry_base_url
|
|
186
|
+
else:
|
|
187
|
+
kwargs["resource"] = self.settings.anthropic_foundry_resource
|
|
188
|
+
return anthropic.AsyncAnthropicFoundry(**kwargs)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Provider-neutral interface for "transcribe this page image" calls."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import abc
|
|
6
|
+
import time
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
|
|
9
|
+
from . import catalog
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ProviderError(Exception):
|
|
13
|
+
"""A provider call failed (bad credentials, refusal, network, ...)."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ProviderNotConfigured(ProviderError):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class TranscriptionRequest:
|
|
22
|
+
image: bytes
|
|
23
|
+
mime_type: str # "image/png" or "image/jpeg"
|
|
24
|
+
system_prompt: str
|
|
25
|
+
user_prompt: str
|
|
26
|
+
model: str | None = None # None -> provider default
|
|
27
|
+
max_output_tokens: int = 16000
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class TranscriptionResult:
|
|
32
|
+
text: str
|
|
33
|
+
provider: str
|
|
34
|
+
model: str
|
|
35
|
+
latency_ms: float
|
|
36
|
+
input_tokens: int | None = None
|
|
37
|
+
output_tokens: int | None = None
|
|
38
|
+
stop_reason: str | None = None
|
|
39
|
+
warnings: list[str] = field(default_factory=list)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Provider(abc.ABC):
|
|
43
|
+
#: stable identifier used in URLs / cache keys
|
|
44
|
+
id: str
|
|
45
|
+
#: human readable name for the UI
|
|
46
|
+
label: str
|
|
47
|
+
#: example model names shown as suggestions in the UI
|
|
48
|
+
suggested_models: list[str] = []
|
|
49
|
+
#: what the "model" field means for this provider
|
|
50
|
+
model_hint: str = "Model name"
|
|
51
|
+
#: (ENV_VAR, required, description) - shown on the Providers page
|
|
52
|
+
env_vars: list[tuple[str, bool, str]] = []
|
|
53
|
+
#: where to get credentials
|
|
54
|
+
docs_url: str = ""
|
|
55
|
+
#: whether :meth:`list_models` asks the provider's API (False: deployments you name yourself)
|
|
56
|
+
can_list_models: bool = False
|
|
57
|
+
|
|
58
|
+
def env_status(self) -> list[dict]:
|
|
59
|
+
"""Which settings are set (never the values themselves)."""
|
|
60
|
+
settings = getattr(self, "settings", None)
|
|
61
|
+
fields = type(settings).model_fields if settings is not None else {}
|
|
62
|
+
out = []
|
|
63
|
+
for name, required, desc in self.env_vars:
|
|
64
|
+
attr = name.lower()
|
|
65
|
+
value = getattr(settings, attr, None)
|
|
66
|
+
default = fields[attr].default if attr in fields else None
|
|
67
|
+
# "default" = not set by the user but a built-in default applies
|
|
68
|
+
state = "missing" if not value else "default" if value == default else "set"
|
|
69
|
+
out.append({"name": name, "required": required, "description": desc,
|
|
70
|
+
"set": state == "set", "state": state,
|
|
71
|
+
"default": default if isinstance(default, (str, int, float)) else None})
|
|
72
|
+
return out
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
@abc.abstractmethod
|
|
76
|
+
def default_model(self) -> str | None: ...
|
|
77
|
+
|
|
78
|
+
@abc.abstractmethod
|
|
79
|
+
def missing_settings(self) -> list[str]:
|
|
80
|
+
"""Environment variables that must be set before the provider works."""
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def configured(self) -> bool:
|
|
84
|
+
return not self.missing_settings()
|
|
85
|
+
|
|
86
|
+
def reset_client(self) -> None:
|
|
87
|
+
"""Forget the cached SDK client so the next call picks up changed settings."""
|
|
88
|
+
if hasattr(self, "_client"):
|
|
89
|
+
self._client = None
|
|
90
|
+
|
|
91
|
+
async def list_models(self) -> list[str] | None:
|
|
92
|
+
"""Model ids the provider says this key can use, or ``None`` if it can't list them.
|
|
93
|
+
|
|
94
|
+
Azure/Foundry deployments aren't listable with a data-plane key, so those return ``None``.
|
|
95
|
+
"""
|
|
96
|
+
return None
|
|
97
|
+
|
|
98
|
+
async def transcribe(self, req: TranscriptionRequest) -> TranscriptionResult:
|
|
99
|
+
missing = self.missing_settings()
|
|
100
|
+
if missing:
|
|
101
|
+
raise ProviderNotConfigured(f"{self.label} is not configured; set {', '.join(missing)}")
|
|
102
|
+
model = (req.model or self.default_model or "").strip()
|
|
103
|
+
if not model:
|
|
104
|
+
raise ProviderError(f"no model given for {self.label}")
|
|
105
|
+
t0 = time.perf_counter()
|
|
106
|
+
result = await self._transcribe(req, model)
|
|
107
|
+
result.latency_ms = round((time.perf_counter() - t0) * 1000, 1)
|
|
108
|
+
return result
|
|
109
|
+
|
|
110
|
+
@abc.abstractmethod
|
|
111
|
+
async def _transcribe(self, req: TranscriptionRequest, model: str) -> TranscriptionResult: ...
|
|
112
|
+
|
|
113
|
+
def describe(self) -> dict:
|
|
114
|
+
return {
|
|
115
|
+
"id": self.id,
|
|
116
|
+
"label": self.label,
|
|
117
|
+
"configured": self.configured,
|
|
118
|
+
"missing": self.missing_settings(),
|
|
119
|
+
"default_model": self.default_model,
|
|
120
|
+
"suggested_models": self.suggested_models,
|
|
121
|
+
"model_options": catalog.model_options(self.id, self.suggested_models),
|
|
122
|
+
"model_hint": self.model_hint,
|
|
123
|
+
"env": self.env_status(),
|
|
124
|
+
"docs_url": self.docs_url,
|
|
125
|
+
"can_list_models": self.can_list_models,
|
|
126
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"""A curated catalog of vision models, rated for *this* job: verbatim page transcription.
|
|
2
|
+
|
|
3
|
+
Why a hand-written catalog instead of only asking each provider for its model list?
|
|
4
|
+
Provider ``/models`` endpoints return dozens of ids (embeddings, TTS, image generators)
|
|
5
|
+
and say nothing about which ones read a scanned page well. The catalog adds that missing
|
|
6
|
+
judgement so the UI can say "good for OCR" / "not suitable" next to a name. It is a
|
|
7
|
+
suggestion list, never a whitelist: any model name the user types is still sent as-is.
|
|
8
|
+
|
|
9
|
+
Ratings were compiled in November 2026 from the providers' own model pages and public
|
|
10
|
+
OCR benchmarks (see ``SOURCES``). Benchmarks disagree and go stale quickly, so each entry
|
|
11
|
+
says *why* it got its rating, and ``evidence`` separates measured results from estimates.
|
|
12
|
+
Test on your own pages: the Compare tab exists exactly for that.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
from dataclasses import asdict, dataclass, field
|
|
19
|
+
|
|
20
|
+
#: rating -> (short label, sort order). "unrated" is only produced by :func:`lookup`.
|
|
21
|
+
RATINGS: dict[str, tuple[str, int]] = {
|
|
22
|
+
"excellent": ("Excellent for OCR", 0),
|
|
23
|
+
"good": ("Good for OCR", 1),
|
|
24
|
+
"fair": ("Fair: clean print only", 2),
|
|
25
|
+
"unsuitable": ("Not suitable", 4),
|
|
26
|
+
"unrated": ("Not rated", 3),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
SOURCES = [
|
|
30
|
+
("Roboflow: Best LLMs for OCR (Oct 2026)", "https://roboflow.com/blog/best-llms-for-ocr"),
|
|
31
|
+
("Roboflow OCR leaderboard (updated Nov 19, 2026)", "https://playground.roboflow.com/models/task/ocr"),
|
|
32
|
+
("Docsumo: OmniDocBench roundup", "https://www.docsumo.com/blog/best-ocr-models"),
|
|
33
|
+
("Anthropic models overview", "https://platform.claude.com/docs/en/about-claude/models/overview"),
|
|
34
|
+
("OpenAI models", "https://developers.openai.com/api/docs/models"),
|
|
35
|
+
("Gemini models", "https://ai.google.dev/gemini-api/docs/models"),
|
|
36
|
+
]
|
|
37
|
+
CATALOG_UPDATED = "2026-11"
|
|
38
|
+
|
|
39
|
+
# Provider ids a model *family* can be used with. Azure / Foundry / OpenAI-compatible take
|
|
40
|
+
# deployment or server-specific names, which :func:`lookup` matches loosely.
|
|
41
|
+
_CLAUDE = ("anthropic", "azure_claude", "openai_compatible")
|
|
42
|
+
_OPENAI = ("openai", "azure_openai", "openai_compatible")
|
|
43
|
+
_GEMINI = ("gemini", "openai_compatible")
|
|
44
|
+
_OPEN = ("openai_compatible",)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True)
|
|
48
|
+
class ModelInfo:
|
|
49
|
+
id: str
|
|
50
|
+
label: str
|
|
51
|
+
vendor: str
|
|
52
|
+
providers: tuple[str, ...]
|
|
53
|
+
rating: str
|
|
54
|
+
note: str
|
|
55
|
+
#: "benchmark" = measured on a public OCR benchmark; "vendor" = vendor docs + tier estimate
|
|
56
|
+
evidence: str = "vendor"
|
|
57
|
+
#: current | previous | preview | deprecated
|
|
58
|
+
status: str = "current"
|
|
59
|
+
#: list price, USD per 1M input / output tokens (None = not published)
|
|
60
|
+
price_in: float | None = None
|
|
61
|
+
price_out: float | None = None
|
|
62
|
+
#: the name differs per server (Ollama tag, OpenRouter slug, HF repo); ``id`` is the family
|
|
63
|
+
name_varies: bool = False
|
|
64
|
+
aliases: tuple[str, ...] = field(default_factory=tuple)
|
|
65
|
+
|
|
66
|
+
def to_json(self) -> dict:
|
|
67
|
+
d = asdict(self)
|
|
68
|
+
d["providers"] = list(self.providers)
|
|
69
|
+
d["aliases"] = list(self.aliases)
|
|
70
|
+
d["rating_label"] = RATINGS[self.rating][0]
|
|
71
|
+
return d
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _m(*args, **kw) -> ModelInfo:
|
|
75
|
+
return ModelInfo(*args, **kw)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
MODELS: list[ModelInfo] = [
|
|
79
|
+
# ---------------------------------------------------------------- Anthropic
|
|
80
|
+
_m("claude-fable-5-2", "Claude Fable 5.2", "Anthropic", _CLAUDE, "excellent",
|
|
81
|
+
"Top accuracy pick. Its predecessor Fable 5 ranked #1 of 88 models (94%) on Roboflow's OCR benchmark; "
|
|
82
|
+
"strongest on dense tables and charts. Also the slowest and most expensive.",
|
|
83
|
+
evidence="benchmark", price_in=8, price_out=40),
|
|
84
|
+
_m("claude-opus-5-5", "Claude Opus 5.5", "Anthropic", _CLAUDE, "excellent",
|
|
85
|
+
"Strong vision and instruction following at half Fable's price; reliable at copying text without "
|
|
86
|
+
"'fixing' it. Not separately benchmarked.", price_in=4, price_out=20),
|
|
87
|
+
_m("claude-sonnet-5-5", "Claude Sonnet 5.5", "Anthropic", _CLAUDE, "good",
|
|
88
|
+
"Balanced cost/quality for bulk jobs. Raise effort for handwriting.", price_in=2, price_out=10),
|
|
89
|
+
_m("claude-haiku-5-5", "Claude Haiku 5.5", "Anthropic", _CLAUDE, "fair",
|
|
90
|
+
"Very cheap and fast; fine for clean printed pages, weaker on handwriting and complex layouts.",
|
|
91
|
+
price_in=0.1, price_out=0.5),
|
|
92
|
+
_m("claude-fable-5-1", "Claude Fable 5.1", "Anthropic", _CLAUDE, "excellent",
|
|
93
|
+
"Previous Fable; still top-tier, but 5.2 is cheaper.", status="previous", price_in=10, price_out=50),
|
|
94
|
+
_m("claude-opus-5", "Claude Opus 5", "Anthropic", _CLAUDE, "good", "Previous Opus.", status="previous",
|
|
95
|
+
price_in=5, price_out=25),
|
|
96
|
+
_m("claude-sonnet-5", "Claude Sonnet 5", "Anthropic", _CLAUDE, "good", "Previous Sonnet.", status="previous",
|
|
97
|
+
price_in=2, price_out=10),
|
|
98
|
+
_m("claude-opus-4-8", "Claude Opus 4.8", "Anthropic", _CLAUDE, "good", "Older generation.", status="previous",
|
|
99
|
+
price_in=5, price_out=25),
|
|
100
|
+
_m("claude-opus-4-7", "Claude Opus 4.7", "Anthropic", _CLAUDE, "good", "Older generation.", status="previous",
|
|
101
|
+
price_in=5, price_out=25),
|
|
102
|
+
_m("claude-opus-4-6", "Claude Opus 4.6", "Anthropic", _CLAUDE, "good", "Older generation.", status="previous",
|
|
103
|
+
price_in=5, price_out=25),
|
|
104
|
+
_m("claude-sonnet-4-6", "Claude Sonnet 4.6", "Anthropic", _CLAUDE, "fair", "Older generation.",
|
|
105
|
+
status="previous", price_in=3, price_out=15),
|
|
106
|
+
_m("claude-haiku-4-5", "Claude Haiku 4.5", "Anthropic", _CLAUDE, "fair",
|
|
107
|
+
"Older and pricier than Haiku 5.5; prefer 5.5.", status="previous", price_in=1, price_out=5),
|
|
108
|
+
# ---------------------------------------------------------------- OpenAI
|
|
109
|
+
_m("gpt-6.2-sol", "GPT-6.2 Sol", "OpenAI", _OPENAI, "excellent",
|
|
110
|
+
"#2 on Roboflow's OCR leaderboard (87.5%, Nov 2026), close behind Gemini 4 Neon. OpenAI's everyday model.",
|
|
111
|
+
evidence="benchmark", price_in=2, price_out=10),
|
|
112
|
+
_m("gpt-6.2-astra", "GPT-6.2 Astra", "OpenAI", _OPENAI, "good",
|
|
113
|
+
"OpenAI's most capable reasoning model. Extra reasoning rarely helps plain transcription "
|
|
114
|
+
"(GPT-6.1 Sol scored no better at high effort), so Sol is usually the better buy.",
|
|
115
|
+
price_in=8, price_out=40),
|
|
116
|
+
_m("gpt-6.1-terra", "GPT-6.1 Terra", "OpenAI", _OPENAI, "good",
|
|
117
|
+
"Described by OpenAI as tuned for visual reasoning; cheap. A good bulk option.", price_in=1, price_out=5),
|
|
118
|
+
_m("gpt-6.1-sol", "GPT-6.1 Sol", "OpenAI", _OPENAI, "excellent",
|
|
119
|
+
"92.0% on Roboflow's OCR benchmark (Oct 2026); higher reasoning effort did not improve it.",
|
|
120
|
+
evidence="benchmark", status="previous", price_in=2, price_out=10),
|
|
121
|
+
_m("gpt-6-luna", "GPT-6 Luna", "OpenAI", _OPENAI, "fair",
|
|
122
|
+
"OpenAI's most efficient model; fine for clean printed text at very low cost.", price_in=0.1, price_out=0.5),
|
|
123
|
+
_m("gpt-6-sol", "GPT-6 Sol", "OpenAI", _OPENAI, "good", "Previous generation.", status="previous",
|
|
124
|
+
price_in=2, price_out=10),
|
|
125
|
+
_m("gpt-6-astra", "GPT-6 Astra", "OpenAI", _OPENAI, "good", "Previous generation; expensive.",
|
|
126
|
+
status="previous", price_in=10, price_out=50),
|
|
127
|
+
_m("gpt-5.6-sol", "GPT-5.6 Sol", "OpenAI", _OPENAI, "good", "Older generation.", status="previous",
|
|
128
|
+
price_in=4, price_out=20),
|
|
129
|
+
_m("gpt-5.6-terra", "GPT-5.6 Terra", "OpenAI", _OPENAI, "good", "Older generation.", status="previous",
|
|
130
|
+
price_in=2, price_out=12),
|
|
131
|
+
_m("gpt-5.6-luna", "GPT-5.6 Luna", "OpenAI", _OPENAI, "fair", "Older budget model.", status="previous",
|
|
132
|
+
price_in=0.2, price_out=1.2),
|
|
133
|
+
_m("gpt-5.5", "GPT-5.5", "OpenAI", _OPENAI, "good", "Older generation; pricey for what it does here.",
|
|
134
|
+
status="previous", price_in=5, price_out=30),
|
|
135
|
+
_m("gpt-5.4", "GPT-5.4", "OpenAI", _OPENAI, "fair", "Older generation.", status="previous",
|
|
136
|
+
price_in=2.5, price_out=15),
|
|
137
|
+
_m("gpt-5.4-mini", "GPT-5.4 mini", "OpenAI", _OPENAI, "fair", "Older budget model.", status="previous",
|
|
138
|
+
price_in=0.75, price_out=4.5),
|
|
139
|
+
_m("gpt-5.4-nano", "GPT-5.4 nano", "OpenAI", _OPENAI, "fair", "Deprecated by OpenAI.", status="deprecated",
|
|
140
|
+
price_in=0.2, price_out=1.25),
|
|
141
|
+
_m("gpt-5", "GPT-5", "OpenAI", _OPENAI, "fair",
|
|
142
|
+
"Deprecated by OpenAI; move to gpt-6.2-sol (similar price, much better at OCR).", status="deprecated",
|
|
143
|
+
price_in=1.25, price_out=10),
|
|
144
|
+
_m("gpt-5-mini", "GPT-5 mini", "OpenAI", _OPENAI, "fair", "Deprecated by OpenAI; try gpt-6.1-terra.",
|
|
145
|
+
status="deprecated", price_in=0.25, price_out=2),
|
|
146
|
+
_m("gpt-5-nano", "GPT-5 nano", "OpenAI", _OPENAI, "fair", "Deprecated by OpenAI; try gpt-6-luna.",
|
|
147
|
+
status="deprecated", price_in=0.05, price_out=0.4),
|
|
148
|
+
_m("gpt-4.1", "GPT-4.1", "OpenAI", _OPENAI, "fair", "Deprecated by OpenAI.", status="deprecated"),
|
|
149
|
+
_m("gpt-4o", "GPT-4o", "OpenAI", _OPENAI, "fair", "Deprecated by OpenAI.", status="deprecated"),
|
|
150
|
+
_m("gpt-4o-mini", "GPT-4o mini", "OpenAI", _OPENAI, "fair", "Deprecated by OpenAI.", status="deprecated"),
|
|
151
|
+
_m("gpt-oss-120b", "gpt-oss-120b", "OpenAI (open weights)", _OPEN, "unsuitable",
|
|
152
|
+
"Text-only open-weight model: it cannot read images."),
|
|
153
|
+
_m("text-embedding-3-large", "text-embedding-3-large", "OpenAI", _OPENAI, "unsuitable",
|
|
154
|
+
"Embedding model: no image input, no text output."),
|
|
155
|
+
_m("whisper-1", "Whisper", "OpenAI", _OPENAI, "unsuitable", "Speech-to-text: audio only."),
|
|
156
|
+
_m("gpt-image-2.6-sunburst", "GPT Image 2.6", "OpenAI", _OPENAI, "unsuitable",
|
|
157
|
+
"Image generator: makes pictures, doesn't transcribe them."),
|
|
158
|
+
# ---------------------------------------------------------------- Google
|
|
159
|
+
_m("gemini-4-neon", "Gemini 4 Neon", "Google", _GEMINI, "excellent",
|
|
160
|
+
"#1 on Roboflow's OCR leaderboard (88.1%, Nov 19 2026, preliminary single run).",
|
|
161
|
+
evidence="benchmark"),
|
|
162
|
+
_m("gemini-4-argon", "Gemini 4 Argon", "Google", _GEMINI, "excellent",
|
|
163
|
+
"Efficient Gemini 4 reasoning model; led an earlier snapshot of the same leaderboard (85.7%).",
|
|
164
|
+
evidence="benchmark", price_in=2, price_out=10),
|
|
165
|
+
_m("gemini-4-carbon", "Gemini 4 Carbon", "Google", _GEMINI, "good",
|
|
166
|
+
"Google's strongest reasoning model. Not separately benchmarked; Neon/Argon are better value for OCR."),
|
|
167
|
+
_m("gemini-4-hydrogen", "Gemini 4 Hydrogen", "Google", _GEMINI, "good",
|
|
168
|
+
"Google's suggested default for new projects; everyday tier."),
|
|
169
|
+
_m("gemini-3.1-pro-preview", "Gemini 3.1 Pro (preview)", "Google", _GEMINI, "excellent",
|
|
170
|
+
"92.6% on Roboflow's OCR benchmark and 95.9% on data extraction (Oct 2026); fast (~6 s/page). "
|
|
171
|
+
"Best closed model on OmniDocBench in Docsumo's roundup.", evidence="benchmark", status="preview",
|
|
172
|
+
price_in=2, price_out=12),
|
|
173
|
+
_m("gemini-3.8-flash", "Gemini 3.8 Flash", "Google", _GEMINI, "good",
|
|
174
|
+
"Cheap, fast and capable; a sensible bulk default.", price_in=0.83, price_out=4.13),
|
|
175
|
+
_m("gemini-3.6-flash", "Gemini 3.6 Flash", "Google", _GEMINI, "good", "Balanced speed and multimodal quality.",
|
|
176
|
+
status="previous", price_in=0.75, price_out=3.75),
|
|
177
|
+
_m("gemini-3-flash-preview", "Gemini 3 Flash (preview)", "Google", _GEMINI, "good", "Older preview.",
|
|
178
|
+
status="preview", price_in=0.5, price_out=3),
|
|
179
|
+
_m("gemini-3.5-flash-lite", "Gemini 3.5 Flash-Lite", "Google", _GEMINI, "fair",
|
|
180
|
+
"Lowest-cost current Gemini; clean printed pages only.", price_in=0.3, price_out=2.5),
|
|
181
|
+
_m("gemini-3.1-flash-lite", "Gemini 3.1 Flash-Lite", "Google", _GEMINI, "fair", "Older budget model.",
|
|
182
|
+
status="previous", price_in=0.25, price_out=1.5),
|
|
183
|
+
_m("gemini-2.5-pro", "Gemini 2.5 Pro", "Google", _GEMINI, "fair",
|
|
184
|
+
"Deprecated: from Dec 1, 2026 Google routes it to gemini-3.8-flash.", status="deprecated",
|
|
185
|
+
price_in=1.25, price_out=10),
|
|
186
|
+
_m("gemini-2.5-flash", "Gemini 2.5 Flash", "Google", _GEMINI, "fair",
|
|
187
|
+
"Deprecated: from Dec 1, 2026 Google routes it to gemini-3.5-flash-lite.", status="deprecated",
|
|
188
|
+
price_in=0.3, price_out=2.5),
|
|
189
|
+
_m("gemini-2.5-flash-lite", "Gemini 2.5 Flash-Lite", "Google", _GEMINI, "fair",
|
|
190
|
+
"Old but still served; very cheap.", status="previous", price_in=0.1, price_out=0.4),
|
|
191
|
+
_m("gemini-3-pro-image", "Nano Banana Pro (Gemini 3 Pro Image)", "Google", _GEMINI, "unsuitable",
|
|
192
|
+
"Image generator: outputs pictures, not transcriptions."),
|
|
193
|
+
# ------------------------------------------------- open weights (Ollama, vLLM, OpenRouter, ...)
|
|
194
|
+
_m("kimi-k3", "Kimi K3", "Moonshot AI", _OPEN, "excellent",
|
|
195
|
+
"Best open model in Roboflow's OCR test (93.0%), but 2.8T parameters: realistic only via a hosted API.",
|
|
196
|
+
evidence="benchmark", name_varies=True),
|
|
197
|
+
_m("qwen3.8-max", "Qwen3.8 Max", "Alibaba", _OPEN, "excellent",
|
|
198
|
+
"93.4% on Roboflow's OCR benchmark at a low price; slower than peers (~14 s/page). Hosted only.",
|
|
199
|
+
evidence="benchmark", name_varies=True),
|
|
200
|
+
_m("qwen3.8-27b", "Qwen3.8 27B", "Alibaba", _OPEN, "excellent",
|
|
201
|
+
"92.2% on Roboflow's OCR benchmark; the practical self-hosted choice (fits one large GPU).",
|
|
202
|
+
evidence="benchmark", name_varies=True, aliases=("qwen3.8:27b",)),
|
|
203
|
+
_m("gemma-4-31b", "Gemma 4 31B", "Google (open weights)", _OPEN, "good",
|
|
204
|
+
"90.8% on Roboflow's OCR benchmark; permissive licence, runs locally.", evidence="benchmark",
|
|
205
|
+
name_varies=True, aliases=("gemma4:31b",)),
|
|
206
|
+
_m("glm-ocr", "GLM-OCR (0.9B)", "Zhipu AI", _OPEN, "excellent",
|
|
207
|
+
"Tiny dedicated OCR model (95.2% on OmniDocBench). Runs on a laptop; may ignore custom prompts.",
|
|
208
|
+
evidence="benchmark", name_varies=True),
|
|
209
|
+
_m("paddleocr-vl", "PaddleOCR-VL (0.9B)", "Baidu", _OPEN, "excellent",
|
|
210
|
+
"Tiny dedicated document model that tops OmniDocBench (~96). Needs a server that exposes it via "
|
|
211
|
+
"the OpenAI chat API (e.g. vLLM).", evidence="benchmark", name_varies=True),
|
|
212
|
+
_m("qwen3-vl", "Qwen3-VL", "Alibaba", _OPEN, "good",
|
|
213
|
+
"Widely available on Ollama/vLLM; the 235B version scores ~90 on OmniDocBench, small sizes less.",
|
|
214
|
+
evidence="benchmark", status="previous", name_varies=True),
|
|
215
|
+
_m("qwen2.5vl", "Qwen2.5-VL", "Alibaba", _OPEN, "fair", "Older local vision model (e.g. qwen2.5vl:7b on Ollama).",
|
|
216
|
+
status="previous", name_varies=True),
|
|
217
|
+
_m("llama3.2-vision", "Llama 3.2 Vision", "Meta", _OPEN, "fair",
|
|
218
|
+
"Older local vision model; often paraphrases or skips text.", status="previous", name_varies=True),
|
|
219
|
+
_m("llama-4-maverick", "Llama 4 Maverick", "Meta", _OPEN, "fair", "Older open model.", status="previous",
|
|
220
|
+
name_varies=True),
|
|
221
|
+
_m("mistral-small-3.1", "Mistral Small 3.1 24B", "Mistral", _OPEN, "fair", "Older open vision model.",
|
|
222
|
+
status="previous", name_varies=True),
|
|
223
|
+
]
|
|
224
|
+
|
|
225
|
+
# Name fragments that mark a model which cannot transcribe a page image.
|
|
226
|
+
_UNSUITABLE_RE = re.compile(
|
|
227
|
+
r"embed|rerank|tts|whisper|transcribe|moderation|dall-e|gpt-image|imagen|veo|lyria|"
|
|
228
|
+
r"realtime|[-_]audio|audio[-_]|[-_]live|speech|[-_]image(?:$|[-_])|nano-banana|computer-use|codex|search-preview",
|
|
229
|
+
)
|
|
230
|
+
_VISION_RE = re.compile(r"vl|vision|ocr|pixtral|llava|omni|gemma[-_]?[34]|minicpm-v|molmo")
|
|
231
|
+
# What may follow a catalog id inside a longer name: a tag, a date, or a quantisation / variant
|
|
232
|
+
# suffix (Ollama "qwen3.8:27b-q4_K_M", HF "...-Instruct-AWQ"); not another version digit.
|
|
233
|
+
_TRAILER_RE = r"(?=$|[:@/]|-\d{4,}|-(?:latest|q\d|fp\d|bf16|int\d|instruct|it|awq|gptq|gguf|mlx)(?:$|[-.]))"
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _norm(name: str) -> str:
|
|
237
|
+
return name.strip().lower().replace(" ", "-").replace("_", "-")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _patterns(info: ModelInfo) -> list[str]:
|
|
241
|
+
return [_norm(n) for n in (info.id, *info.aliases)]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def lookup(name: str, provider_id: str | None = None) -> dict:
|
|
245
|
+
"""Describe how well ``name`` suits page transcription.
|
|
246
|
+
|
|
247
|
+
Matches the catalog exactly first, then loosely, so ``openai/gpt-6.2-sol`` (OpenRouter),
|
|
248
|
+
``prod-gpt-6.2-sol`` (an Azure deployment) or ``qwen3.8:27b-q4`` (an Ollama tag) are
|
|
249
|
+
recognised. Unknown names get a heuristic verdict and ``match: None``.
|
|
250
|
+
"""
|
|
251
|
+
n = _norm(name)
|
|
252
|
+
if not n:
|
|
253
|
+
return {"name": name, "match": None, "rating": "unrated", "rating_label": RATINGS["unrated"][0],
|
|
254
|
+
"note": ""}
|
|
255
|
+
best: tuple[int, ModelInfo] | None = None
|
|
256
|
+
for info in MODELS:
|
|
257
|
+
for pat in _patterns(info):
|
|
258
|
+
if n == pat:
|
|
259
|
+
best = (10_000, info)
|
|
260
|
+
break
|
|
261
|
+
if re.search(r"(?:^|[/:._-])" + re.escape(pat) + _TRAILER_RE, n):
|
|
262
|
+
if best is None or len(pat) > best[0]:
|
|
263
|
+
best = (len(pat), info)
|
|
264
|
+
if best and best[0] == 10_000:
|
|
265
|
+
break
|
|
266
|
+
if best:
|
|
267
|
+
info = best[1]
|
|
268
|
+
out = {"name": name, "match": info.id, "exact": best[0] == 10_000, **info.to_json()}
|
|
269
|
+
out["id"] = info.id
|
|
270
|
+
if provider_id and provider_id not in info.providers:
|
|
271
|
+
out["note"] = f"{info.note} (Usually not offered by this provider.)"
|
|
272
|
+
return out
|
|
273
|
+
if _UNSUITABLE_RE.search(n):
|
|
274
|
+
rating, note = "unsuitable", "Looks like a non-vision model (embeddings, audio, image generation, code...)."
|
|
275
|
+
elif _VISION_RE.search(n):
|
|
276
|
+
rating, note = "unrated", "Not in the catalog, but the name suggests a vision model. Try Test connection."
|
|
277
|
+
else:
|
|
278
|
+
rating, note = "unrated", "Not in the catalog. Make sure it accepts images, then try Test connection."
|
|
279
|
+
return {"name": name, "match": None, "rating": rating, "rating_label": RATINGS[rating][0], "note": note}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def price(name: str, provider_id: str | None = None) -> tuple[float, float, str] | None:
|
|
283
|
+
"""``(usd_per_1m_in, usd_per_1m_out, catalog_id)`` for a model name, or None if unknown."""
|
|
284
|
+
info = lookup(name, provider_id)
|
|
285
|
+
if info.get("match") and info.get("price_in") is not None and info.get("price_out") is not None:
|
|
286
|
+
return info["price_in"], info["price_out"], info["match"]
|
|
287
|
+
return None
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _sort_key(info: ModelInfo) -> tuple:
|
|
291
|
+
status_order = {"current": 0, "preview": 1, "previous": 2, "deprecated": 3}
|
|
292
|
+
return (RATINGS[info.rating][1], status_order.get(info.status, 9), info.price_in or 0)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def search(q: str = "", provider_id: str | None = None, rating: str | None = None,
|
|
296
|
+
include_deprecated: bool = True) -> list[ModelInfo]:
|
|
297
|
+
"""Filter the catalog by free text (id, label, vendor, note), provider and rating."""
|
|
298
|
+
words = [w for w in _norm(q).split("-") if w] if q else []
|
|
299
|
+
out = []
|
|
300
|
+
for info in MODELS:
|
|
301
|
+
if provider_id and provider_id not in info.providers:
|
|
302
|
+
continue
|
|
303
|
+
if rating and info.rating != rating:
|
|
304
|
+
continue
|
|
305
|
+
if not include_deprecated and info.status == "deprecated":
|
|
306
|
+
continue
|
|
307
|
+
hay = _norm(" ".join([info.id, info.label, info.vendor, info.note, info.status, *info.aliases]))
|
|
308
|
+
if all(w in hay for w in words):
|
|
309
|
+
out.append(info)
|
|
310
|
+
return sorted(out, key=_sort_key)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def recommended(provider_id: str, limit: int = 6) -> list[str]:
|
|
314
|
+
"""Model ids worth suggesting first for a provider (current, rated good or better)."""
|
|
315
|
+
picks = [m for m in search(provider_id=provider_id)
|
|
316
|
+
if m.rating in ("excellent", "good") and m.status in ("current", "preview") and not m.name_varies]
|
|
317
|
+
return [m.id for m in picks[:limit]]
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def model_options(provider_id: str, suggested: list[str]) -> list[dict]:
|
|
321
|
+
"""What a model input should offer: the provider's suggestions, then the rest of the catalog.
|
|
322
|
+
|
|
323
|
+
Unsuitable and deprecated models are left out of the dropdown (they're still searchable on the
|
|
324
|
+
Models page and still accepted if typed). Families whose name varies per server are left out
|
|
325
|
+
too, since their catalog id is not something a server will recognise.
|
|
326
|
+
"""
|
|
327
|
+
out, seen = [], set()
|
|
328
|
+
for name in suggested:
|
|
329
|
+
if name and name not in seen:
|
|
330
|
+
seen.add(name)
|
|
331
|
+
out.append(lookup(name, provider_id))
|
|
332
|
+
for m in search(provider_id=provider_id, include_deprecated=False):
|
|
333
|
+
if m.id in seen or m.rating == "unsuitable" or m.name_varies:
|
|
334
|
+
continue
|
|
335
|
+
seen.add(m.id)
|
|
336
|
+
out.append(lookup(m.id, provider_id))
|
|
337
|
+
return out
|