Files
pipewright/examples/hardening/graph_build.py
T

27 lines
1.5 KiB
Python

"""Graph 1 of the two-graph example: synthesize coding tasks, validate them in
sandboxes, probe them with an agent and bucket them by pass rate.
pw run examples/hardening/graph_build.py
pw run examples/hardening/graph_harden.py # consumes build's too_easy outputs
"""
from pipewright import Graph
from common import STUB, validate_and_probe
g = Graph("build", description="Synthesize tasks, validate, probe, bucket by pass rate")
synth = g.add("synth", "llm.synthesize", model="generator", kind="task", calls=1, batch=6, key_field="name",
prompt=("Invent {{ batch }} small, self-contained Python exercises (variation {{ i }}). For each "
"give `name`, `statement`, `signature` (one `def` line), `solution` (solution.py) and "
"`tests` (a script doing `from solution import *`, plain asserts, printing ok)."),
item_schema={"type": "object", "required": ["name", "statement", "signature", "solution", "tests"],
"properties": {k: {"type": "string"} for k in
("name", "statement", "signature", "solution", "tests")}})
prepare = g.add("prepare", "map.expr", input=synth, fields=STUB)
valid, bucket = validate_and_probe(g, prepare)
for name in ("too_easy", "learnable", "too_hard"):
g.add(f"export_{name}", "sink.jsonl", path=f"out/build_{name}.jsonl", input=bucket.port(name),
fields=["key", "labels.pass_rate"])
graph = g