Class: ActiveCortex::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cortex/generator.rb

Direct Known Subclasses

Boolean, HasMany, Text

Defined Under Namespace

Classes: Boolean, HasMany, Text

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record:, field_name:, prompt:, max_results:, model:) ⇒ Generator

Returns a new instance of Generator.

Raises:

  • (ArgumentError)


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_nameObject (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_resultsObject (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

#modelObject (readonly)

Returns the value of attribute model.



13
14
15
# File 'lib/active_cortex/generator.rb', line 13

def model
  @model
end

#recordObject (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

.generateObject

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

#generationObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/active_cortex/generator.rb', line 26

def generation
  raise NotImplementedError
end

#save_generationObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/active_cortex/generator.rb', line 30

def save_generation
  raise NotImplementedError
end