Class: DSPy::Signature
- Inherits:
-
Object
show all
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/signature.rb
Defined Under Namespace
Classes: FieldDescriptor, StructBuilder
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.desc ⇒ Object
Returns the value of attribute desc.
74
75
76
|
# File 'lib/dspy/signature.rb', line 74
def desc
@desc
end
|
Returns the value of attribute input_field_descriptors.
83
84
85
|
# File 'lib/dspy/signature.rb', line 83
def input_field_descriptors
@input_field_descriptors
end
|
Returns the value of attribute input_struct_class.
77
78
79
|
# File 'lib/dspy/signature.rb', line 77
def input_struct_class
@input_struct_class
end
|
.output_field_descriptors ⇒ Object
Returns the value of attribute output_field_descriptors.
86
87
88
|
# File 'lib/dspy/signature.rb', line 86
def output_field_descriptors
@output_field_descriptors
end
|
.output_struct_class ⇒ Object
Returns the value of attribute output_struct_class.
80
81
82
|
# File 'lib/dspy/signature.rb', line 80
def output_struct_class
@output_struct_class
end
|
Class Method Details
.description(desc = nil) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/dspy/signature.rb', line 89
def description(desc = nil)
if desc.nil?
@desc
else
@desc = desc
end
end
|
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/dspy/signature.rb', line 98
def input(&block)
builder = StructBuilder.new
if block.arity > 0
block.call(builder)
else
builder.instance_eval(&block)
end
@input_field_descriptors = builder.field_descriptors
@input_struct_class = builder.build_struct_class
end
|
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/dspy/signature.rb', line 128
def input_json_schema
return {} unless @input_struct_class
properties = {}
required = []
@input_field_descriptors&.each do |name, descriptor|
schema = DSPy::TypeSystem::SorbetJsonSchema.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
|
150
151
152
|
# File 'lib/dspy/signature.rb', line 150
def input_schema
@input_struct_class
end
|
.output(&block) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/dspy/signature.rb', line 113
def output(&block)
builder = StructBuilder.new
if block.arity > 0
block.call(builder)
else
builder.instance_eval(&block)
end
@output_field_descriptors = builder.field_descriptors
@output_struct_class = builder.build_struct_class
end
|
.output_json_schema ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/dspy/signature.rb', line 155
def output_json_schema
return {} unless @output_struct_class
properties = {}
required = []
@output_field_descriptors&.each do |name, descriptor|
schema = DSPy::TypeSystem::SorbetJsonSchema.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_json_schema_with_defs ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/dspy/signature.rb', line 179
def output_json_schema_with_defs
properties = {}
required = []
all_definitions = {}
@output_field_descriptors&.each do |name, descriptor|
result = DSPy::TypeSystem::SorbetJsonSchema.type_to_json_schema_with_defs(descriptor.type, nil, all_definitions)
schema = result.schema
schema[:description] = descriptor.description if descriptor.description
properties[name] = schema
required << name.to_s unless descriptor.has_default
end
final_schema = {
"$schema": "http://json-schema.org/draft-06/schema#",
type: "object",
properties: properties,
required: required
}
DSPy::TypeSystem::SorbetJsonSchema::SchemaResult.new(
schema: final_schema,
definitions: all_definitions
)
end
|
.output_schema ⇒ Object
206
207
208
|
# File 'lib/dspy/signature.rb', line 206
def output_schema
@output_struct_class
end
|