trialmark 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.
- trialmark/__init__.py +28 -0
- trialmark/cli.py +85 -0
- trialmark/passmark.py +117 -0
- trialmark/record.py +131 -0
- trialmark/report.py +123 -0
- trialmark/testset.py +97 -0
- trialmark-0.1.0.dist-info/METADATA +152 -0
- trialmark-0.1.0.dist-info/RECORD +11 -0
- trialmark-0.1.0.dist-info/WHEEL +4 -0
- trialmark-0.1.0.dist-info/entry_points.txt +2 -0
- trialmark-0.1.0.dist-info/licenses/LICENSE +202 -0
trialmark/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Trialmark: model acceptance tests with a pass mark set before the run."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
from .passmark import Decision, PassMark, decide, parse_pass_mark # noqa: E402
|
|
6
|
+
from .record import ModelEntry, Result, RunRecord, load_record, parse_record # noqa: E402
|
|
7
|
+
from .report import decision, summarise, text_report # noqa: E402
|
|
8
|
+
from .testset import Case, TestSet, hash_cases, load_test_set, parse_test_set # noqa: E402
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Case",
|
|
12
|
+
"Decision",
|
|
13
|
+
"ModelEntry",
|
|
14
|
+
"PassMark",
|
|
15
|
+
"Result",
|
|
16
|
+
"RunRecord",
|
|
17
|
+
"TestSet",
|
|
18
|
+
"decide",
|
|
19
|
+
"decision",
|
|
20
|
+
"hash_cases",
|
|
21
|
+
"load_record",
|
|
22
|
+
"load_test_set",
|
|
23
|
+
"parse_pass_mark",
|
|
24
|
+
"parse_record",
|
|
25
|
+
"parse_test_set",
|
|
26
|
+
"summarise",
|
|
27
|
+
"text_report",
|
|
28
|
+
]
|
trialmark/cli.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""The trialmark command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from . import __version__
|
|
9
|
+
from .record import load_record
|
|
10
|
+
from .report import decision, text_report
|
|
11
|
+
from .testset import load_test_set
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _hash(args: argparse.Namespace) -> int:
|
|
15
|
+
ts = load_test_set(args.test_set)
|
|
16
|
+
print(ts.hash)
|
|
17
|
+
return 0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _validate(args: argparse.Namespace) -> int:
|
|
21
|
+
ts = load_test_set(args.test_set)
|
|
22
|
+
tags = ts.tags()
|
|
23
|
+
print(f"{ts.name} v{ts.version}: {len(ts.cases)} cases, tags: {', '.join(tags) if tags else 'none'}")
|
|
24
|
+
print(ts.hash)
|
|
25
|
+
return 0
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _report(args: argparse.Namespace) -> int:
|
|
29
|
+
print(text_report(load_record(args.record), by_tag=args.by_tag))
|
|
30
|
+
return 0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _gate(args: argparse.Namespace) -> int:
|
|
34
|
+
record = load_record(args.record)
|
|
35
|
+
if args.test_set:
|
|
36
|
+
expected = load_test_set(args.test_set).hash
|
|
37
|
+
if expected != record.test_set["hash"]:
|
|
38
|
+
print(f"FAIL: the run used test set {record.test_set['hash']}, not {expected}.")
|
|
39
|
+
return 1
|
|
40
|
+
d = decision(record)
|
|
41
|
+
v = d.verdict_for(args.model)
|
|
42
|
+
if v is None:
|
|
43
|
+
print(f"FAIL: {args.model} has no results in this run.")
|
|
44
|
+
return 1
|
|
45
|
+
if v.passed:
|
|
46
|
+
print(f"PASS: {args.model} meets the pass mark.")
|
|
47
|
+
return 0
|
|
48
|
+
print(f"FAIL: {args.model}: {'; '.join(v.reasons)}")
|
|
49
|
+
return 1
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def main(argv: list[str] | None = None) -> int:
|
|
53
|
+
p = argparse.ArgumentParser(prog="trialmark", description="Model acceptance tests with a pass mark set before the run.")
|
|
54
|
+
p.add_argument("--version", action="version", version=f"trialmark {__version__}")
|
|
55
|
+
sub = p.add_subparsers(dest="command", required=True)
|
|
56
|
+
|
|
57
|
+
s = sub.add_parser("hash", help="print a test set's hash")
|
|
58
|
+
s.add_argument("test_set")
|
|
59
|
+
s.set_defaults(fn=_hash)
|
|
60
|
+
|
|
61
|
+
s = sub.add_parser("validate", help="check a test set and list its tags")
|
|
62
|
+
s.add_argument("test_set")
|
|
63
|
+
s.set_defaults(fn=_validate)
|
|
64
|
+
|
|
65
|
+
s = sub.add_parser("report", help="summarise a run record against its pass mark")
|
|
66
|
+
s.add_argument("record")
|
|
67
|
+
s.add_argument("--by-tag", action="store_true", help="also break results down by tag")
|
|
68
|
+
s.set_defaults(fn=_report)
|
|
69
|
+
|
|
70
|
+
s = sub.add_parser("gate", help="exit 0 if a model meets the run's pass mark, 1 if not")
|
|
71
|
+
s.add_argument("record")
|
|
72
|
+
s.add_argument("--model", required=True)
|
|
73
|
+
s.add_argument("--test-set", help="also check that the run used this exact test set")
|
|
74
|
+
s.set_defaults(fn=_gate)
|
|
75
|
+
|
|
76
|
+
args = p.parse_args(argv)
|
|
77
|
+
try:
|
|
78
|
+
return args.fn(args)
|
|
79
|
+
except (OSError, ValueError) as e:
|
|
80
|
+
print(f"trialmark: {e}", file=sys.stderr)
|
|
81
|
+
return 2
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
sys.exit(main())
|
trialmark/passmark.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Pass marks: the decision rule, written down before the run.
|
|
2
|
+
|
|
3
|
+
A pass mark says which model to choose once the results are in, so the choice
|
|
4
|
+
is not made after seeing them:
|
|
5
|
+
|
|
6
|
+
{
|
|
7
|
+
"metric": "correct",
|
|
8
|
+
"tolerance_points": 3,
|
|
9
|
+
"floors": {"grounded": 0.95},
|
|
10
|
+
"choose": "cheapest"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Read as: among the models whose mean "grounded" is at least 0.95, every model
|
|
14
|
+
within 3 points of the best mean "correct" passes, and the cheapest of those is
|
|
15
|
+
chosen. Points are percentage points of a score between 0 and 1.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import hashlib
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
from .testset import canonical_json
|
|
25
|
+
|
|
26
|
+
CHOOSE_RULES = ("cheapest", "fastest", "best")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class PassMark:
|
|
31
|
+
metric: str
|
|
32
|
+
tolerance_points: float = 0.0
|
|
33
|
+
floors: dict[str, float] = field(default_factory=dict)
|
|
34
|
+
choose: str = "cheapest"
|
|
35
|
+
|
|
36
|
+
def to_dict(self) -> dict[str, Any]:
|
|
37
|
+
return {
|
|
38
|
+
"metric": self.metric,
|
|
39
|
+
# Floats throughout, so 3 and 3.0 hash the same after a round trip.
|
|
40
|
+
"tolerance_points": float(self.tolerance_points),
|
|
41
|
+
"floors": {k: float(v) for k, v in self.floors.items()},
|
|
42
|
+
"choose": self.choose,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def hash(self) -> str:
|
|
47
|
+
return "sha256:" + hashlib.sha256(canonical_json(self.to_dict()).encode("utf-8")).hexdigest()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def parse_pass_mark(data: dict[str, Any]) -> PassMark:
|
|
51
|
+
if "metric" not in data:
|
|
52
|
+
raise ValueError("Pass mark is missing 'metric'.")
|
|
53
|
+
choose = data.get("choose", "cheapest")
|
|
54
|
+
if choose not in CHOOSE_RULES:
|
|
55
|
+
raise ValueError(f"Pass mark 'choose' must be one of {', '.join(CHOOSE_RULES)}.")
|
|
56
|
+
tolerance = float(data.get("tolerance_points", 0))
|
|
57
|
+
if tolerance < 0:
|
|
58
|
+
raise ValueError("Pass mark 'tolerance_points' cannot be negative.")
|
|
59
|
+
floors = {str(k): float(v) for k, v in dict(data.get("floors", {})).items()}
|
|
60
|
+
return PassMark(metric=str(data["metric"]), tolerance_points=tolerance, floors=floors, choose=choose)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True)
|
|
64
|
+
class ModelVerdict:
|
|
65
|
+
model: str
|
|
66
|
+
passed: bool
|
|
67
|
+
reasons: tuple[str, ...]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True)
|
|
71
|
+
class Decision:
|
|
72
|
+
chosen: str | None
|
|
73
|
+
best_score: float | None
|
|
74
|
+
verdicts: tuple[ModelVerdict, ...]
|
|
75
|
+
|
|
76
|
+
def verdict_for(self, model: str) -> ModelVerdict | None:
|
|
77
|
+
return next((v for v in self.verdicts if v.model == model), None)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def decide(pass_mark: PassMark, summaries: list[Any]) -> Decision:
|
|
81
|
+
"""Apply a pass mark to model summaries (see report.summarise)."""
|
|
82
|
+
scored = [s for s in summaries if pass_mark.metric in s.metrics]
|
|
83
|
+
if not scored:
|
|
84
|
+
return Decision(chosen=None, best_score=None, verdicts=tuple(
|
|
85
|
+
ModelVerdict(s.model, False, (f"no '{pass_mark.metric}' results",)) for s in summaries
|
|
86
|
+
))
|
|
87
|
+
best = max(s.metrics[pass_mark.metric].mean for s in scored)
|
|
88
|
+
threshold = best - pass_mark.tolerance_points / 100
|
|
89
|
+
verdicts: list[ModelVerdict] = []
|
|
90
|
+
passing = []
|
|
91
|
+
for s in summaries:
|
|
92
|
+
reasons: list[str] = []
|
|
93
|
+
m = s.metrics.get(pass_mark.metric)
|
|
94
|
+
if m is None:
|
|
95
|
+
reasons.append(f"no '{pass_mark.metric}' results")
|
|
96
|
+
elif m.mean < threshold - 1e-9:
|
|
97
|
+
reasons.append(
|
|
98
|
+
f"{pass_mark.metric} {m.mean:.1%} is more than {pass_mark.tolerance_points:g} points below the best {best:.1%}"
|
|
99
|
+
)
|
|
100
|
+
for name, floor in pass_mark.floors.items():
|
|
101
|
+
fm = s.metrics.get(name)
|
|
102
|
+
if fm is None:
|
|
103
|
+
reasons.append(f"no '{name}' results")
|
|
104
|
+
elif fm.mean < floor - 1e-9:
|
|
105
|
+
reasons.append(f"{name} {fm.mean:.1%} is below the floor of {floor:.1%}")
|
|
106
|
+
verdicts.append(ModelVerdict(s.model, not reasons, tuple(reasons)))
|
|
107
|
+
if not reasons:
|
|
108
|
+
passing.append(s)
|
|
109
|
+
chosen = None
|
|
110
|
+
if passing:
|
|
111
|
+
if pass_mark.choose == "cheapest":
|
|
112
|
+
chosen = min(passing, key=lambda s: (s.cost_per_100_usd, s.model)).model
|
|
113
|
+
elif pass_mark.choose == "fastest":
|
|
114
|
+
chosen = min(passing, key=lambda s: (s.latency_p50_ms, s.model)).model
|
|
115
|
+
else:
|
|
116
|
+
chosen = max(passing, key=lambda s: (s.metrics[pass_mark.metric].mean, -s.cost_per_100_usd)).model
|
|
117
|
+
return Decision(chosen=chosen, best_score=best, verdicts=tuple(verdicts))
|
trialmark/record.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Run records: everything needed to repeat a run and check its result.
|
|
2
|
+
|
|
3
|
+
A record is started before any model runs, with the test set and the pass mark
|
|
4
|
+
fixed, and results are added as they arrive. The pass mark's hash and the time
|
|
5
|
+
it was set are kept, so a reader can see it was not changed after the results.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import uuid
|
|
12
|
+
from dataclasses import asdict, dataclass, field
|
|
13
|
+
from datetime import datetime, timezone
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from . import __version__
|
|
18
|
+
from .passmark import PassMark, parse_pass_mark
|
|
19
|
+
from .testset import TestSet
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class ModelEntry:
|
|
24
|
+
id: str
|
|
25
|
+
provider: str = ""
|
|
26
|
+
settings: dict[str, Any] = field(default_factory=dict)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class Result:
|
|
31
|
+
model: str
|
|
32
|
+
repeat: int
|
|
33
|
+
case_id: str
|
|
34
|
+
metrics: dict[str, float]
|
|
35
|
+
tags: list[str] = field(default_factory=list)
|
|
36
|
+
output: Any = None
|
|
37
|
+
cost_usd: float = 0.0
|
|
38
|
+
latency_ms: int = 0
|
|
39
|
+
input_tokens: int = 0
|
|
40
|
+
output_tokens: int = 0
|
|
41
|
+
error: str | None = None
|
|
42
|
+
note: str = ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class RunRecord:
|
|
47
|
+
test_set: dict[str, str]
|
|
48
|
+
pass_mark: dict[str, Any]
|
|
49
|
+
pass_mark_hash: str
|
|
50
|
+
pass_mark_set_at: str
|
|
51
|
+
models: list[ModelEntry]
|
|
52
|
+
repeats: int
|
|
53
|
+
run_id: str = field(default_factory=lambda: str(uuid.uuid4()))
|
|
54
|
+
trialmark_version: str = __version__
|
|
55
|
+
judge: dict[str, Any] | None = None
|
|
56
|
+
environment: dict[str, Any] = field(default_factory=dict)
|
|
57
|
+
results: list[Result] = field(default_factory=list)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def start(
|
|
61
|
+
cls,
|
|
62
|
+
test_set: TestSet,
|
|
63
|
+
pass_mark: PassMark,
|
|
64
|
+
models: list[ModelEntry],
|
|
65
|
+
repeats: int = 3,
|
|
66
|
+
judge: dict[str, Any] | None = None,
|
|
67
|
+
environment: dict[str, Any] | None = None,
|
|
68
|
+
) -> "RunRecord":
|
|
69
|
+
if repeats < 1:
|
|
70
|
+
raise ValueError("A run needs at least one repeat.")
|
|
71
|
+
if not models:
|
|
72
|
+
raise ValueError("A run needs at least one model.")
|
|
73
|
+
return cls(
|
|
74
|
+
test_set={"name": test_set.name, "version": test_set.version, "hash": test_set.hash},
|
|
75
|
+
pass_mark=pass_mark.to_dict(),
|
|
76
|
+
pass_mark_hash=pass_mark.hash,
|
|
77
|
+
pass_mark_set_at=datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
78
|
+
models=models,
|
|
79
|
+
repeats=repeats,
|
|
80
|
+
judge=judge,
|
|
81
|
+
environment=environment or {},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def add(self, result: Result) -> None:
|
|
85
|
+
if result.model not in {m.id for m in self.models}:
|
|
86
|
+
raise ValueError(f"Model '{result.model}' is not in this run.")
|
|
87
|
+
if not 0 <= result.repeat < self.repeats:
|
|
88
|
+
raise ValueError(f"Repeat {result.repeat} is outside 0..{self.repeats - 1}.")
|
|
89
|
+
self.results.append(result)
|
|
90
|
+
|
|
91
|
+
def parsed_pass_mark(self) -> PassMark:
|
|
92
|
+
pm = parse_pass_mark(self.pass_mark)
|
|
93
|
+
if pm.hash != self.pass_mark_hash:
|
|
94
|
+
raise ValueError("The pass mark does not match the hash recorded when it was set.")
|
|
95
|
+
return pm
|
|
96
|
+
|
|
97
|
+
def to_dict(self) -> dict[str, Any]:
|
|
98
|
+
return asdict(self)
|
|
99
|
+
|
|
100
|
+
def save(self, path: str | Path) -> None:
|
|
101
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
102
|
+
json.dump(self.to_dict(), f, indent=2, ensure_ascii=False)
|
|
103
|
+
f.write("\n")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def parse_record(data: dict[str, Any]) -> RunRecord:
|
|
107
|
+
try:
|
|
108
|
+
models = [ModelEntry(**m) for m in data["models"]]
|
|
109
|
+
results = [Result(**r) for r in data.get("results", [])]
|
|
110
|
+
return RunRecord(
|
|
111
|
+
test_set=dict(data["test_set"]),
|
|
112
|
+
pass_mark=dict(data["pass_mark"]),
|
|
113
|
+
pass_mark_hash=str(data["pass_mark_hash"]),
|
|
114
|
+
pass_mark_set_at=str(data["pass_mark_set_at"]),
|
|
115
|
+
models=models,
|
|
116
|
+
repeats=int(data["repeats"]),
|
|
117
|
+
run_id=str(data.get("run_id", "")),
|
|
118
|
+
trialmark_version=str(data.get("trialmark_version", "")),
|
|
119
|
+
judge=data.get("judge"),
|
|
120
|
+
environment=dict(data.get("environment", {})),
|
|
121
|
+
results=results,
|
|
122
|
+
)
|
|
123
|
+
except KeyError as e:
|
|
124
|
+
raise ValueError(f"Run record is missing {e}.") from None
|
|
125
|
+
except TypeError as e:
|
|
126
|
+
raise ValueError(f"Run record has an unexpected field: {e}.") from None
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def load_record(path: str | Path) -> RunRecord:
|
|
130
|
+
with open(path, encoding="utf-8") as f:
|
|
131
|
+
return parse_record(json.load(f))
|
trialmark/report.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Summaries and reports: each model's scores, cost and speed, with the range
|
|
2
|
+
across repeats, overall and for each tag."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import statistics
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from .passmark import Decision, decide
|
|
10
|
+
from .record import Result, RunRecord
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class MetricSummary:
|
|
15
|
+
mean: float
|
|
16
|
+
low: float
|
|
17
|
+
high: float
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class ModelSummary:
|
|
22
|
+
model: str
|
|
23
|
+
cases: int
|
|
24
|
+
repeats: int
|
|
25
|
+
errors: int
|
|
26
|
+
metrics: dict[str, MetricSummary]
|
|
27
|
+
cost_per_100_usd: float
|
|
28
|
+
latency_p50_ms: int
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _summarise(model: str, results: list[Result]) -> ModelSummary:
|
|
32
|
+
by_repeat: dict[int, list[Result]] = {}
|
|
33
|
+
for r in results:
|
|
34
|
+
by_repeat.setdefault(r.repeat, []).append(r)
|
|
35
|
+
names = sorted({k for r in results for k in r.metrics})
|
|
36
|
+
metrics: dict[str, MetricSummary] = {}
|
|
37
|
+
for name in names:
|
|
38
|
+
# Mean within each repeat, then the mean and range across repeats.
|
|
39
|
+
per_repeat = []
|
|
40
|
+
for rs in by_repeat.values():
|
|
41
|
+
vals = [r.metrics[name] for r in rs if name in r.metrics]
|
|
42
|
+
if vals:
|
|
43
|
+
per_repeat.append(sum(vals) / len(vals))
|
|
44
|
+
if per_repeat:
|
|
45
|
+
metrics[name] = MetricSummary(
|
|
46
|
+
mean=sum(per_repeat) / len(per_repeat), low=min(per_repeat), high=max(per_repeat)
|
|
47
|
+
)
|
|
48
|
+
costs = [sum(r.cost_usd for r in rs) / len(rs) * 100 for rs in by_repeat.values() if rs]
|
|
49
|
+
latencies = [r.latency_ms for r in results if r.latency_ms > 0 and r.error is None]
|
|
50
|
+
return ModelSummary(
|
|
51
|
+
model=model,
|
|
52
|
+
cases=len({r.case_id for r in results}),
|
|
53
|
+
repeats=len(by_repeat),
|
|
54
|
+
errors=sum(1 for r in results if r.error),
|
|
55
|
+
metrics=metrics,
|
|
56
|
+
cost_per_100_usd=sum(costs) / len(costs) if costs else 0.0,
|
|
57
|
+
latency_p50_ms=int(statistics.median(latencies)) if latencies else 0,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def summarise(record: RunRecord, tag: str | None = None) -> list[ModelSummary]:
|
|
62
|
+
out = []
|
|
63
|
+
for m in record.models:
|
|
64
|
+
rs = [r for r in record.results if r.model == m.id and (tag is None or tag in r.tags)]
|
|
65
|
+
if rs:
|
|
66
|
+
out.append(_summarise(m.id, rs))
|
|
67
|
+
return out
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def decision(record: RunRecord) -> Decision:
|
|
71
|
+
return decide(record.parsed_pass_mark(), summarise(record))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _pct(m: MetricSummary | None) -> str:
|
|
75
|
+
if m is None:
|
|
76
|
+
return "-"
|
|
77
|
+
if abs(m.high - m.low) < 1e-9:
|
|
78
|
+
return f"{m.mean:.0%}"
|
|
79
|
+
return f"{m.mean:.0%} ({m.low:.0%}-{m.high:.0%})"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _table(summaries: list[ModelSummary], metrics: list[str]) -> list[str]:
|
|
83
|
+
head = ["Model", *metrics, "Cost/100", "Median time"]
|
|
84
|
+
rows = [
|
|
85
|
+
[
|
|
86
|
+
s.model,
|
|
87
|
+
*(_pct(s.metrics.get(n)) for n in metrics),
|
|
88
|
+
f"${s.cost_per_100_usd:.2f}",
|
|
89
|
+
f"{s.latency_p50_ms / 1000:.1f}s",
|
|
90
|
+
]
|
|
91
|
+
for s in summaries
|
|
92
|
+
]
|
|
93
|
+
widths = [max(len(str(x)) for x in col) for col in zip(head, *rows)]
|
|
94
|
+
fmt = lambda r: " ".join(str(x).ljust(w) for x, w in zip(r, widths)).rstrip() # noqa: E731
|
|
95
|
+
return [fmt(head), fmt(["-" * w for w in widths]), *map(fmt, rows)]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def text_report(record: RunRecord, by_tag: bool = False) -> str:
|
|
99
|
+
summaries = summarise(record)
|
|
100
|
+
metrics = sorted({n for s in summaries for n in s.metrics})
|
|
101
|
+
pm = record.parsed_pass_mark()
|
|
102
|
+
d = decide(pm, summaries)
|
|
103
|
+
lines = [
|
|
104
|
+
f"Test set {record.test_set['name']} v{record.test_set['version']} ({record.test_set['hash'][:19]}...)",
|
|
105
|
+
f"Run {record.run_id}, {record.repeats} repeats, Trialmark {record.trialmark_version}",
|
|
106
|
+
]
|
|
107
|
+
if record.judge:
|
|
108
|
+
lines.append(f"Judge {record.judge.get('model', '?')}")
|
|
109
|
+
lines += ["", *_table(summaries, metrics), ""]
|
|
110
|
+
lines.append(
|
|
111
|
+
"Ranges in brackets are the lowest and highest repeat. Treat differences inside them as no difference."
|
|
112
|
+
)
|
|
113
|
+
lines += ["", f"Pass mark set {record.pass_mark_set_at}: {pm.metric} within {pm.tolerance_points:g} points of the best"
|
|
114
|
+
+ "".join(f", {k} at least {v:.0%}" for k, v in pm.floors.items())
|
|
115
|
+
+ f"; choose the {pm.choose}."]
|
|
116
|
+
for v in d.verdicts:
|
|
117
|
+
lines.append(f" {'PASS' if v.passed else 'FAIL'} {v.model}" + (f": {'; '.join(v.reasons)}" if v.reasons else ""))
|
|
118
|
+
lines.append(f"Chosen {d.chosen or 'no model met the pass mark'}")
|
|
119
|
+
if by_tag:
|
|
120
|
+
tags = sorted({t for r in record.results for t in r.tags})
|
|
121
|
+
for t in tags:
|
|
122
|
+
lines += ["", f"Tag: {t}", *_table(summarise(record, tag=t), metrics)]
|
|
123
|
+
return "\n".join(lines)
|
trialmark/testset.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Test sets: the cases a model is tested on, each with a reference output and tags.
|
|
2
|
+
|
|
3
|
+
A test set is a JSON file:
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
"name": "contracts",
|
|
7
|
+
"version": "2026-11-05",
|
|
8
|
+
"cases": [
|
|
9
|
+
{"id": "q1", "input": "What is the notice period?",
|
|
10
|
+
"reference": "Sixty days' written notice.", "tags": ["factual"]}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
The hash covers the cases only, so a rerun can prove it used exactly the same
|
|
15
|
+
cases even if the set was renamed.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import hashlib
|
|
21
|
+
import json
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class Case:
|
|
29
|
+
id: str
|
|
30
|
+
input: Any
|
|
31
|
+
reference: Any
|
|
32
|
+
tags: tuple[str, ...] = ()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class TestSet:
|
|
37
|
+
name: str
|
|
38
|
+
version: str
|
|
39
|
+
cases: tuple[Case, ...]
|
|
40
|
+
description: str = ""
|
|
41
|
+
extra: dict[str, Any] = field(default_factory=dict)
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def hash(self) -> str:
|
|
45
|
+
return hash_cases(self.cases)
|
|
46
|
+
|
|
47
|
+
def tags(self) -> list[str]:
|
|
48
|
+
return sorted({t for c in self.cases for t in c.tags})
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def canonical_json(value: Any) -> str:
|
|
52
|
+
return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def hash_cases(cases: tuple[Case, ...] | list[Case]) -> str:
|
|
56
|
+
rows = sorted(
|
|
57
|
+
({"id": c.id, "input": c.input, "reference": c.reference, "tags": sorted(c.tags)} for c in cases),
|
|
58
|
+
key=lambda r: r["id"],
|
|
59
|
+
)
|
|
60
|
+
return "sha256:" + hashlib.sha256(canonical_json(rows).encode("utf-8")).hexdigest()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def parse_test_set(data: dict[str, Any]) -> TestSet:
|
|
64
|
+
for key in ("name", "version", "cases"):
|
|
65
|
+
if key not in data:
|
|
66
|
+
raise ValueError(f"Test set is missing '{key}'.")
|
|
67
|
+
if not isinstance(data["cases"], list) or not data["cases"]:
|
|
68
|
+
raise ValueError("Test set 'cases' must be a non-empty list.")
|
|
69
|
+
cases: list[Case] = []
|
|
70
|
+
seen: set[str] = set()
|
|
71
|
+
for i, raw in enumerate(data["cases"]):
|
|
72
|
+
if not isinstance(raw, dict):
|
|
73
|
+
raise ValueError(f"Case {i} must be an object.")
|
|
74
|
+
for key in ("id", "input", "reference"):
|
|
75
|
+
if key not in raw:
|
|
76
|
+
raise ValueError(f"Case {i} is missing '{key}'.")
|
|
77
|
+
cid = str(raw["id"])
|
|
78
|
+
if cid in seen:
|
|
79
|
+
raise ValueError(f"Case id '{cid}' appears more than once.")
|
|
80
|
+
seen.add(cid)
|
|
81
|
+
tags = raw.get("tags", [])
|
|
82
|
+
if not isinstance(tags, list) or not all(isinstance(t, str) for t in tags):
|
|
83
|
+
raise ValueError(f"Case '{cid}' tags must be a list of strings.")
|
|
84
|
+
cases.append(Case(id=cid, input=raw["input"], reference=raw["reference"], tags=tuple(tags)))
|
|
85
|
+
extra = {k: v for k, v in data.items() if k not in ("name", "version", "cases", "description")}
|
|
86
|
+
return TestSet(
|
|
87
|
+
name=str(data["name"]),
|
|
88
|
+
version=str(data["version"]),
|
|
89
|
+
cases=tuple(cases),
|
|
90
|
+
description=str(data.get("description", "")),
|
|
91
|
+
extra=extra,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def load_test_set(path: str | Path) -> TestSet:
|
|
96
|
+
with open(path, encoding="utf-8") as f:
|
|
97
|
+
return parse_test_set(json.load(f))
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: trialmark
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Model acceptance tests for language models: your own test set, a pass mark set before the run, and a record anyone can rerun.
|
|
5
|
+
Project-URL: Homepage, https://github.com/peshwar9/trialmark
|
|
6
|
+
Project-URL: Issues, https://github.com/peshwar9/trialmark/issues
|
|
7
|
+
Author: PE (peshwar9)
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: acceptance testing,benchmark,evaluation,llm,model selection
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Classifier: Topic :: Software Development :: Testing
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Trialmark
|
|
22
|
+
|
|
23
|
+
**Model acceptance tests for language models.** Test models on your own work, decide in advance
|
|
24
|
+
what result is good enough, and keep a record that anyone can rerun and check.
|
|
25
|
+
|
|
26
|
+
Choosing a language model is a trade between accuracy, cost and speed. Trialmark makes that
|
|
27
|
+
choice systematic:
|
|
28
|
+
|
|
29
|
+
1. **Your own test set.** Cases from your own work, each with a reference answer written by a
|
|
30
|
+
person and tagged by kind, such as "factual" or "multi-part". The set is hashed, so a later
|
|
31
|
+
run can prove it used exactly the same cases.
|
|
32
|
+
2. **A pass mark set before the run.** For example: "choose the cheapest model within 3 points
|
|
33
|
+
of the best on correctness, as long as at least 95% of its answers are grounded". The rule
|
|
34
|
+
is stored with its hash and the time it was set, so it cannot be quietly changed after the
|
|
35
|
+
results are in.
|
|
36
|
+
3. **Repeats, with the range shown.** Models do not give the same answer every time. Each model
|
|
37
|
+
runs several times, and the report shows the lowest and highest result so that a difference
|
|
38
|
+
inside the range is read as no difference.
|
|
39
|
+
4. **A report by kind of case.** A small model may be as good as a large one on single facts
|
|
40
|
+
and worse on multi-part questions. The breakdown by tag shows where.
|
|
41
|
+
5. **A run record and a release gate.** Every run writes one JSON file with the test set's hash,
|
|
42
|
+
the models and their settings, the judge, the pass mark and every result. `trialmark gate`
|
|
43
|
+
exits with 0 or 1, so a pipeline can refuse a model change that fails the pass mark.
|
|
44
|
+
|
|
45
|
+
Trialmark runs on your own machines. Your test sets, reference answers and records stay with you.
|
|
46
|
+
|
|
47
|
+
## Where it comes from
|
|
48
|
+
|
|
49
|
+
Trialmark was spun out of the model benchmark in [Forge](https://www.forgeprivate.com), a
|
|
50
|
+
governed layer through which organisations delegate work to AI. That benchmark compares models
|
|
51
|
+
on a fixed set of business-document questions, through Forge's own answer path, with three
|
|
52
|
+
repeats and accuracy, cost and speed side by side. Trialmark makes the same kind of test
|
|
53
|
+
available to any developer or team, with or without Forge.
|
|
54
|
+
|
|
55
|
+
## Status
|
|
56
|
+
|
|
57
|
+
Trialmark is at an early stage. Version 0.1 provides the formats and the decision:
|
|
58
|
+
|
|
59
|
+
| Built in 0.1 | Planned |
|
|
60
|
+
|---|---|
|
|
61
|
+
| The test set format, with hashing and tags | Runners that call models directly (Anthropic, OpenAI and others) |
|
|
62
|
+
| The pass mark and the decision rule | A reference-answer judge, which grades an answer as correct, partly correct or incorrect and checks that it is grounded |
|
|
63
|
+
| The run record, with the pass mark's hash | A field-by-field scorer for extraction and classification |
|
|
64
|
+
| The report, with ranges and the breakdown by tag | A runner that tests a model inside Forge, with Forge's retrieval and rules applied |
|
|
65
|
+
| `trialmark gate` for pipelines | Logging runs to MLflow |
|
|
66
|
+
|
|
67
|
+
In 0.1 you produce the results yourself, with your own code, and Trialmark records, reports and
|
|
68
|
+
decides on them.
|
|
69
|
+
|
|
70
|
+
## Install
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install trialmark
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Python 3.10 or later. The core has no dependencies.
|
|
77
|
+
|
|
78
|
+
## Try it
|
|
79
|
+
|
|
80
|
+
The `examples` folder holds a five-question test set and an illustrative run of three made-up
|
|
81
|
+
models. The scores in it are invented to show the format; they are not measurements of any real
|
|
82
|
+
model.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
trialmark validate examples/testset.json
|
|
86
|
+
trialmark report examples/run-record.json --by-tag
|
|
87
|
+
trialmark gate examples/run-record.json --model medium-model --test-set examples/testset.json
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Use it from Python
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from trialmark import ModelEntry, PassMark, Result, RunRecord, load_test_set, text_report
|
|
94
|
+
|
|
95
|
+
test_set = load_test_set("my-testset.json")
|
|
96
|
+
|
|
97
|
+
# Fix the decision before any model runs.
|
|
98
|
+
pass_mark = PassMark(metric="correct", tolerance_points=3, floors={"grounded": 0.95}, choose="cheapest")
|
|
99
|
+
record = RunRecord.start(
|
|
100
|
+
test_set,
|
|
101
|
+
pass_mark,
|
|
102
|
+
[ModelEntry(id="model-a", provider="provider-x"), ModelEntry(id="model-b", provider="provider-y")],
|
|
103
|
+
repeats=3,
|
|
104
|
+
judge={"model": "judge-model", "prompt_version": "1"},
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
for repeat in range(3):
|
|
108
|
+
for model in ("model-a", "model-b"):
|
|
109
|
+
for case in test_set.cases:
|
|
110
|
+
answer, cost, ms = call_your_model(model, case.input) # your code
|
|
111
|
+
score = grade(answer, case.reference) # your code: 0, 0.5 or 1
|
|
112
|
+
record.add(Result(
|
|
113
|
+
model=model, repeat=repeat, case_id=case.id, tags=list(case.tags),
|
|
114
|
+
metrics={"correct": score, "grounded": 1.0},
|
|
115
|
+
output=answer, cost_usd=cost, latency_ms=ms,
|
|
116
|
+
))
|
|
117
|
+
|
|
118
|
+
record.save("run-record.json")
|
|
119
|
+
print(text_report(record, by_tag=True))
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Formats
|
|
123
|
+
|
|
124
|
+
**Test set**
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"name": "contract-questions",
|
|
129
|
+
"version": "2026-11-05",
|
|
130
|
+
"cases": [
|
|
131
|
+
{ "id": "q1", "input": "What is the notice period?", "reference": "Sixty days' written notice.", "tags": ["factual"] }
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The hash covers the cases (their ids, inputs, references and tags), not the name or version.
|
|
137
|
+
|
|
138
|
+
**Pass mark**
|
|
139
|
+
|
|
140
|
+
| Field | Meaning |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `metric` | The score the decision rests on, such as `correct` |
|
|
143
|
+
| `tolerance_points` | How many percentage points below the best model still passes |
|
|
144
|
+
| `floors` | Minimum mean scores on other metrics, such as `{"grounded": 0.95}` |
|
|
145
|
+
| `choose` | Which passing model to choose: `cheapest`, `fastest` or `best` |
|
|
146
|
+
|
|
147
|
+
**Metrics** are whatever your scorer produces, each between 0 and 1. A model's score on a
|
|
148
|
+
metric is the mean within each repeat; the report shows the mean of those and their range.
|
|
149
|
+
|
|
150
|
+
## Licence
|
|
151
|
+
|
|
152
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
trialmark/__init__.py,sha256=XwXHsiw1Ib4gAxswMDKo0jHbyVVWRJY-CkTPILBislA,743
|
|
2
|
+
trialmark/cli.py,sha256=779mvyqJYrkKYT1hENGWTtIHNthgCo06ET4IZkdIlT8,2700
|
|
3
|
+
trialmark/passmark.py,sha256=UQ3EqNbQpHbZ0ocfptY4TWCsGzC3NghPH7H792CA9_0,4344
|
|
4
|
+
trialmark/record.py,sha256=ZWXcjhfjEHca8luSiyohl0XyKAmCdetY-wpf-4pmfck,4351
|
|
5
|
+
trialmark/report.py,sha256=3ipooxxdIrWGpy8kfC2RIwBvsRWlOwWGMRgWjFTqkbk,4548
|
|
6
|
+
trialmark/testset.py,sha256=-LQMl-tSblQiJ7X4dr2oFAGp2NLZf6DtHy3DIwy5GNI,3083
|
|
7
|
+
trialmark-0.1.0.dist-info/METADATA,sha256=wG1attMcWnl02HGSEQ2fqNkMeCGbPXKA8OzgERXf7cc,6332
|
|
8
|
+
trialmark-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
9
|
+
trialmark-0.1.0.dist-info/entry_points.txt,sha256=V5xoW75gguNdKsK49ManBGrXWh8F2-JdPDCDriwH3jU,49
|
|
10
|
+
trialmark-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
11
|
+
trialmark-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|