dspy-core
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDSPy Core
DSPy 核心
Core guidance for working with the DSPy framework: signatures, modules, programs, compilation, and testing.
DSPy框架使用核心指南:签名、模块、程序、编译与测试。
Environment Setup
环境搭建
This skill requires as the Python package manager. Always ensure a virtual environment is active before running any DSPy code.
uvuvbash
undefined本技能需要****作为Python包管理器。在运行任何DSPy代码之前,请确保始终激活虚拟环境。
uvuvbash
undefinedCreate and activate a uv virtual environment
创建并激活uv虚拟环境
uv venv
source .venv/bin/activate
uv venv
source .venv/bin/activate
Install dspy
安装dspy
uv pip install dspy
> **Rule**: Never use raw `pip` or `python -m pip`. Always use `uv pip` for package installation and `uv run` for script execution.uv pip install dspy
> **规则**:永远不要使用原生`pip`或`python -m pip`。安装包请始终使用`uv pip`,执行脚本请使用`uv run`。Quick Start
快速开始
Creating a new signature
创建新签名
python
import dspy
class MySignature(dspy.Signature):
"""Input and output fields with descriptions."""
input_field = dspy.InputField(desc="Description of input")
output_field = dspy.OutputField(desc="Description of output")python
import dspy
class MySignature(dspy.Signature):
"""输入和输出字段及描述。"""
input_field = dspy.InputField(desc="输入描述")
output_field = dspy.OutputField(desc="输出描述")Compiling a program
编译程序
python
undefinedpython
undefinedUse the compile-dspy script for safe compilation
使用compile-dspy脚本进行安全编译
uv run scripts/compile-dspy.py --module my_module --teleprompter teleprompter_name
undefineduv run scripts/compile-dspy.py --module my_module --teleprompter teleprompter_name
undefinedWhen to Use This Skill
适用场景
Use this skill when:
- Creating or modifying DSPy signatures
- Building new DSPy programs or modules
- Running DSPy compilation
- Testing DSPy signatures and programs
- Learning DSPy fundamentals
在以下场景中使用本技能:
- 创建或修改DSPy签名
- 构建新的DSPy程序或模块
- 执行DSPy编译
- 测试DSPy签名和程序
- 学习DSPy基础知识
Core Concepts
核心概念
Signatures
签名
DSPy signatures define the input/output contract for your programs. See signatures.md for:
- Signature design patterns
- InputField vs OutputField usage
- Type hints and validation
- Hint and description best practices
DSPy签名定义了程序的输入/输出契约。请查看signatures.md了解:
- 签名设计模式
- InputField与OutputField的使用
- 类型提示与验证
- 提示与描述的最佳实践
Programs & Modules
程序与模块
DSPy programs are composed of modules that process inputs. See programs.md for:
- Building DSPy programs
- Module composition
- Compilation workflows
- Chain-of-thought and other patterns
DSPy程序由处理输入的模块组成。请查看programs.md了解:
- 构建DSPy程序
- 模块组合
- 编译工作流
- 思维链及其他模式
Scripts
脚本
- compile-dspy.py: Compile DSPy modules with proper caching
- test-signature.py: Validate signature structure and types
- clear-cache.py: Clear DSPy cache safely
- compile-dspy.py:使用适当的缓存编译DSPy模块
- test-signature.py:验证签名结构与类型
- clear-cache.py:安全清除DSPy缓存
Templates
模板
The directory provides boilerplate:
assets/templates/- signature-template.py: Starting point for new signatures
- program-template.py: Starting point for new programs
assets/templates/- signature-template.py:创建新签名的起始模板
- program-template.py:创建新程序的起始模板
Critical Rules
重要规则
- Always use : Use
uvfor environment creation,uv venvfor installs, anduv pipfor script executionuv run - Compilation is offline-only: Never compile at runtime in production
- Clear cache after changes: Run after modifying DSPy modules
clear-cache.py
- 始终使用:使用
uv创建环境,uv venv安装包,uv pip执行脚本uv run - 编译仅支持离线操作:生产环境中切勿在运行时进行编译
- 修改后清除缓存:修改DSPy模块后,请运行
clear-cache.py
Related Skills
相关技能
- dspy-optimization: Optimization, metrics, evaluation, and teleprompters
- dspy-fleet-rlm: fleet-rlm-specific DSPy patterns, debugging, and integration
- dspy-optimization:优化、指标、评估与提示器(teleprompters)
- dspy-fleet-rlm:fleet-rlm专属DSPy模式、调试与集成
Progressive Disclosure
渐进式披露
- SKILL.md (this file): Quick reference and navigation
- references/: Detailed technical docs loaded as needed
- scripts/: Executable tools (can be run without reading)
- assets/: Templates for new work
- SKILL.md(本文档):快速参考与导航
- references/:按需加载的详细技术文档
- scripts/:可直接运行的工具(无需阅读即可使用)
- assets/:用于新工作的模板