Class: DSPy::Signature
- Inherits:
-
Object
- Object
- DSPy::Signature
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/signature.rb
Direct Known Subclasses
ReActObservationBase, RubyCodeGeneration, RubyCodeObservation, ThoughtBase
Defined Under Namespace
Classes: FieldDescriptor, StructBuilder
Class Attribute Summary collapse
-
.desc ⇒ Object
readonly
Returns the value of attribute desc.
-
.input_field_descriptors ⇒ Object
readonly
Returns the value of attribute input_field_descriptors.
-
.input_struct_class ⇒ Object
readonly
Returns the value of attribute input_struct_class.
-
.output_field_descriptors ⇒ Object
readonly
Returns the value of attribute output_field_descriptors.
-
.output_struct_class ⇒ Object
readonly
Returns the value of attribute output_struct_class.
Class Method Summary collapse
- .description(desc = nil) ⇒ Object
- .input(&block) ⇒ Object
- .input_json_schema ⇒ Object
- .input_schema ⇒ Object
- .output(&block) ⇒ Object
- .output_json_schema ⇒ Object
- .output_schema ⇒ Object
Class Attribute Details
.desc ⇒ Object (readonly)
Returns the value of attribute desc.
75 76 77 |
# File 'lib/dspy/signature.rb', line 75 def desc @desc end |
.input_field_descriptors ⇒ Object (readonly)
Returns the value of attribute input_field_descriptors.
84 85 86 |
# File 'lib/dspy/signature.rb', line 84 def input_field_descriptors @input_field_descriptors end |
.input_struct_class ⇒ Object (readonly)
Returns the value of attribute input_struct_class.
78 79 80 |
# File 'lib/dspy/signature.rb', line 78 def input_struct_class @input_struct_class end |
.output_field_descriptors ⇒ Object (readonly)
Returns the value of attribute output_field_descriptors.
87 88 89 |
# File 'lib/dspy/signature.rb', line 87 def output_field_descriptors @output_field_descriptors end |
.output_struct_class ⇒ Object (readonly)
Returns the value of attribute output_struct_class.
81 82 83 |
# File 'lib/dspy/signature.rb', line 81 def output_struct_class @output_struct_class end |
Class Method Details
.description(desc = nil) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/dspy/signature.rb', line 90 def description(desc = nil) if desc.nil? @desc else @desc = desc end end |
.input(&block) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dspy/signature.rb', line 99 def input(&block) builder = StructBuilder.new if block.arity > 0 block.call(builder) else # Preferred format builder.instance_eval(&block) end @input_field_descriptors = builder.field_descriptors @input_struct_class = builder.build_struct_class end |
.input_json_schema ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/dspy/signature.rb', line 129 def input_json_schema return {} unless @input_struct_class properties = {} required = [] @input_field_descriptors&.each do |name, descriptor| schema = type_to_json_schema(descriptor.type) schema[:description] = descriptor.description if descriptor.description properties[name] = schema required << name.to_s unless descriptor.has_default end { "$schema": "http://json-schema.org/draft-06/schema#", type: "object", properties: properties, required: required } end |
.input_schema ⇒ Object
151 152 153 |
# File 'lib/dspy/signature.rb', line 151 def input_schema @input_struct_class end |
.output(&block) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dspy/signature.rb', line 114 def output(&block) builder = StructBuilder.new if block.arity > 0 block.call(builder) else # Preferred format builder.instance_eval(&block) end @output_field_descriptors = builder.field_descriptors @output_struct_class = builder.build_struct_class end |
.output_json_schema ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/dspy/signature.rb', line 156 def output_json_schema return {} unless @output_struct_class properties = {} required = [] @output_field_descriptors&.each do |name, descriptor| schema = type_to_json_schema(descriptor.type) schema[:description] = descriptor.description if descriptor.description properties[name] = schema required << name.to_s unless descriptor.has_default end { "$schema": "http://json-schema.org/draft-06/schema#", type: "object", properties: properties, required: required } end |
.output_schema ⇒ Object
178 179 180 |
# File 'lib/dspy/signature.rb', line 178 def output_schema @output_struct_class end |