dspy-better-together

Solid

This skill should be used when the user asks to "use BetterTogether", "combine prompt optimization and fine-tuning", "sequence DSPy optimizers", "run prompt then weight optimization", mentions `dspy.BetterTogether`, strategy strings such as "p -> w -> p", or needs to compose multiple DSPy teleprompters into an evaluated optimization sequence.

AI & Automation 78 stars 10 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 90/100

Stars 20%
63
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# DSPy BetterTogether ## Goal Sequence prompt and weight optimizers, evaluate intermediate programs, and return the best candidate. ## Prerequisites - Use DSPy `3.2.1` or later in the stable `3.2.x` series. - Assign an LM directly to every predictor with `student.set_lm(lm)`. - Keep a validation set, or allow `BetterTogether` to hold out part of the trainset. - Confirm the LM provider supports fine-tuning before including `BootstrapFinetune`. ## Basic Pattern ```python import dspy lm = dspy.LM("openai/gpt-4o-mini") dspy.configure(lm=lm) student = dspy.ChainOfThought("question -> answer") student.set_lm(lm) def metric(example, pred, trace=None): return float(example.answer.lower() == pred.answer.lower()) optimizer = dspy.BetterTogether( metric=metric, p=dspy.GEPA( metric=lambda gold, pred, trace=None, pred_name=None, pred_trace=None: dspy.Prediction(score=metric(gold, pred), feedback="Check answer correctness."), reflection_lm=dspy.LM("openai/gpt-4o"), auto="light", ), w=dspy.BootstrapFinetune(metric=metric), ) compiled = optimizer.compile( student, trainset=trainset, valset=valset, strategy="p -> w -> p", ) ``` ## Strategy Choices | Strategy | Use it when | |----------|-------------| | `"p -> w"` | Start with a simple prompt-then-weight pass | | `"p -> w -> p"` | Re-optimize prompts after fine-tuning | | `"w -> p"` | Fine-tuning data is already strong | | Custom chains | Comparing prompt opti...

Details

Author
OmidZamani
Repository
OmidZamani/dspy-skills
Created
5 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category