Skip to main content
ClaudeWave
Skill78 estrellas del repoactualizado 11d ago

dspy-better-together

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.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/OmidZamani/dspy-skills /tmp/dspy-better-together && cp -r /tmp/dspy-better-together/skills/dspy-better-together ~/.claude/skills/dspy-better-together
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

# 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 optimizers or conducting controlled experiments |

Optimizer names come from constructor keyword arguments. For example, `mipro=...` and `gepa=...` make `"mipro -> gepa"` valid.

## Per-Optimizer Compile Arguments

Pass optimizer-specific arguments through `optimizer_compile_args`:

```python
compiled = optimizer.compile(
    student,
    trainset=trainset,
    valset=valset,
    strategy="p -> w",
    optimizer_compile_args={
        "p": {"max_metric_calls": 150},
    },
)
```

Do not pass `student` inside `optimizer_compile_args`; `BetterTogether` manages the current program.

## Inspect Results

The returned program exposes:

- `candidate_programs`: evaluated candidates with score and strategy
- `flag_compilation_error_occurred`: whether a step failed before completion

## Related Skills

- Pick optimizers: [dspy-optimizer-selection](../dspy-optimizer-selection/SKILL.md)
- Fine-tune weights: [dspy-finetune-bootstrap](../dspy-finetune-bootstrap/SKILL.md)
- Reflect with GEPA: [dspy-gepa-reflective](../dspy-gepa-reflective/SKILL.md)

## Official Documentation

- **BetterTogether API**: https://dspy.ai/api/optimizers/BetterTogether/
- **Optimizer guide**: https://dspy.ai/learn/optimization/optimizers/
skill-perfectionSkill

Use this skill when you need to QA audit and fix a plugin skill file. Provides a methodology for verifying skill content against official documentation, fixing issues in-place, and producing verification reports.

dspy-adapters-multimodalSkill

This skill should be used when the user asks to "choose a DSPy adapter", "use JSONAdapter", "use XMLAdapter", "enable native function calling", "send images, audio, or files to DSPy", mentions `dspy.ChatAdapter`, `dspy.JSONAdapter`, `dspy.XMLAdapter`, `dspy.Image`, `dspy.Audio`, `dspy.File`, structured outputs, or multimodal DSPy signatures.

dspy-advanced-module-compositionSkill

This skill should be used when the user asks to "compose DSPy modules", "use Ensemble optimizer", "combine multiple programs", "use dspy.MultiChainComparison", mentions "ensemble voting", "module composition", "sequential pipelines", or needs to build complex multi-module DSPy programs with ensemble patterns or multi-chain comparison.

dspy-bootstrap-fewshotSkill

This skill should be used when the user asks to "bootstrap few-shot examples", "generate demonstrations", "use BootstrapFewShot", "optimize with limited data", "create training demos automatically", mentions "teacher model for few-shot", "10-50 training examples", or wants automatic demonstration generation for a DSPy program without extensive compute.

dspy-custom-module-designSkill

This skill should be used when the user asks to "create custom DSPy module", "design a DSPy module", "extend dspy.Module", "build reusable DSPy component", mentions "custom module patterns", "module serialization", "stateful modules", "module testing", or needs to design production-quality custom DSPy modules with proper architecture, state management, and testing.

dspy-debugging-observabilitySkill

This skill should be used when the user asks to "debug DSPy programs", "trace LLM calls", "monitor production DSPy", "use MLflow with DSPy", mentions "inspect_history", "custom callbacks", "observability", "production monitoring", "cost tracking", or needs to debug, trace, and monitor DSPy applications in development and production.

dspy-embedding-retrievalSkill

This skill should be used when the user asks to "build local DSPy retrieval", "use dspy.Embedder", "use dspy.Embeddings", "save an embeddings index", "add FAISS retrieval", mentions semantic search, hosted embeddings, local embedding models, `EmbeddingsWithScores`, or needs a DSPy retriever over an application-owned text corpus.

dspy-evaluation-suiteSkill

This skill should be used when the user asks to "evaluate a DSPy program", "test my DSPy module", "measure performance", "create evaluation metrics", "use answer_exact_match or SemanticF1", mentions "Evaluate class", "comparing programs", "establishing baselines", or needs to systematically test and measure DSPy program quality with custom or built-in metrics.