Class: Boxcars::ActiveRecord

Inherits:
EngineBoxcar show all
Defined in:
lib/boxcars/boxcar/active_record.rb

Overview

A Boxcar that interprets a prompt and executes SQL code to get answers rubocop:disable Metrics/ClassLength

Constant Summary collapse

ARDESC =

the description of this engine boxcar

"useful for when you need to query a database for an application named %<name>s."
LOCKED_OUT_MODELS =
%w[ActiveRecord::SchemaMigration ActiveRecord::InternalMetadata ApplicationRecord].freeze

Instance Attribute Summary collapse

Attributes inherited from EngineBoxcar

#engine, #prompt, #stop, #top_k

Attributes inherited from Boxcar

#description, #name, #parameters, #return_direct

Instance Method Summary collapse

Methods inherited from EngineBoxcar

#apply, #call, #check_output_keys, #extract_code, #generate, #input_key, #input_keys, #output_key, #output_keys, #predict, #prediction_input, #prediction_variables

Methods inherited from Boxcar

#apply, assi, #call, #conduct, hist, #input_keys, #load, #output_keys, #run, #save, #schema, syst, user, #validate_inputs, #validate_outputs

Constructor Details

#initialize(models: nil, except_models: nil, read_only: nil, approval_callback: nil, **kwargs) ⇒ ActiveRecord

Returns a new instance of ActiveRecord.

Parameters:

  • models (Array<ActiveRecord::Model>) (defaults to: nil)

    The models to use for this boxcar. Will use all if nil.

  • except_models (Array<ActiveRecord::Model>) (defaults to: nil)

    The models to exclude from this boxcar. Will exclude none if nil.

  • read_only (Boolean) (defaults to: nil)

    Whether to use read only models. Defaults to true unless you pass an approval function.

  • approval_callback (Proc) (defaults to: nil)

    A function to call to approve changes. Defaults to nil.

  • kwargs (Hash)

    Any other keyword arguments. These can include: :name, :description, :prompt, :except_models, :top_k, :stop, :code_only and :engine



20
21
22
23
24
25
26
27
28
29
# File 'lib/boxcars/boxcar/active_record.rb', line 20

def initialize(models: nil, except_models: nil, read_only: nil, approval_callback: nil, **kwargs)
  check_models(models, except_models)
  @approval_callback = approval_callback
  @read_only = read_only.nil? ? !approval_callback : read_only
  @code_only = kwargs.delete(:code_only) || false
  kwargs[:name] ||= get_name
  kwargs[:description] ||= format(ARDESC, name: name)
  kwargs[:prompt] ||= my_prompt
  super(**kwargs)
end

Instance Attribute Details

#approval_callbackObject

Returns the value of attribute approval_callback.



11
12
13
# File 'lib/boxcars/boxcar/active_record.rb', line 11

def approval_callback
  @approval_callback
end

#code_onlyObject

Returns the value of attribute code_only.



11
12
13
# File 'lib/boxcars/boxcar/active_record.rb', line 11

def code_only
  @code_only
end

#connectionObject

Returns the value of attribute connection.



11
12
13
# File 'lib/boxcars/boxcar/active_record.rb', line 11

def connection
  @connection
end

#except_modelsObject (readonly)

Returns the value of attribute except_models.



12
13
14
# File 'lib/boxcars/boxcar/active_record.rb', line 12

def except_models
  @except_models
end

#read_onlyObject

Returns the value of attribute read_only.



11
12
13
# File 'lib/boxcars/boxcar/active_record.rb', line 11

def read_only
  @read_only
end

#requested_modelsObject

Returns the value of attribute requested_models.



11
12
13
# File 'lib/boxcars/boxcar/active_record.rb', line 11

def requested_models
  @requested_models
end

Instance Method Details

#prediction_additional(_inputs) ⇒ Object

Returns Hash The additional variables for this boxcar.

Returns:

  • Hash The additional variables for this boxcar.



32
33
34
# File 'lib/boxcars/boxcar/active_record.rb', line 32

def prediction_additional(_inputs)
  { model_info: model_info }.merge super
end