Class: RLM::Signature::Dspy
- Inherits:
-
Object
- Object
- RLM::Signature::Dspy
- Defined in:
- lib/rlm/signature/dspy.rb
Constant Summary collapse
- TYPE_MAP =
{ "array" => :array, "boolean" => :boolean, "integer" => :integer, "number" => :number, "object" => :object, "string" => :string }.freeze
Instance Method Summary collapse
- #coerce_output(output) ⇒ Object
- #description ⇒ Object
-
#initialize(signature) ⇒ Dspy
constructor
A new instance of Dspy.
- #input_fields ⇒ Object
- #name ⇒ Object
- #output_fields ⇒ Object
- #validate_input(input) ⇒ Object
- #validate_output(output) ⇒ Object
Constructor Details
#initialize(signature) ⇒ Dspy
Returns a new instance of Dspy.
15 16 17 |
# File 'lib/rlm/signature/dspy.rb', line 15 def initialize(signature) @signature = signature end |
Instance Method Details
#coerce_output(output) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/rlm/signature/dspy.rb', line 47 def coerce_output(output) return output unless output.is_a?(Hash) schema_keys = output_fields.keys output.each_with_object({}) do |(key, value), coerced| coerced_key = schema_keys.find { |schema_key| schema_key.to_s == key.to_s } || key coerced[coerced_key] = value end end |
#description ⇒ Object
25 26 27 28 29 |
# File 'lib/rlm/signature/dspy.rb', line 25 def description return signature.description if signature.respond_to?(:description) name end |
#input_fields ⇒ Object
31 32 33 |
# File 'lib/rlm/signature/dspy.rb', line 31 def input_fields fields_for(input_schema) end |
#name ⇒ Object
19 20 21 22 23 |
# File 'lib/rlm/signature/dspy.rb', line 19 def name return signature.name if signature.respond_to?(:name) && !signature.name.to_s.empty? signature.to_s end |
#output_fields ⇒ Object
35 36 37 |
# File 'lib/rlm/signature/dspy.rb', line 35 def output_fields fields_for(output_schema) end |
#validate_input(input) ⇒ Object
39 40 41 |
# File 'lib/rlm/signature/dspy.rb', line 39 def validate_input(input) validate_payload(input, input_schema) end |
#validate_output(output) ⇒ Object
43 44 45 |
# File 'lib/rlm/signature/dspy.rb', line 43 def validate_output(output) validate_payload(output, output_schema) end |