mirror of
https://github.com/magnus919/agent-skills.git
synced 2026-09-11 19:47:12 +03:00
Greenfield SkillOpt: 3 epochs for a Stanford DSPy compiler skill. DSPy is a fundamentally different paradigm from chain/RAG frameworks. Epoch 1 — Prominence: - Hard-gate blockquote: 'DSPy is NOT a chain framework' - Core Paradigm section with runnable code example early Epoch 2 — Decision Guidance: - Framework Routing Guide (DSPy vs LlamaIndex vs LangChain vs LangGraph) - Where to Start table mapping entry points - Troubleshooting table with reference links Epoch 3 — Pattern Expansion: - Optimizer selection cheat sheet from official docs - Caching, compilation cost management, save/load - FAQ covering paradigm confusion, errors, deployment 12 files: SKILL.md, 7 references, 3 templates, 1 script. v1.0.0 -> v1.0.3 across 3 epochs. All API surfaces validated against dspy.ai official docs — optimizer selection guide, caching, core modules, FAQ. Signed-off-by: Jasper <jasper@montcastle.bitches>
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Classification with DSPy using BootstrapFewShot."""
|
|
|
|
import dspy
|
|
|
|
lm = dspy.LM("openai/gpt-4o-mini")
|
|
dspy.configure(lm=lm)
|
|
|
|
class IntentClassify(dspy.Signature):
|
|
"""Classify customer support intent."""
|
|
text: str = dspy.InputField()
|
|
intent: str = dspy.OutputField(desc="billing, technical, account, or sales")
|
|
|
|
class Classifier(dspy.Module):
|
|
def __init__(self):
|
|
self.classify = dspy.ChainOfThought(IntentClassify)
|
|
def forward(self, text):
|
|
return self.classify(text=text)
|
|
|
|
def accuracy(example, pred, trace=None):
|
|
return example.intent == pred.intent
|
|
|
|
# Example training data
|
|
trainset = [
|
|
dspy.Example(text="My card was charged twice", intent="billing").with_inputs("text"),
|
|
dspy.Example(text="The login page won't load", intent="technical").with_inputs("text"),
|
|
dspy.Example(text="I want to upgrade my plan", intent="account").with_inputs("text"),
|
|
]
|
|
|
|
program = Classifier()
|
|
optimizer = dspy.BootstrapFewShot(metric=accuracy)
|
|
compiled = optimizer.compile(program, trainset=trainset)
|
|
|
|
# Use
|
|
result = compiled(text="Where is my refund?")
|
|
print(f"Intent: {result.intent}")
|