From cfd457fe663ec363514f90e0d34b6fc3fc0bcd30 Mon Sep 17 00:00:00 2001 From: Tyrin Todd Date: Thu, 2 Apr 2026 18:18:59 -0700 Subject: [PATCH] (no commit message) --- optimize.py | 49 ------------------------------------------------- program.py | 6 +++++- 2 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 optimize.py diff --git a/optimize.py b/optimize.py deleted file mode 100644 index c1d066d..0000000 --- a/optimize.py +++ /dev/null @@ -1,49 +0,0 @@ -import json - -import dspy - -from program import DocExtract - - -def load_dataset(path): - with open(path) as f: - return [ - dspy.Example(**json.loads(line)).with_inputs("context") - for line in f - if line.strip() - ] - - -def classification_metric( - gold: dspy.Example, - pred: dspy.Prediction, - trace=None, - pred_name: str | None = None, - pred_trace=None, -) -> dspy.Prediction: - del trace, pred_name, pred_trace - - if getattr(pred, "label", None) == gold.label: - return dspy.Prediction(score=1.0, feedback="Correct.") - - return dspy.Prediction( - score=0.0, - feedback=f"Expected `{gold.label}` because {gold.reason}", - ) - - -if __name__ == "__main__": - program = DocExtract.from_precompiled("tyrin/doc-extract") - dspy.configure(lm=dspy.LM("openai/gpt-4.1-mini", temperature=0.0)) - - optimized_program = dspy.GEPA( - metric=classification_metric, - reflection_lm=dspy.LM("openai/gpt-4.1-mini", temperature=1.0, max_tokens=8000), - auto="light", - ).compile( - program, - trainset=load_dataset("data/train.jsonl"), - valset=load_dataset("data/val.jsonl"), - ) - - optimized_program.push_to_hub("tyrin/doc-extract") diff --git a/program.py b/program.py index 31caa37..ff94dbb 100644 --- a/program.py +++ b/program.py @@ -26,4 +26,8 @@ class DocExtract(PrecompiledProgram): if __name__ == "__main__": - DocExtract().push_to_hub("tyrin/doc-extract") + program = DocExtract() + dspy.configure(lm=dspy.LM(model="gpt-5-mini")) + result = program(context="This is a legal document") + print(result.label) + program.push_to_hub("tyrin/doc-extract")