dspy-ruby
This skill should be used when working with DSPy.rb, a Ruby framework for building type-safe, composable LLM applications. Use this when implementing predictable AI features, creating LLM signatures and modules, configuring language model providers (OpenAI, Anthropic, Gemini, Ollama), building agent systems with tools, optimizing prompts, or testing LLM-powered functionality in Ruby applications.
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- dspy-ruby
- model
- inherit
- description
- This skill should be used when working with DSPy.rb, a Ruby framework for building type-safe, composable LLM applications. Use this when implementing predictable AI features, creating LLM signatures and modules, configuring language model providers (OpenAI, Anthropic, Gemini, Ollama), building agent systems with tools, optimizing prompts, or testing LLM-powered functionality in Ruby applications.
- allowed-tools
- [ "Bash", "Read", "Write", "Edit", "Grep", "Glob" ]
- user-invocable
- true
02 资源文件 8
- 脚本assets/config-template.rb10.1 KB
- 脚本assets/module-template.rb7.5 KB
- 脚本assets/signature-template.rb4.7 KB
- 参考文档references/core-concepts.md6.2 KB
- 参考文档references/optimization.md13.9 KB
- 参考文档references/patterns.md3.2 KB
- 参考文档references/providers.md8.0 KB
- 参考文档references/quickstart.md2.1 KB
03 SKILL.md 正文
DSPy.rb Expert
Overview
DSPy.rb is a Ruby framework that enables developers to program LLMs, not prompt them. Instead of manually crafting prompts, define application requirements through type-safe, composable modules that can be tested, optimized, and version-controlled like regular code.
Mode Detection
Determine what the user needs, then read ONLY the relevant reference files before proceeding.
| User Intent | Reference Files to Read |
|---|---|
| Signatures, modules, predictors, type safety | core-concepts.md |
| LLM provider setup, API keys, configuration | providers.md |
| Testing, optimization, observability | optimization.md |
| Getting started, Rails integration | quickstart.md |
| Common patterns, agents, pipelines, vision | patterns.md |
All reference files are in ~/.claude/skills/dspy-ruby/references/.
Core Capabilities (Quick Reference)
1. Type-Safe Signatures
class EmailClassificationSignature < DSPy::Signature
description "Classify customer support emails"
input do
const :email_subject, String
const :email_body, String
end
output do
const :category, T.enum(["Technical", "Billing", "General"])
const :priority, T.enum(["Low", "Medium", "High"])
end
end
Best practices: Clear descriptions, enums for constrained outputs, desc: parameter for fields, specific types over generic String. Full docs: core-concepts.md.
2. Composable Modules
class EmailProcessor < DSPy::Module
def initialize
super
@classifier = DSPy::Predict.new(EmailClassificationSignature)
end
def forward(email_subject:, email_body:)
@classifier.forward(email_subject: email_subject, email_body: email_body)
end
end
Chain modules for complex workflows. Full docs: core-concepts.md.
3. Predictor Types
| Predictor | Use For | Key Feature |
|---|---|---|
| Predict | Simple tasks, classification, extraction | Basic type-safe inference |
| ChainOfThought | Complex reasoning, analysis | Automatic reasoning step |
| ReAct | Tasks requiring external tools | Iterative tool-using agent |
| CodeAct | Tasks best solved with code | Dynamic code generation (dspy-code_act gem) |
Full docs: core-concepts.md.
4. LLM Provider Configuration
# OpenAI
DSPy.configure { |c| c.lm = DSPy::LM.new('openai/gpt-4o-mini', api_key: ENV['OPENAI_API_KEY']) }
# Anthropic Claude
DSPy.configure { |c| c.lm = DSPy::LM.new('anthropic/claude-3-5-sonnet-20241022', api_key: ENV['ANTHROPIC_API_KEY']) }
# Google Gemini
DSPy.configure { |c| c.lm = DSPy::LM.new('gemini/gemini-1.5-pro', api_key: ENV['GOOGLE_API_KEY']) }
# Local Ollama (free, private)
DSPy.configure { |c| c.lm = DSPy::LM.new('ollama/llama3.1') }
Provider compatibility matrix:
| Feature | OpenAI | Anthropic | Gemini | Ollama |
|---|---|---|---|---|
| Structured Output | yes | yes | yes | yes |
| Vision (Images) | yes | yes | yes | limited |
| Image URLs | yes | no | no | no |
| Tool Calling | yes | yes | yes | varies |
Cost optimization: Dev = Ollama/gpt-4o-mini, Test = gpt-4o-mini (temp=0), Prod simple = gpt-4o-mini/haiku/flash, Prod complex = gpt-4o/sonnet/pro. Full docs: providers.md.
5. Testing
RSpec.describe EmailClassifier do
before do
DSPy.configure { |c| c.lm = DSPy::LM.new('openai/gpt-4o-mini', api_key: ENV['OPENAI_API_KEY']) }
end
it 'classifies technical emails correctly' do
result = EmailClassifier.new.forward(email_subject: "Can't log in", email_body: "Unable to access account")
expect(result[:category]).to eq('Technical')
end
end
Full docs: optimization.md.
Reference Files Index
| File | Content |
|---|---|
core-concepts.md |
Signatures, modules, predictors, multimodal support, best practices |
providers.md |
All LLM provider configs, compatibility matrix, cost optimization, troubleshooting |
optimization.md |
Testing patterns, MIPROv2 optimization, observability, monitoring |
quickstart.md |
Step-by-step new project setup, Rails integration |
patterns.md |
Multi-step pipelines, agents with tools, conditional routing, retry/fallback, vision, observability |
Assets (templates for quick starts)
assets/signature-template.rb-- Examples of signatures including basic, vision, sentiment, code genassets/module-template.rb-- Module patterns including pipelines, agents, error handling, cachingassets/config-template.rb-- Configuration for all providers, environments, observability, production
When to Use This Skill
- Implementing LLM-powered features in Ruby applications
- Creating type-safe interfaces for AI operations
- Building agent systems with tool usage
- Setting up or troubleshooting LLM providers
- Optimizing prompts and improving accuracy
- Testing LLM functionality
- Adding observability to AI applications
- Converting from manual prompt engineering to programmatic approach
- Debugging DSPy.rb code or configuration issues
04 同仓库更多 Skills
zi-search
暂无简介
visualise
Render inline interactive visuals — SVG diagrams, HTML widgets, charts, and explainers — directly in the conversation. Use this skill whenever the user asks to visualize, diagram, chart, illustrate, or explain something visually, or when an explanation would genuinely benefit from a spatial/interactive diagram rather than text. Also triggers for: flowcharts, architecture diagrams, data visualizations, interactive explainers, comparison layouts, UI mockups, and any request containing 'show me', 'draw', 'map out', 'visualize', or 'diagram'. Even when the user doesn't explicitly ask for a visual, use this skill proactively when the topic has spatial, sequential, or systemic relationships that a diagram would clarify better than prose.
video
When the user wants to create, generate, or produce video content using AI tools or programmatic frameworks. Also use when the user mentions 'video production,' 'AI video,' 'Remotion,' 'Hyperframes,' 'HeyGen,' 'Synthesia,' 'Veo,' 'Runway,' 'Kling,' 'Pika,' 'video generation,' 'AI avatar,' 'talking head video,' 'programmatic video,' 'video template,' 'explainer video,' 'product demo video,' 'video pipeline,' or 'make me a video.' Use this for video creation, generation, and production workflows. For video content strategy and what to post, see social-content. For paid video ad creative, see ad-creative.
manim-video
Production pipeline for mathematical and technical animations using Manim Community Edition. Creates 3Blue1Brown-style explainer videos, algorithm visualizations, equation derivations, architecture diagrams, and data stories. Use when users request: animated explanations, math animations, concept visualizations, algorithm walkthroughs, technical explainers, 3Blue1Brown style videos, or any programmatic animation with geometric/mathematical content.
video-use
Edit any video by conversation. Transcribe, cut, color grade, generate overlay animations, burn subtitles — for talking heads, montages, tutorials, travel, interviews. No presets, no menus. Ask questions, confirm the plan, execute, iterate, persist. Production-correctness rules are hard; everything else is artistic freedom.
ui-improver
暂无简介