evaltrack 0.1.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.
- evaltrack/__init__.py +65 -0
- evaltrack/cli.py +606 -0
- evaltrack/config.py +185 -0
- evaltrack/context.py +112 -0
- evaltrack/core/__init__.py +26 -0
- evaltrack/core/errors.py +59 -0
- evaltrack/core/eval_round.py +123 -0
- evaltrack/core/gate.py +77 -0
- evaltrack/core/projection.py +124 -0
- evaltrack/core/recorder.py +176 -0
- evaltrack/core/refs.py +82 -0
- evaltrack/core/repetition.py +152 -0
- evaltrack/core/results.py +167 -0
- evaltrack/core/run_context.py +12 -0
- evaltrack/core/run_record.py +319 -0
- evaltrack/core/score_bars.py +70 -0
- evaltrack/core/user_values.py +162 -0
- evaltrack/failure.py +110 -0
- evaltrack/history/__init__.py +4 -0
- evaltrack/history/reliability.py +180 -0
- evaltrack/history/score_history.py +175 -0
- evaltrack/history/segments.py +106 -0
- evaltrack/marked_test.py +352 -0
- evaltrack/py.typed +0 -0
- evaltrack/pytest_plugin.py +521 -0
- evaltrack/repositories/__init__.py +68 -0
- evaltrack/repositories/azure.py +179 -0
- evaltrack/repositories/file.py +153 -0
- evaltrack/repositories/lifecycle.py +147 -0
- evaltrack/repositories/repository.py +438 -0
- evaltrack/repositories/store.py +56 -0
- evaltrack/translators/__init__.py +120 -0
- evaltrack/translators/deepeval.py +260 -0
- evaltrack/translators/protocol.py +13 -0
- evaltrack/translators/pydantic_evals.py +195 -0
- evaltrack/ui/__init__.py +7 -0
- evaltrack/ui/app.py +173 -0
- evaltrack/ui/models.py +77 -0
- evaltrack/ui/routes/__init__.py +6 -0
- evaltrack/ui/routes/history.py +119 -0
- evaltrack/ui/routes/meta.py +29 -0
- evaltrack/ui/routes/refs.py +114 -0
- evaltrack/ui/routes/runs.py +116 -0
- evaltrack/ui/routes/static.py +37 -0
- evaltrack/ui/security.py +41 -0
- evaltrack/ui/static/assets/index-BZO2JqWB.css +1 -0
- evaltrack/ui/static/assets/index-Cg522kcf.js +56 -0
- evaltrack/ui/static/favicon.svg +9 -0
- evaltrack/ui/static/index.html +14 -0
- evaltrack-0.1.0.dist-info/METADATA +281 -0
- evaltrack-0.1.0.dist-info/RECORD +54 -0
- evaltrack-0.1.0.dist-info/WHEEL +4 -0
- evaltrack-0.1.0.dist-info/entry_points.txt +5 -0
- evaltrack-0.1.0.dist-info/licenses/LICENSE +21 -0
evaltrack/config.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""Project configuration from the `[tool.evaltrack]` table in pyproject.toml."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import tomllib
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Annotated, Literal
|
|
8
|
+
|
|
9
|
+
from pydantic import AfterValidator, BaseModel, ConfigDict, ValidationError
|
|
10
|
+
|
|
11
|
+
# `local` is where this project's own runs go. `remote` is the shared repository.
|
|
12
|
+
RepositoryRole = Literal["local", "remote"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _check_pr_url_template(value: str) -> str:
|
|
16
|
+
if "{pr}" not in value:
|
|
17
|
+
raise ValueError(
|
|
18
|
+
"pr_url_template must contain the '{pr}' placeholder "
|
|
19
|
+
"(e.g. 'https://github.com/OWNER/REPO/pull/{pr}')"
|
|
20
|
+
)
|
|
21
|
+
# `javascript:` and `data:` schemes execute when the link is followed.
|
|
22
|
+
if not value.lower().startswith(("http://", "https://")):
|
|
23
|
+
raise ValueError(
|
|
24
|
+
"pr_url_template must be an http(s) URL (got a non-http scheme)"
|
|
25
|
+
)
|
|
26
|
+
return value
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Every carrier of a template uses this type, so no value reaches a link target
|
|
30
|
+
# without the scheme check.
|
|
31
|
+
PrUrlTemplate = Annotated[str, AfterValidator(_check_pr_url_template)]
|
|
32
|
+
|
|
33
|
+
LOCAL_ENV = "EVALTRACK_LOCAL"
|
|
34
|
+
REMOTE_ENV = "EVALTRACK_REMOTE"
|
|
35
|
+
DEFAULT_LOCAL_PATH = "./.evaltrack"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class EvaltrackConfig(BaseModel):
|
|
39
|
+
"""The `[tool.evaltrack]` table. All fields optional. An unknown key is refused.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
local: The working repository, a directory path or a repository URL.
|
|
43
|
+
Unset means `./.evaltrack`. A relative path resolves against the
|
|
44
|
+
pyproject.toml's directory.
|
|
45
|
+
remote: The shared repository, a directory path or a repository URL.
|
|
46
|
+
A relative path resolves as for `local`.
|
|
47
|
+
keep_raw_results: Store the eval runner's own result objects too.
|
|
48
|
+
pr_url_template: Link target for a PR ref, with a `{pr}` placeholder.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
model_config = ConfigDict(extra="forbid")
|
|
52
|
+
|
|
53
|
+
local: str | None = None
|
|
54
|
+
remote: str | None = None
|
|
55
|
+
keep_raw_results: bool = False
|
|
56
|
+
pr_url_template: PrUrlTemplate | None = None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def names_a_url(location: str) -> bool:
|
|
60
|
+
"""Whether `location` names a repository URL rather than a directory path,
|
|
61
|
+
including one written without its `://`. A ':' in the first segment can only
|
|
62
|
+
be a scheme, since a directory path must carry none there."""
|
|
63
|
+
if "://" in location:
|
|
64
|
+
return True
|
|
65
|
+
scheme, colon, _ = location.partition(":")
|
|
66
|
+
return bool(colon) and "/" not in scheme
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def anchor_path(location: str, base: Path) -> str:
|
|
70
|
+
"""Rewrite a relative directory path to an absolute one under `base`. A URL,
|
|
71
|
+
an absolute path and a `~` path come back unchanged.
|
|
72
|
+
|
|
73
|
+
A URL written without its `://` is left alone too, so it stays recognisable
|
|
74
|
+
as a URL instead of turning into a relative path with a ':' mid-way.
|
|
75
|
+
"""
|
|
76
|
+
if names_a_url(location) or location.startswith("~") or os.path.isabs(location):
|
|
77
|
+
return location
|
|
78
|
+
return os.path.normpath(os.path.join(base, location))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def project_root(start: Path | None = None) -> Path:
|
|
82
|
+
"""The nearest directory at or above `start` (default cwd) holding a pyproject.toml,
|
|
83
|
+
else `start` itself."""
|
|
84
|
+
pyproject = _find_pyproject(start)
|
|
85
|
+
if pyproject is not None:
|
|
86
|
+
return pyproject.parent
|
|
87
|
+
return (start or Path.cwd()).resolve()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _find_pyproject(start: Path | None = None) -> Path | None:
|
|
91
|
+
base = (start or Path.cwd()).resolve()
|
|
92
|
+
for directory in (base, *base.parents):
|
|
93
|
+
candidate = directory / "pyproject.toml"
|
|
94
|
+
if candidate.is_file():
|
|
95
|
+
return candidate
|
|
96
|
+
return None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _describe_config_errors(exc: ValidationError) -> str:
|
|
100
|
+
"""Render the rejected keys without their values, which can carry a SAS token."""
|
|
101
|
+
return "".join(
|
|
102
|
+
f"\n {'.'.join(str(part) for part in error['loc']) or '[tool.evaltrack]'}: "
|
|
103
|
+
f"{error['msg']}"
|
|
104
|
+
for error in exc.errors(include_input=False)
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def load_config(start: Path | None = None) -> EvaltrackConfig:
|
|
109
|
+
"""Load `[tool.evaltrack]` from the nearest pyproject.toml, empty when there is
|
|
110
|
+
none.
|
|
111
|
+
|
|
112
|
+
`local` and `remote` are a directory path or a repository URL. A relative
|
|
113
|
+
path is anchored to the pyproject's directory.
|
|
114
|
+
|
|
115
|
+
Raises:
|
|
116
|
+
ValueError: naming the file when it is not valid TOML, or when the
|
|
117
|
+
`[tool.evaltrack]` table holds an unknown key or an invalid value.
|
|
118
|
+
"""
|
|
119
|
+
path = _find_pyproject(start)
|
|
120
|
+
if path is None:
|
|
121
|
+
return EvaltrackConfig()
|
|
122
|
+
try:
|
|
123
|
+
data = tomllib.loads(path.read_text(encoding="utf-8"))
|
|
124
|
+
except tomllib.TOMLDecodeError as exc:
|
|
125
|
+
raise ValueError(f"could not parse {path}: {exc}") from exc
|
|
126
|
+
tool = data.get("tool", {})
|
|
127
|
+
if not isinstance(tool, dict):
|
|
128
|
+
# `tool = 5` is valid TOML.
|
|
129
|
+
raise ValueError(
|
|
130
|
+
f"invalid pyproject.toml at {path}: top-level 'tool' must be a "
|
|
131
|
+
f"table, got {type(tool).__name__}"
|
|
132
|
+
)
|
|
133
|
+
try:
|
|
134
|
+
config = EvaltrackConfig.model_validate(tool.get("evaltrack", {}))
|
|
135
|
+
except ValidationError as exc:
|
|
136
|
+
# The file is found by searching upward, so the message must name it.
|
|
137
|
+
raise ValueError(
|
|
138
|
+
f"invalid [tool.evaltrack] in {path}: {_describe_config_errors(exc)}"
|
|
139
|
+
) from exc
|
|
140
|
+
base = path.parent
|
|
141
|
+
return config.model_copy(
|
|
142
|
+
update={
|
|
143
|
+
role: anchor_path(location, base) if location else None
|
|
144
|
+
for role, location in (("local", config.local), ("remote", config.remote))
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@dataclass(frozen=True)
|
|
150
|
+
class ConfiguredRemote:
|
|
151
|
+
"""A configured remote repository and the label naming where it came from."""
|
|
152
|
+
|
|
153
|
+
url: str
|
|
154
|
+
source: str
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def resolve_local(
|
|
158
|
+
config: EvaltrackConfig, *, override: str | None = None, start: Path | None = None
|
|
159
|
+
) -> str:
|
|
160
|
+
"""The local repository: `override`, then `$EVALTRACK_LOCAL`, then `config.local`,
|
|
161
|
+
else `./.evaltrack` under the project at or above `start` (default cwd).
|
|
162
|
+
|
|
163
|
+
An override and an environment value are used as written, so a relative path
|
|
164
|
+
in either follows the working directory, as a typed one does.
|
|
165
|
+
"""
|
|
166
|
+
if override:
|
|
167
|
+
return override
|
|
168
|
+
env = os.environ.get(LOCAL_ENV)
|
|
169
|
+
if env:
|
|
170
|
+
return env
|
|
171
|
+
return config.local or anchor_path(DEFAULT_LOCAL_PATH, project_root(start))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def resolve_remote(config: EvaltrackConfig) -> ConfiguredRemote | None:
|
|
175
|
+
"""The remote repository: `$EVALTRACK_REMOTE`, then `config.remote`, else None.
|
|
176
|
+
|
|
177
|
+
A remote is optional and its source is displayed, where a local one is
|
|
178
|
+
neither, so this returns a different shape from `resolve_local`.
|
|
179
|
+
"""
|
|
180
|
+
env = os.environ.get(REMOTE_ENV)
|
|
181
|
+
if env:
|
|
182
|
+
return ConfiguredRemote(env, f"${REMOTE_ENV}")
|
|
183
|
+
if config.remote:
|
|
184
|
+
return ConfiguredRemote(config.remote, "[tool.evaltrack].remote")
|
|
185
|
+
return None
|
evaltrack/context.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Run context detection from git, env, or both."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import subprocess # nosec B404 - used only for `git rev-parse`-style metadata lookups
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from functools import partial
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from evaltrack.core.run_context import RunContext
|
|
10
|
+
|
|
11
|
+
_ENV_LABEL_PREFIX = "EVALTRACK_LABEL_"
|
|
12
|
+
|
|
13
|
+
# Detection must never fail a run, so any failure to launch git means no
|
|
14
|
+
# context. `CalledProcessError` is not an `OSError`, so it is named too.
|
|
15
|
+
_GIT_UNAVAILABLE = (subprocess.CalledProcessError, OSError)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def build_from_env() -> RunContext:
|
|
19
|
+
"""Build a `RunContext` from environment variables.
|
|
20
|
+
|
|
21
|
+
Reads `EVALTRACK_COMMIT`, `EVALTRACK_BRANCH`, and any
|
|
22
|
+
`EVALTRACK_LABEL_<KEY>` variable (lowercased after the prefix).
|
|
23
|
+
"""
|
|
24
|
+
labels: dict[str, str] = {}
|
|
25
|
+
if branch := os.environ.get("EVALTRACK_BRANCH"):
|
|
26
|
+
labels["branch"] = branch
|
|
27
|
+
for key, value in os.environ.items():
|
|
28
|
+
if key.startswith(_ENV_LABEL_PREFIX) and value:
|
|
29
|
+
labels[key[len(_ENV_LABEL_PREFIX) :].lower()] = value
|
|
30
|
+
return RunContext(commit=os.environ.get("EVALTRACK_COMMIT") or None, labels=labels)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def build_from_git(
|
|
34
|
+
runner: Callable[[list[str]], str | None] | None = None,
|
|
35
|
+
dirty_check: Callable[[], bool | None] | None = None,
|
|
36
|
+
*,
|
|
37
|
+
cwd: Path | None = None,
|
|
38
|
+
) -> RunContext | None:
|
|
39
|
+
"""Build a `RunContext` from git, or None when git is unavailable or `cwd` is not a
|
|
40
|
+
repo.
|
|
41
|
+
|
|
42
|
+
`dirty_check` is separate from `runner` because empty stdout means "clean"
|
|
43
|
+
here, while the `runner` contract reads empty output as a failure. `cwd`
|
|
44
|
+
applies to the default runners only.
|
|
45
|
+
"""
|
|
46
|
+
run = runner if runner is not None else partial(_default_git_runner, cwd=cwd)
|
|
47
|
+
check_dirty = (
|
|
48
|
+
dirty_check
|
|
49
|
+
if dirty_check is not None
|
|
50
|
+
else partial(_default_dirty_check, cwd=cwd)
|
|
51
|
+
)
|
|
52
|
+
commit = run(["rev-parse", "HEAD"])
|
|
53
|
+
if not commit:
|
|
54
|
+
return None
|
|
55
|
+
labels: dict[str, str] = {}
|
|
56
|
+
branch = run(["rev-parse", "--abbrev-ref", "HEAD"])
|
|
57
|
+
# `--abbrev-ref` yields the literal "HEAD" on a detached HEAD.
|
|
58
|
+
if branch and branch != "HEAD":
|
|
59
|
+
labels["branch"] = branch
|
|
60
|
+
return RunContext(commit=commit, worktree_dirty=check_dirty(), labels=labels)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def detect(
|
|
64
|
+
git_runner: Callable[[list[str]], str | None] | None = None,
|
|
65
|
+
dirty_check: Callable[[], bool | None] | None = None,
|
|
66
|
+
*,
|
|
67
|
+
cwd: Path | None = None,
|
|
68
|
+
) -> RunContext:
|
|
69
|
+
"""Build a `RunContext` from git, overlaid with `build_from_env()`.
|
|
70
|
+
|
|
71
|
+
An env var wins over git output. In CI, git can return a temporary merge
|
|
72
|
+
commit rather than the real source SHA. When the env var overrides the
|
|
73
|
+
commit, git's `dirty` and `branch` are dropped rather than recorded against
|
|
74
|
+
a different commit.
|
|
75
|
+
"""
|
|
76
|
+
base = build_from_git(git_runner, dirty_check, cwd=cwd) or RunContext()
|
|
77
|
+
overlay = build_from_env()
|
|
78
|
+
base_labels = {} if overlay.commit else base.labels
|
|
79
|
+
return RunContext(
|
|
80
|
+
commit=overlay.commit or base.commit,
|
|
81
|
+
worktree_dirty=None if overlay.commit else base.worktree_dirty,
|
|
82
|
+
labels={**base_labels, **overlay.labels},
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _default_git_runner(args: list[str], *, cwd: Path | None = None) -> str | None:
|
|
87
|
+
try:
|
|
88
|
+
result = subprocess.run( # nosec B603 B607: git invocation with literal args
|
|
89
|
+
["git", *args],
|
|
90
|
+
capture_output=True,
|
|
91
|
+
text=True,
|
|
92
|
+
check=True,
|
|
93
|
+
cwd=cwd,
|
|
94
|
+
)
|
|
95
|
+
except _GIT_UNAVAILABLE:
|
|
96
|
+
return None
|
|
97
|
+
return result.stdout.strip() or None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _default_dirty_check(*, cwd: Path | None = None) -> bool | None:
|
|
101
|
+
"""`--porcelain` lists untracked files, so they count as dirty."""
|
|
102
|
+
try:
|
|
103
|
+
result = subprocess.run( # nosec B603 B607: git invocation with literal args
|
|
104
|
+
["git", "status", "--porcelain"],
|
|
105
|
+
capture_output=True,
|
|
106
|
+
text=True,
|
|
107
|
+
check=True,
|
|
108
|
+
cwd=cwd,
|
|
109
|
+
)
|
|
110
|
+
except _GIT_UNAVAILABLE:
|
|
111
|
+
return None
|
|
112
|
+
return result.stdout.strip() != ""
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""The eval data model and the rules that act on it. It imports nothing from the
|
|
2
|
+
rest of evaltrack, and nothing outside the standard library but pydantic and
|
|
3
|
+
python-ulid.
|
|
4
|
+
|
|
5
|
+
evaltrack has two data models for a recorded eval. `EvalRound` is what the eval
|
|
6
|
+
produced, a flat list of attempts. `RunRecord` is what a repository stores, a
|
|
7
|
+
tree of tests, then cases, then attempts. A translator builds the first from
|
|
8
|
+
whatever the runner returned, and `projection` builds the second from the first:
|
|
9
|
+
|
|
10
|
+
runner result --(translator)--> EvalRound --(projection)--> RunRecord
|
|
11
|
+
flat tree
|
|
12
|
+
|
|
13
|
+
`RunRecord` is derived from the rounds, not a copy of them. `projection` builds
|
|
14
|
+
it, and nothing goes back the other way. On the way it:
|
|
15
|
+
|
|
16
|
+
- groups the attempts of a case under one key, and keeps one copy of the case's
|
|
17
|
+
inputs, expected output and metadata
|
|
18
|
+
- derives an outcome for each attempt and for each case, and counts a case's
|
|
19
|
+
passes
|
|
20
|
+
|
|
21
|
+
The models differ in what they accept. A round refuses a field it does not
|
|
22
|
+
declare, since what describes the round itself is not stored. Every stored model
|
|
23
|
+
accepts fields it does not declare, because a run written by a newer evaltrack
|
|
24
|
+
still has to load in an older one. The result and error records are stored as
|
|
25
|
+
well, so either accepts an undeclared field even inside a round that refuses one.
|
|
26
|
+
"""
|
evaltrack/core/errors.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Every public evaltrack exception. One `except EvaltrackError` catches them all."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EvaltrackError(Exception):
|
|
5
|
+
"""Base class of every public evaltrack exception."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class EvalExecutionError(EvaltrackError):
|
|
9
|
+
"""A task or evaluator raised."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class EvalDefinitionError(EvaltrackError):
|
|
13
|
+
"""The eval as defined cannot produce a verdict. Some of this shows only
|
|
14
|
+
after the eval ran, but none of it depends on what the model answered, so
|
|
15
|
+
running the eval again cannot change it."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class InvalidIdentifierError(EvaltrackError):
|
|
19
|
+
"""A ref name or run id that breaks the naming rules."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CorruptRecordError(EvaltrackError):
|
|
23
|
+
"""Stored bytes that cannot be read as the record they are keyed as, a run or
|
|
24
|
+
a reflog. Raised only when a caller asked for that record."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class UnsupportedSchemaError(EvaltrackError):
|
|
28
|
+
"""A run stamped with a stored format this evaltrack does not read. The fix
|
|
29
|
+
is to use the evaltrack that wrote it, not to delete the run."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class RefNotFoundError(EvaltrackError):
|
|
33
|
+
"""No ref exists under `name`."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, name: str) -> None:
|
|
36
|
+
self.name = name
|
|
37
|
+
super().__init__(f"ref does not exist: {name}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class RunReferencedError(EvaltrackError):
|
|
41
|
+
"""A run deletion refused because `refs` still reach the run."""
|
|
42
|
+
|
|
43
|
+
def __init__(self, run_id: str, refs: list[str]) -> None:
|
|
44
|
+
self.run_id = run_id
|
|
45
|
+
self.refs = refs
|
|
46
|
+
super().__init__(f"run {run_id} is referenced by: {', '.join(refs)}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class BaselineRefProtectedError(EvaltrackError):
|
|
50
|
+
"""A delete targets the reserved `baseline` ref."""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class RepositoryUnavailableError(EvaltrackError):
|
|
54
|
+
"""The storage cannot serve the request. The cause is the environment, not a
|
|
55
|
+
bug and not a missing run or ref. No storage SDK exception type escapes."""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class TranslatorNotFoundError(EvaltrackError):
|
|
59
|
+
"""No registered translator handles a result."""
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""One round of an eval in runner-neutral terms. Attempts are a flat list, each
|
|
2
|
+
tagged with the case it belongs to.
|
|
3
|
+
|
|
4
|
+
Nothing in this module is stored, except an error record. A run keeps one as it
|
|
5
|
+
stands, so it accepts a field it does not declare, the way every stored model
|
|
6
|
+
does.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from collections import defaultdict
|
|
10
|
+
from collections.abc import Iterable
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, ConfigDict, Field, FiniteFloat
|
|
13
|
+
|
|
14
|
+
from evaltrack.core.results import (
|
|
15
|
+
EvaluatorResult,
|
|
16
|
+
RunnerInfo,
|
|
17
|
+
)
|
|
18
|
+
from evaltrack.core.user_values import UserStr, UserValue
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AttemptErrorRecord(BaseModel):
|
|
22
|
+
"""Something that raised while producing or judging one attempt.
|
|
23
|
+
|
|
24
|
+
Attributes:
|
|
25
|
+
message: The exception's type and message, without a traceback.
|
|
26
|
+
evaluator: The evaluator that raised, or None when the task raised.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
model_config = ConfigDict(frozen=True, extra="allow")
|
|
30
|
+
|
|
31
|
+
message: UserStr
|
|
32
|
+
evaluator: str | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RoundErrorRecord(BaseModel):
|
|
36
|
+
"""A failure that belongs to the whole round rather than to one attempt.
|
|
37
|
+
|
|
38
|
+
Attributes:
|
|
39
|
+
name: What the runner calls this failure.
|
|
40
|
+
message: The exception's type and message, without a traceback.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
model_config = ConfigDict(frozen=True, extra="allow")
|
|
44
|
+
|
|
45
|
+
name: str
|
|
46
|
+
message: UserStr
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class RoundAttempt(BaseModel):
|
|
50
|
+
"""One attempt at one case.
|
|
51
|
+
|
|
52
|
+
Attributes:
|
|
53
|
+
case_id: The case this is an attempt at. Never empty, since it is the
|
|
54
|
+
key attempts are grouped by.
|
|
55
|
+
inputs: What the task was given, as the runner reported it.
|
|
56
|
+
expected_output: What the case expected, or None when it declares none.
|
|
57
|
+
metadata: The case's own metadata, as the runner reported it.
|
|
58
|
+
output: What the task produced. None when the task raised.
|
|
59
|
+
results: What each evaluator returned, keyed by result name.
|
|
60
|
+
task_duration: Seconds the task took, or None.
|
|
61
|
+
errors: What raised while producing or judging this attempt. An attempt
|
|
62
|
+
with any error never passes.
|
|
63
|
+
details: Runner-specific data, stored as produced and never interpreted.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True, extra="forbid")
|
|
67
|
+
|
|
68
|
+
case_id: str = Field(min_length=1)
|
|
69
|
+
inputs: UserValue = None
|
|
70
|
+
expected_output: UserValue = None
|
|
71
|
+
metadata: UserValue = None
|
|
72
|
+
output: UserValue = None
|
|
73
|
+
results: dict[str, EvaluatorResult] = {}
|
|
74
|
+
task_duration: FiniteFloat | None = None
|
|
75
|
+
errors: list[AttemptErrorRecord] = []
|
|
76
|
+
details: dict[str, UserValue] = {}
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def errored(self) -> bool:
|
|
80
|
+
return bool(self.errors)
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def passed(self) -> bool:
|
|
84
|
+
"""Whether the attempt is clean and no result failed.
|
|
85
|
+
|
|
86
|
+
A verdict of None is a score the marker's bars have not reached yet.
|
|
87
|
+
The round is refused if one survives them, so by the time anything asks
|
|
88
|
+
this, every result has answered.
|
|
89
|
+
"""
|
|
90
|
+
if self.errored:
|
|
91
|
+
return False
|
|
92
|
+
return all(result.verdict is not False for result in self.results.values())
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class EvalRound(BaseModel):
|
|
96
|
+
"""One batch of cases, put through the runner once. Build one directly to
|
|
97
|
+
record an eval from a runner that has no translator.
|
|
98
|
+
|
|
99
|
+
Attributes:
|
|
100
|
+
runner: Which eval runner produced the batch, and at what version.
|
|
101
|
+
attempts: Every attempt in the batch, in the runner's order. Repetitions
|
|
102
|
+
of one case are separate entries sharing a `case_id`.
|
|
103
|
+
errors: What failed outside any single attempt.
|
|
104
|
+
details: Runner-specific data, stored as produced and never interpreted.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True, extra="forbid")
|
|
108
|
+
|
|
109
|
+
runner: RunnerInfo
|
|
110
|
+
attempts: list[RoundAttempt] = []
|
|
111
|
+
errors: list[RoundErrorRecord] = []
|
|
112
|
+
details: dict[str, UserValue] = {}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def group_by_case_id(
|
|
116
|
+
attempts: Iterable[RoundAttempt],
|
|
117
|
+
) -> dict[str, list[RoundAttempt]]:
|
|
118
|
+
"""Attempts keyed by `case_id`, keys in first-seen order and each group in the
|
|
119
|
+
order given."""
|
|
120
|
+
groups: dict[str, list[RoundAttempt]] = defaultdict(list)
|
|
121
|
+
for attempt in attempts:
|
|
122
|
+
groups[attempt.case_id].append(attempt)
|
|
123
|
+
return dict(groups)
|
evaltrack/core/gate.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Two refusals that keep the gate decidable.
|
|
2
|
+
|
|
3
|
+
evaltrack gates on every result, so a round it cannot decide in full is refused.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from difflib import get_close_matches
|
|
7
|
+
|
|
8
|
+
from evaltrack.core.errors import EvalDefinitionError
|
|
9
|
+
from evaltrack.core.eval_round import EvalRound
|
|
10
|
+
from evaltrack.core.results import EvaluatorResult
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def raise_on_unknown_result_fields(eval_round: EvalRound) -> None:
|
|
14
|
+
"""Refuse a result that carries a field it does not declare.
|
|
15
|
+
|
|
16
|
+
The field is usually a misspelt `bar=` or `verdict=`. A name evaltrack does
|
|
17
|
+
not know decides nothing, so the case passes on a check that never ran.
|
|
18
|
+
"""
|
|
19
|
+
__tracebackhide__ = True
|
|
20
|
+
declared = list(EvaluatorResult.model_fields)
|
|
21
|
+
for attempt in eval_round.attempts:
|
|
22
|
+
for name, result in attempt.results.items():
|
|
23
|
+
unknown = sorted(result.__pydantic_extra__ or {})
|
|
24
|
+
if not unknown:
|
|
25
|
+
continue
|
|
26
|
+
hints = [
|
|
27
|
+
f"did you mean {match[0]!r}?"
|
|
28
|
+
for key in unknown
|
|
29
|
+
if (match := get_close_matches(key, declared, n=1))
|
|
30
|
+
]
|
|
31
|
+
hint = f" {' '.join(hints)}" if hints else ""
|
|
32
|
+
raise EvalDefinitionError(
|
|
33
|
+
f"evaltrack: the result {name!r} on case {attempt.case_id!r} "
|
|
34
|
+
f"carries {', '.join(map(repr, unknown))}, which EvaluatorResult "
|
|
35
|
+
f"does not declare.{hint} An unknown field gates nothing, so it "
|
|
36
|
+
"is refused rather than recorded. Its fields are "
|
|
37
|
+
f"{', '.join(declared)}."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def raise_unless_every_result_gates(eval_round: EvalRound, nodeid: str) -> None:
|
|
42
|
+
"""Refuse a round the gate cannot decide in full.
|
|
43
|
+
|
|
44
|
+
A score answers only through a bar. The marker's bars are applied by now,
|
|
45
|
+
so a score still without one has none from either side. An attempt
|
|
46
|
+
that evaluated nothing passes on an empty set of checks, which is the same
|
|
47
|
+
mistake with nothing to name. Runs after the crash report, so an attempt
|
|
48
|
+
with no results here is one that ran and judged nothing.
|
|
49
|
+
"""
|
|
50
|
+
__tracebackhide__ = True
|
|
51
|
+
bare = sorted(
|
|
52
|
+
{
|
|
53
|
+
name
|
|
54
|
+
for attempt in eval_round.attempts
|
|
55
|
+
for name, result in attempt.results.items()
|
|
56
|
+
if result.verdict is None
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
if bare:
|
|
60
|
+
raise EvalDefinitionError(
|
|
61
|
+
f"evaltrack: {', '.join(bare)} scored without a bar, so nothing in "
|
|
62
|
+
f"{nodeid} judges them and the eval reads as checked where it is "
|
|
63
|
+
"not. Give each one a bar with score_bars={...} on the marker, or "
|
|
64
|
+
"with runner_bar= on the EvaluatorResult in a translator, or stop "
|
|
65
|
+
"recording it."
|
|
66
|
+
)
|
|
67
|
+
# Per attempt, not per case. Under repeats= a case with one evaluated
|
|
68
|
+
# attempt and one empty one passes on the empty half.
|
|
69
|
+
unevaluated = sorted(
|
|
70
|
+
{attempt.case_id for attempt in eval_round.attempts if not attempt.results}
|
|
71
|
+
)
|
|
72
|
+
if unevaluated:
|
|
73
|
+
raise EvalDefinitionError(
|
|
74
|
+
f"evaltrack: {', '.join(unevaluated)} recorded no results, so they "
|
|
75
|
+
"pass whatever they produced. Evaluate them, or drop them from the "
|
|
76
|
+
"dataset."
|
|
77
|
+
)
|