Module: DSPy::Ext::StructDescriptions

Defined in:
lib/dspy/ext/struct_descriptions.rb

Overview

Extends T::Struct to support field descriptions via the :description kwarg.

This module is prepended to T::Struct to intercept const/prop definitions and capture descriptions before they reach Sorbet (which doesn’t support them).

Examples:

class ASTNode < T::Struct
  const :node_type, String, description: 'The type of AST node'
  const :text, String, default: "", description: 'Text content of the node'
  const :children, T::Array[ASTNode], default: []
end

ASTNode.field_descriptions[:node_type]  # => "The type of AST node"
ASTNode.field_descriptions[:text]       # => "Text content of the node"
ASTNode.field_descriptions[:children]   # => nil (no description)

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



24
25
26
# File 'lib/dspy/ext/struct_descriptions.rb', line 24

def self.prepended(base)
  base.singleton_class.prepend(ClassMethods)
end