Class: ActiveCortex::Generator
- Inherits:
-
Object
- Object
- ActiveCortex::Generator
- Defined in:
- lib/active_cortex/generator.rb
Defined Under Namespace
Classes: Boolean, HasMany, Text
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#max_results ⇒ Object
readonly
Returns the value of attribute max_results.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Class Method Summary collapse
-
.generate ⇒ Object
This is a factory method that returns an instance of a subclass of ActiveCortex::Generator.
Instance Method Summary collapse
- #generation ⇒ Object
-
#initialize(record:, field_name:, prompt:, max_results:, model:) ⇒ Generator
constructor
A new instance of Generator.
- #save_generation ⇒ Object
Constructor Details
#initialize(record:, field_name:, prompt:, max_results:, model:) ⇒ Generator
Returns a new instance of Generator.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_cortex/generator.rb', line 15 def initialize(record:, field_name:, prompt:, max_results:, model:) @record = record @field_name = field_name @prompt = prompt @max_results = max_results @model = model raise ArgumentError, "Invalid model provided must be " \ "e.g. 'gpt-3.5-turbo', was #{model.inspect}" unless valid_model? end |
Instance Attribute Details
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
13 14 15 |
# File 'lib/active_cortex/generator.rb', line 13 def field_name @field_name end |
#max_results ⇒ Object (readonly)
Returns the value of attribute max_results.
13 14 15 |
# File 'lib/active_cortex/generator.rb', line 13 def max_results @max_results end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
13 14 15 |
# File 'lib/active_cortex/generator.rb', line 13 def model @model end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
13 14 15 |
# File 'lib/active_cortex/generator.rb', line 13 def record @record end |
Class Method Details
.generate ⇒ Object
This is a factory method that returns an instance of a subclass of ActiveCortex::Generator. The subclass is chosen based on the type of the field that is being generated: text or has_many.
The subclass is responsible for generating the result and saving it to the database.
9 10 11 |
# File 'lib/active_cortex/generator.rb', line 9 def self.generate(**) find_generator_class(**).new(**).save_generation end |
Instance Method Details
#generation ⇒ Object
26 27 28 |
# File 'lib/active_cortex/generator.rb', line 26 def generation raise NotImplementedError end |
#save_generation ⇒ Object
30 31 32 |
# File 'lib/active_cortex/generator.rb', line 30 def save_generation raise NotImplementedError end |