dspy 0.15.4 → 0.15.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7154d8c22730a4216467c15a71d3adf4e2826e49211dfde7fd20e20344e4d4b
4
- data.tar.gz: 4e3450f2b5d9e8acf2a5b583a3180bec0608b4c948a9b860bcd8bd387dc0bb7a
3
+ metadata.gz: 23a6a17123d707111960517ebbb8d7accb947bbd2c199aaa9dd6c2173b52a67a
4
+ data.tar.gz: b1a403bd0e4abd30e331fa2d0f84da4bef2a2078bf94d3a69481b93d40fd4d34
5
5
  SHA512:
6
- metadata.gz: 36f07d86290d95e91ac8842807739d9edd566e3b9694413060181266611ea6fa1de941a509feb4518dfd3cf97f922689f8f15df7f6d3182cae0bef1b94b785cb
7
- data.tar.gz: ad2a480af294da127d6fc6b54c56f66e9c59829e86c4dab70c6427d5b9dc6a7a9e26381f35448e9a8b514326169784ba160a92ba488fc06a9e47fcdacd2a2814
6
+ metadata.gz: 955a457ef9f0a391d73212274287ef731c80861d9eb06eec34fa0bca6812a423aa1e759a454f8a1da6d8681ce4485495768cc6c94c7c3633c4b2a94ec8d16551
7
+ data.tar.gz: 90719fda7971c93494494edec7dc69de72208494153b89b67828491740a84c16aded9a8c0f1bde57ded5f22e00ca04934d583053691f53f3d4908137c00c375a
data/README.md CHANGED
@@ -47,7 +47,7 @@ The result? LLM applications that actually scale and don't break when you sneeze
47
47
 
48
48
  ## Development Status
49
49
 
50
- DSPy.rb is actively developed and approaching stability at **v0.13.0**. The core framework is production-ready with comprehensive documentation, but I'm battle-testing features through the 0.x series before committing to a stable v1.0 API.
50
+ DSPy.rb is actively developed and approaching stability at **v0.15.4**. The core framework is production-ready with comprehensive documentation, but I'm battle-testing features through the 0.x series before committing to a stable v1.0 API.
51
51
 
52
52
  Real-world usage feedback is invaluable - if you encounter issues or have suggestions, please open a GitHub issue!
53
53
 
@@ -56,7 +56,7 @@ Real-world usage feedback is invaluable - if you encounter issues or have sugges
56
56
  ### Installation
57
57
 
58
58
  ```ruby
59
- gem 'dspy', '~> 0.13'
59
+ gem 'dspy', '~> 0.15'
60
60
  ```
61
61
 
62
62
  Or add to your Gemfile:
@@ -172,13 +172,12 @@ module DSPy
172
172
  struct_class = type.raw_type
173
173
  struct_props = struct_class.props
174
174
 
175
+ # ONLY include fields that exist in the struct
175
176
  coerced_hash = {}
176
- symbolized_hash.each do |key, val|
177
- if struct_props[key]
177
+ struct_props.each_key do |key|
178
+ if symbolized_hash.key?(key)
178
179
  prop_type = struct_props[key][:type_object] || struct_props[key][:type]
179
- coerced_hash[key] = coerce_value_to_type(val, prop_type)
180
- else
181
- coerced_hash[key] = val
180
+ coerced_hash[key] = coerce_value_to_type(symbolized_hash[key], prop_type)
182
181
  end
183
182
  end
184
183
 
@@ -280,8 +280,20 @@ module DSPy
280
280
  struct_class = type_mapping[discriminator_str]
281
281
  return value unless struct_class
282
282
 
283
- # Convert the Hash to the appropriate struct type
284
- struct_class.new(**value)
283
+ # Filter to only include fields defined in the struct
284
+ struct_props = struct_class.props
285
+ filtered_hash = {}
286
+
287
+ value.each do |k, v|
288
+ # Skip _type field and any fields not defined in the struct
289
+ next if k == :_type || k == "_type"
290
+ next unless struct_props.key?(k.to_sym)
291
+
292
+ filtered_hash[k.to_sym] = v
293
+ end
294
+
295
+ # Convert the filtered Hash to the appropriate struct type
296
+ struct_class.new(**filtered_hash)
285
297
  rescue TypeError, ArgumentError
286
298
  # If conversion fails, return the original value
287
299
  value
@@ -335,9 +347,8 @@ module DSPy
335
347
  else
336
348
  converted_hash[k] = v
337
349
  end
338
- else
339
- converted_hash[k] = v
340
350
  end
351
+ # Skip fields not defined in the struct
341
352
  end
342
353
  begin
343
354
  struct_class.new(**converted_hash)
@@ -388,7 +399,17 @@ module DSPy
388
399
  def needs_array_conversion?(type)
389
400
  case type
390
401
  when T::Types::TypedArray
391
- needs_struct_conversion?(type.type)
402
+ needs_struct_conversion?(type.type) || is_enum_type?(type.type)
403
+ when T::Types::Union
404
+ # Handle nilable arrays: T.nilable(T::Array[...])
405
+ if is_nilable_type?(type)
406
+ # Find the non-nil type in the union
407
+ non_nil_type = type.types.find { |t| t != T::Utils.coerce(NilClass) }
408
+ # Recursively check if it needs array conversion
409
+ needs_array_conversion?(non_nil_type)
410
+ else
411
+ false
412
+ end
392
413
  else
393
414
  false
394
415
  end
@@ -396,6 +417,13 @@ module DSPy
396
417
 
397
418
  sig { params(array: T::Array[T.untyped], type: T.untyped).returns(T::Array[T.untyped]) }
398
419
  def convert_array_elements(array, type)
420
+ # Handle nilable arrays: T.nilable(T::Array[...])
421
+ if type.is_a?(T::Types::Union) && is_nilable_type?(type)
422
+ # Find the non-nil type (should be TypedArray)
423
+ array_type = type.types.find { |t| t != T::Utils.coerce(NilClass) }
424
+ return convert_array_elements(array, array_type)
425
+ end
426
+
399
427
  return array unless type.is_a?(T::Types::TypedArray)
400
428
 
401
429
  element_type = type.type
@@ -470,9 +498,8 @@ module DSPy
470
498
  else
471
499
  converted_hash[k] = v
472
500
  end
473
- else
474
- converted_hash[k] = v
475
501
  end
502
+ # Skip fields not defined in the struct
476
503
  end
477
504
  return struct_class.new(**converted_hash)
478
505
  rescue TypeError, ArgumentError
data/lib/dspy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSPy
4
- VERSION = "0.15.4"
4
+ VERSION = "0.15.6"
5
5
  end
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.15.4
4
+ version: 0.15.6
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-08-02 00:00:00.000000000 Z
10
+ date: 2025-08-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: dry-configurable