Class: Leva::SignatureGenerator
- Inherits:
-
Object
- Object
- Leva::SignatureGenerator
- Defined in:
- app/services/leva/signature_generator.rb
Overview
Generates DSPy signatures from Leva dataset records.
This service analyzes the structure of dataset records and generates a dynamic DSPy::Signature class that matches the input/output schema.
Instance Method Summary collapse
-
#generate ⇒ Class?
Generates a DSPy::Signature class based on the dataset structure.
-
#initialize(dataset, description: nil) ⇒ SignatureGenerator
constructor
A new instance of SignatureGenerator.
-
#input_field_names ⇒ Array<Symbol>
Returns the input field names that will be used in the signature.
Constructor Details
#initialize(dataset, description: nil) ⇒ SignatureGenerator
Returns a new instance of SignatureGenerator.
16 17 18 19 20 |
# File 'app/services/leva/signature_generator.rb', line 16 def initialize(dataset, description: nil) @dataset = dataset @description = description @sample_record = dataset.dataset_records.first&.recordable end |
Instance Method Details
#generate ⇒ Class?
Generates a DSPy::Signature class based on the dataset structure.
25 26 27 28 29 30 31 32 33 |
# File 'app/services/leva/signature_generator.rb', line 25 def generate return nil unless @sample_record input_fields = extract_input_fields output_type = infer_output_type(@sample_record.ground_truth) description = @description || generate_description build_signature_class(input_fields, output_type, description) end |
#input_field_names ⇒ Array<Symbol>
Returns the input field names that will be used in the signature.
38 39 40 41 42 |
# File 'app/services/leva/signature_generator.rb', line 38 def input_field_names return [] unless @sample_record extract_input_fields.keys end |