dspy 0.6.1 → 0.6.3
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 +1 -1
- data/lib/dspy/mixins/type_coercion.rb +70 -2
- data/lib/dspy/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae1673ad31bc71e2573800124ebb74ea807cd94a1c14b9b58f3de94b7f62363a
|
4
|
+
data.tar.gz: f52d96924b536e5941ff34b45f1080ddb08dc9243095df51f11352cb65979ba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98f1d7b285f9342b8dfc82cdc7606d2a4c8cbdb1df86713b7176a389893f7c652e7c5df473ddcf42335ab37a2cfffe35e9519310b45be396c9bfe8847c7fabc1
|
7
|
+
data.tar.gz: cbee70fb3afc5b5b7dce3caf2efbca258d5cbd12680f950fe52be30bd84754369b620c21617315c04a62e2f982fe485b0c05f7ed30676007c19527715c3fc9c0
|
data/README.md
CHANGED
@@ -113,7 +113,7 @@ puts result.confidence # => 0.85
|
|
113
113
|
- **[Observability](docs/production/observability.md)** - Multi-platform monitoring and metrics
|
114
114
|
|
115
115
|
### Advanced Usage
|
116
|
-
- **[Complex Types](docs/advanced/complex-types.md)** -
|
116
|
+
- **[Complex Types](docs/advanced/complex-types.md)** - Sorbet type integration with automatic coercion for structs, enums, and arrays
|
117
117
|
- **[Manual Pipelines](docs/advanced/pipelines.md)** - Manual module composition patterns
|
118
118
|
- **[RAG Patterns](docs/advanced/rag.md)** - Manual RAG implementation with external services
|
119
119
|
- **[Custom Metrics](docs/advanced/custom-metrics.md)** - Proc-based evaluation logic
|
@@ -30,12 +30,16 @@ module DSPy
|
|
30
30
|
return value if value.nil?
|
31
31
|
|
32
32
|
case prop_type
|
33
|
+
when ->(type) { array_type?(type) }
|
34
|
+
coerce_array_value(value, prop_type)
|
33
35
|
when ->(type) { enum_type?(type) }
|
34
36
|
extract_enum_class(prop_type).deserialize(value)
|
35
37
|
when Float, ->(type) { simple_type_match?(type, Float) }
|
36
38
|
value.to_f
|
37
39
|
when Integer, ->(type) { simple_type_match?(type, Integer) }
|
38
40
|
value.to_i
|
41
|
+
when ->(type) { struct_type?(type) }
|
42
|
+
coerce_struct_value(value, prop_type)
|
39
43
|
else
|
40
44
|
value
|
41
45
|
end
|
@@ -44,8 +48,17 @@ module DSPy
|
|
44
48
|
# Checks if a type is an enum type
|
45
49
|
sig { params(type: T.untyped).returns(T::Boolean) }
|
46
50
|
def enum_type?(type)
|
47
|
-
|
48
|
-
|
51
|
+
return false unless type
|
52
|
+
|
53
|
+
if type.is_a?(Class)
|
54
|
+
!!(type < T::Enum)
|
55
|
+
elsif type.is_a?(T::Types::Simple)
|
56
|
+
!!(type.raw_type < T::Enum)
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
60
|
+
rescue StandardError
|
61
|
+
false
|
49
62
|
end
|
50
63
|
|
51
64
|
# Extracts the enum class from a type
|
@@ -65,6 +78,61 @@ module DSPy
|
|
65
78
|
def simple_type_match?(type, target_type)
|
66
79
|
type.is_a?(T::Types::Simple) && type.raw_type == target_type
|
67
80
|
end
|
81
|
+
|
82
|
+
# Checks if a type is an array type
|
83
|
+
sig { params(type: T.untyped).returns(T::Boolean) }
|
84
|
+
def array_type?(type)
|
85
|
+
return false unless type.is_a?(T::Types::TypedArray)
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
# Checks if a type is a struct type
|
90
|
+
sig { params(type: T.untyped).returns(T::Boolean) }
|
91
|
+
def struct_type?(type)
|
92
|
+
if type.is_a?(Class)
|
93
|
+
!!(type < T::Struct)
|
94
|
+
elsif type.is_a?(T::Types::Simple)
|
95
|
+
!!(type.raw_type < T::Struct)
|
96
|
+
else
|
97
|
+
false
|
98
|
+
end
|
99
|
+
rescue StandardError
|
100
|
+
false
|
101
|
+
end
|
102
|
+
|
103
|
+
# Coerces an array value, converting each element as needed
|
104
|
+
sig { params(value: T.untyped, prop_type: T.untyped).returns(T.untyped) }
|
105
|
+
def coerce_array_value(value, prop_type)
|
106
|
+
return value unless value.is_a?(Array)
|
107
|
+
return value unless prop_type.is_a?(T::Types::TypedArray)
|
108
|
+
|
109
|
+
element_type = prop_type.type
|
110
|
+
value.map { |element| coerce_value_to_type(element, element_type) }
|
111
|
+
end
|
112
|
+
|
113
|
+
# Coerces a struct value from a hash
|
114
|
+
sig { params(value: T.untyped, prop_type: T.untyped).returns(T.untyped) }
|
115
|
+
def coerce_struct_value(value, prop_type)
|
116
|
+
return value unless value.is_a?(Hash)
|
117
|
+
|
118
|
+
struct_class = if prop_type.is_a?(Class)
|
119
|
+
prop_type
|
120
|
+
elsif prop_type.is_a?(T::Types::Simple)
|
121
|
+
prop_type.raw_type
|
122
|
+
else
|
123
|
+
return value
|
124
|
+
end
|
125
|
+
|
126
|
+
# Convert string keys to symbols
|
127
|
+
symbolized_hash = value.transform_keys(&:to_sym)
|
128
|
+
|
129
|
+
# Create the struct instance
|
130
|
+
struct_class.new(**symbolized_hash)
|
131
|
+
rescue ArgumentError => e
|
132
|
+
# If struct creation fails, return the original value
|
133
|
+
DSPy.logger.debug("Failed to coerce to struct #{struct_class}: #{e.message}")
|
134
|
+
value
|
135
|
+
end
|
68
136
|
end
|
69
137
|
end
|
70
138
|
end
|
data/lib/dspy/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dspy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vicente Reig Rincón de Arellano
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-08 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: dry-configurable
|
@@ -71,14 +71,14 @@ dependencies:
|
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
74
|
+
version: 0.12.0
|
75
75
|
type: :runtime
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.
|
81
|
+
version: 0.12.0
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: anthropic
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|