Learn rule-based models from examples, corrections, and LLM interactions.
pip install -e .export OPENAI_API_KEY=your_key_here
rulecheffrom openai import OpenAI
from rulechef import RuleChef, Task
# Setup
client = OpenAI(api_key="...")
task = Task(
name="Q&A",
description="Extract answer spans from text",
input_schema={"question": "str", "context": "str"},
output_schema={"spans": "List[Span]"}
)
chef = RuleChef(task, client)
# Add examples
chef.add_example(
{"question": "When?", "context": "Built in 1991"},
{"spans": [{"text": "1991", "start": 9, "end": 13}]}
)
# Learn rules
chef.learn_rules()
# Use
spans, meta = chef.extract("When?", "Released in 1995")
print([s.text for s in spans]) # ["1995"]