48 lines
2.3 KiB
Python
48 lines
2.3 KiB
Python
"""Issue triage: heuristic labels -> filter -> structured LLM labels -> route -> export.
|
|
|
|
pw check examples/issue_triage/graph.py
|
|
pw run examples/issue_triage/graph.py # fake model (pipewright.yaml)
|
|
pw run examples/issue_triage/graph.py --project examples/issue_triage/pipewright.live.yaml
|
|
"""
|
|
|
|
from pipewright import Graph
|
|
from pipewright.nodes.builtin import FilterExpr, LabelExpr, LLMLabel, RouteExpr
|
|
|
|
g = Graph("issue-triage", description="Label GitHub-style issues and route the urgent bugs")
|
|
|
|
issues = g.add("issues", "source.file", path="data/issues.jsonl", kind="issue")
|
|
|
|
heuristics = g.add("heuristics", LabelExpr.Params(labels={
|
|
"has_traceback": r"re(r'traceback|sigsegv|segfault|exception|error:', payload.body)",
|
|
"has_code": "'```' in payload.body",
|
|
"words": "words(payload.body)",
|
|
"engagement": "payload.comments + payload.reactions",
|
|
}), input=issues)
|
|
|
|
substantive = g.add("substantive", FilterExpr.Params(expr="labels.words >= 8"), input=heuristics)
|
|
|
|
classify = g.add("classify", LLMLabel.Params(
|
|
model="labeler",
|
|
system="You triage issues for a software project. Be concise and literal.",
|
|
prompt=("Classify this issue.\n\nTitle: {{ payload.title }}\n\n{{ payload.body }}\n\n"
|
|
"Severity: 0 = cosmetic, 1 = minor, 2 = major (broken feature), 3 = critical (crash, data loss, "
|
|
"security, many users blocked)."),
|
|
labels={
|
|
"category": {"type": "string", "enum": ["bug", "feature", "question", "docs"]},
|
|
"severity": {"type": "integer", "minimum": 0, "maximum": 3},
|
|
"summary": {"type": "string", "maxLength": 160},
|
|
},
|
|
), input=substantive)
|
|
|
|
route = g.add("route", RouteExpr.Params(routes={
|
|
"urgent": "labels.category == 'bug' and (labels.severity >= 2 or labels.has_traceback)",
|
|
"features": "labels.category == 'feature'",
|
|
}, default="other"), input=classify)
|
|
|
|
fields = ["key", "payload.title", "labels.category", "labels.severity", "labels.summary", "labels.engagement"]
|
|
g.add("export_urgent", "sink.jsonl", path="out/urgent.jsonl", fields=fields, input=route.port("urgent"))
|
|
g.add("export_features", "sink.jsonl", path="out/features.jsonl", fields=fields, input=route.port("features"))
|
|
g.add("export_other", "sink.jsonl", path="out/other.jsonl", fields=fields, input=route.port("other"))
|
|
|
|
graph = g
|