paintedwolf-ai's picture
Release open1-b5-e4-bialy
24918f7 verified
Raw History Blame Contribute Delete
1.36 kB
"""Training rows: `lycaon-debug decide export` output, pw-decide-row/1.
row.schema.json beside this file describes the shape. A row is one turn
decision: the state the engine read, the candidates the turn offered, what
the engine answered, and what the session then did. Every consumer reads
option sets from the row's `offered` candidates and option texts from the
corpus, so a label is always read against the options the host had.
"""
import json
SCHEMA = "pw-decide-row/1"
def load(path):
"""Every row of a JSON-lines file, refusing any row of another shape."""
rows = []
with open(path, encoding="utf-8") as fh:
for n, line in enumerate(fh, 1):
if not line.strip():
continue
row = json.loads(line)
if row.get("schema") != SCHEMA:
raise ValueError("%s:%d: schema %r, want %r" % (path, n, row.get("schema"), SCHEMA))
rows.append(row)
return rows
def engine_answered(row):
"""The engine chose what this turn carried, so a tool it preloaded and the session
then called is not an independent label."""
return row["engine"]["state"] == "answered"
def truth_tools(row):
"""The loadable tools the turn needed: the ones it called or asked for by name."""
return set(row["labels"]["tools"]) | set(row["labels"]["requested_names"])