dspy 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -17
- data/lib/dspy/lm/strategy_selector.rb +44 -2
- data/lib/dspy/lm/structured_output_strategy.rb +16 -0
- data/lib/dspy/strategy.rb +18 -0
- data/lib/dspy/version.rb +1 -1
- data/lib/dspy.rb +2 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 564abfdf924b5e3aa3c002a9210a3e1ef73f2d418e80bf58a4038eecee65219a
|
4
|
+
data.tar.gz: c7c8c1b2338d09636a5cca0b9bab7b12affe91d22d5edfb25031b9b4740ba68c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d81c9af7ac29706395e20db912af207cfc02f24d5777e247615ad94ebaa07a5f352df7ce87cac0947acb09a9f9d1e1094950c835a47fda5d2441114bdedabbd2
|
7
|
+
data.tar.gz: 9366f67dffe4baa183f40705e8fc5f8f781b5f87e7aca3f0f77f954bb1009edefd773ce68d704a5e3663a0518f940e2ba51cc9b8a6c5c591e4309a7b325d4d51
|
data/README.md
CHANGED
@@ -96,32 +96,33 @@ puts result.confidence # => 0.85
|
|
96
96
|
|
97
97
|
## Documentation
|
98
98
|
|
99
|
+
📖 **[Complete Documentation Website](https://vicentereig.github.io/dspy.rb/)**
|
100
|
+
|
99
101
|
### Getting Started
|
100
|
-
- **[Installation & Setup](docs/getting-started/installation.md)** - Detailed installation and configuration
|
101
|
-
- **[Quick Start Guide](docs/getting-started/quick-start.md)** - Your first DSPy programs
|
102
|
-
- **[Core Concepts](docs/getting-started/core-concepts.md)** - Understanding signatures, predictors, and modules
|
102
|
+
- **[Installation & Setup](docs/src/getting-started/installation.md)** - Detailed installation and configuration
|
103
|
+
- **[Quick Start Guide](docs/src/getting-started/quick-start.md)** - Your first DSPy programs
|
104
|
+
- **[Core Concepts](docs/src/getting-started/core-concepts.md)** - Understanding signatures, predictors, and modules
|
103
105
|
|
104
106
|
### Core Features
|
105
|
-
- **[Signatures & Types](docs/core-concepts/signatures.md)** - Define typed interfaces for LLM operations
|
106
|
-
- **[Predictors](docs/core-concepts/predictors.md)** - Predict, ChainOfThought, ReAct, and more
|
107
|
-
- **[Modules & Pipelines](docs/core-concepts/modules.md)** - Compose complex multi-stage workflows
|
108
|
-
- **[Examples & Validation](docs/core-concepts/examples.md)** - Type-safe training data
|
107
|
+
- **[Signatures & Types](docs/src/core-concepts/signatures.md)** - Define typed interfaces for LLM operations
|
108
|
+
- **[Predictors](docs/src/core-concepts/predictors.md)** - Predict, ChainOfThought, ReAct, and more
|
109
|
+
- **[Modules & Pipelines](docs/src/core-concepts/modules.md)** - Compose complex multi-stage workflows
|
110
|
+
- **[Examples & Validation](docs/src/core-concepts/examples.md)** - Type-safe training data
|
109
111
|
|
110
112
|
### Optimization
|
111
|
-
- **[Evaluation Framework](docs/optimization/evaluation.md)** - Basic testing with simple metrics
|
112
|
-
- **[Prompt Optimization](docs/optimization/prompt-optimization.md)** - Manipulate prompts as objects
|
113
|
-
- **[MIPROv2 Optimizer](docs/optimization/miprov2.md)** - Basic automatic optimization
|
114
|
-
- **[Simple Optimizer](docs/optimization/simple-optimizer.md)** - Random search experimentation
|
113
|
+
- **[Evaluation Framework](docs/src/optimization/evaluation.md)** - Basic testing with simple metrics
|
114
|
+
- **[Prompt Optimization](docs/src/optimization/prompt-optimization.md)** - Manipulate prompts as objects
|
115
|
+
- **[MIPROv2 Optimizer](docs/src/optimization/miprov2.md)** - Basic automatic optimization
|
115
116
|
|
116
117
|
### Production Features
|
117
|
-
- **[Storage System](docs/production/storage.md)** - Basic file-based persistence
|
118
|
-
- **[Observability](docs/production/observability.md)** - Multi-platform monitoring and metrics
|
118
|
+
- **[Storage System](docs/src/production/storage.md)** - Basic file-based persistence
|
119
|
+
- **[Observability](docs/src/production/observability.md)** - Multi-platform monitoring and metrics
|
119
120
|
|
120
121
|
### Advanced Usage
|
121
|
-
- **[Complex Types](docs/advanced/complex-types.md)** - Sorbet type integration with automatic coercion for structs, enums, and arrays
|
122
|
-
- **[Manual Pipelines](docs/advanced/pipelines.md)** - Manual module composition patterns
|
123
|
-
- **[RAG Patterns](docs/advanced/rag.md)** - Manual RAG implementation with external services
|
124
|
-
- **[Custom Metrics](docs/advanced/custom-metrics.md)** - Proc-based evaluation logic
|
122
|
+
- **[Complex Types](docs/src/advanced/complex-types.md)** - Sorbet type integration with automatic coercion for structs, enums, and arrays
|
123
|
+
- **[Manual Pipelines](docs/src/advanced/pipelines.md)** - Manual module composition patterns
|
124
|
+
- **[RAG Patterns](docs/src/advanced/rag.md)** - Manual RAG implementation with external services
|
125
|
+
- **[Custom Metrics](docs/src/advanced/custom-metrics.md)** - Proc-based evaluation logic
|
125
126
|
|
126
127
|
## What's Next
|
127
128
|
|
@@ -31,10 +31,16 @@ module DSPy
|
|
31
31
|
def select
|
32
32
|
# Allow manual override via configuration
|
33
33
|
if DSPy.config.structured_outputs.strategy
|
34
|
-
strategy =
|
34
|
+
strategy = select_strategy_from_preference(DSPy.config.structured_outputs.strategy)
|
35
35
|
return strategy if strategy&.available?
|
36
36
|
|
37
|
-
|
37
|
+
# If strict strategy not available, fall back to compatible for Strict preference
|
38
|
+
if is_strict_preference?(DSPy.config.structured_outputs.strategy)
|
39
|
+
compatible_strategy = find_strategy_by_name("enhanced_prompting")
|
40
|
+
return compatible_strategy if compatible_strategy&.available?
|
41
|
+
end
|
42
|
+
|
43
|
+
DSPy.logger.warn("No available strategy found for preference '#{DSPy.config.structured_outputs.strategy}'")
|
38
44
|
end
|
39
45
|
|
40
46
|
# Select the highest priority available strategy
|
@@ -65,6 +71,42 @@ module DSPy
|
|
65
71
|
|
66
72
|
private
|
67
73
|
|
74
|
+
# Select internal strategy based on user preference
|
75
|
+
sig { params(preference: DSPy::Strategy).returns(T.nilable(Strategies::BaseStrategy)) }
|
76
|
+
def select_strategy_from_preference(preference)
|
77
|
+
case preference
|
78
|
+
when DSPy::Strategy::Strict
|
79
|
+
# Try provider-optimized strategies first
|
80
|
+
select_provider_optimized_strategy
|
81
|
+
when DSPy::Strategy::Compatible
|
82
|
+
# Use enhanced prompting
|
83
|
+
find_strategy_by_name("enhanced_prompting")
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Check if preference is for strict (provider-optimized) strategies
|
90
|
+
sig { params(preference: DSPy::Strategy).returns(T::Boolean) }
|
91
|
+
def is_strict_preference?(preference)
|
92
|
+
preference == DSPy::Strategy::Strict
|
93
|
+
end
|
94
|
+
|
95
|
+
# Select the best provider-optimized strategy for the current adapter
|
96
|
+
sig { returns(T.nilable(Strategies::BaseStrategy)) }
|
97
|
+
def select_provider_optimized_strategy
|
98
|
+
# Try OpenAI structured output first
|
99
|
+
openai_strategy = find_strategy_by_name("openai_structured_output")
|
100
|
+
return openai_strategy if openai_strategy&.available?
|
101
|
+
|
102
|
+
# Try Anthropic extraction
|
103
|
+
anthropic_strategy = find_strategy_by_name("anthropic_extraction")
|
104
|
+
return anthropic_strategy if anthropic_strategy&.available?
|
105
|
+
|
106
|
+
# No provider-specific strategy available
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
|
68
110
|
sig { returns(T::Array[Strategies::BaseStrategy]) }
|
69
111
|
def build_strategies
|
70
112
|
STRATEGIES.map { |klass| klass.new(@adapter, @signature_class) }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sorbet-runtime"
|
4
|
+
|
5
|
+
module DSPy
|
6
|
+
class LM
|
7
|
+
# Enum for structured output strategies
|
8
|
+
class StructuredOutputStrategy < T::Enum
|
9
|
+
enums do
|
10
|
+
OpenAIStructuredOutput = new("openai_structured_output")
|
11
|
+
AnthropicExtraction = new("anthropic_extraction")
|
12
|
+
EnhancedPrompting = new("enhanced_prompting")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sorbet-runtime"
|
4
|
+
|
5
|
+
module DSPy
|
6
|
+
# User-facing enum for structured output strategy preferences
|
7
|
+
class Strategy < T::Enum
|
8
|
+
enums do
|
9
|
+
# Use provider-optimized strategies when available (OpenAI structured outputs, Anthropic extraction)
|
10
|
+
# Falls back to Compatible if provider-specific strategy isn't available
|
11
|
+
Strict = new("strict")
|
12
|
+
|
13
|
+
# Use enhanced prompting that works with any provider
|
14
|
+
# More compatible but potentially less reliable than provider-specific strategies
|
15
|
+
Compatible = new("compatible")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/dspy/version.rb
CHANGED
data/lib/dspy.rb
CHANGED
@@ -25,7 +25,7 @@ module DSPy
|
|
25
25
|
setting :structured_outputs do
|
26
26
|
setting :openai, default: false
|
27
27
|
setting :anthropic, default: false # Reserved for future use
|
28
|
-
setting :strategy, default: nil # Can be
|
28
|
+
setting :strategy, default: nil # Can be DSPy::Strategy::Strict, DSPy::Strategy::Compatible, or nil for auto
|
29
29
|
setting :retry_enabled, default: true
|
30
30
|
setting :max_retries, default: 3
|
31
31
|
setting :fallback_enabled, default: true
|
@@ -122,6 +122,7 @@ require_relative 'dspy/few_shot_example'
|
|
122
122
|
require_relative 'dspy/prompt'
|
123
123
|
require_relative 'dspy/example'
|
124
124
|
require_relative 'dspy/lm'
|
125
|
+
require_relative 'dspy/strategy'
|
125
126
|
require_relative 'dspy/predict'
|
126
127
|
require_relative 'dspy/chain_of_thought'
|
127
128
|
require_relative 'dspy/re_act'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dspy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vicente Reig Rincón de Arellano
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/dspy/lm/strategies/enhanced_prompting_strategy.rb
|
183
183
|
- lib/dspy/lm/strategies/openai_structured_output_strategy.rb
|
184
184
|
- lib/dspy/lm/strategy_selector.rb
|
185
|
+
- lib/dspy/lm/structured_output_strategy.rb
|
185
186
|
- lib/dspy/memory.rb
|
186
187
|
- lib/dspy/memory/embedding_engine.rb
|
187
188
|
- lib/dspy/memory/in_memory_store.rb
|
@@ -204,6 +205,7 @@ files:
|
|
204
205
|
- lib/dspy/signature.rb
|
205
206
|
- lib/dspy/storage/program_storage.rb
|
206
207
|
- lib/dspy/storage/storage_manager.rb
|
208
|
+
- lib/dspy/strategy.rb
|
207
209
|
- lib/dspy/subscribers/langfuse_subscriber.rb
|
208
210
|
- lib/dspy/subscribers/logger_subscriber.rb
|
209
211
|
- lib/dspy/subscribers/newrelic_subscriber.rb
|