‹ 首页

dspy-better-together

@omidzamani · 收录于 1 周前

Use for BetterTogether, prompt plus weight optimization, fine-tuning sequences, and strategy chains like p -> w -> p.

适合你,如果正在用 DSPy 做提示工程或模型微调

/ 下载安装
dspy-better-together.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add omidzamani/dspy-skills/dspy-better-together
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- omidzamani/dspy-skills/dspy-better-together
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify omidzamani/dspy-skills/dspy-better-together
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
113GitHub stars
~589最小装载
~589含声明引用
~729文本包总量
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · f5db3b7

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
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:

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/
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。