Class: Boxcars::ZeroShot

Inherits:
Train show all
Defined in:
lib/boxcars/train/zero_shot.rb

Overview

A Train using the zero-shot react method.

Instance Attribute Summary collapse

Attributes inherited from Train

#answer_prefix, #early_stopping_method, #engine_prefix, #final_answer_prefix, #max_iterations, #name_to_boxcar_map, #question_prefix, #return_intermediate_steps, #return_values, #thought_prefix, #using_xml

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 Train

#boxcar_descriptions, #boxcar_names, #call, #construct_scratchpad, #finish_boxcar_name, #get_boxcar_result, #get_next_action, #init_prefixes, #input_keys, #key_and_value_text, #next_actions, #observation_text, #output_keys, #plan, #pre_return, #prepare_for_new_call, #question_text, #return_stopped_response, #should_continue?, #validate_prompt

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(boxcars:, engine: nil, name: 'Zero Shot', description: 'Zero Shot Train', prompt: nil, **kwargs) ⇒ ZeroShot

Returns a new instance of ZeroShot.

Parameters:

  • boxcars (Array<Boxcars::Boxcar>)

    The boxcars to run.

  • engine (Boxcars::Engine) (defaults to: nil)

    The engine to use for this train.

  • name (String) (defaults to: 'Zero Shot')

    The name of the train. Defaults to ‘Zero Shot’.

  • description (String) (defaults to: 'Zero Shot Train')

    The description of the train. Defaults to ‘Zero Shot Train’.

  • prompt (Boxcars::Prompt) (defaults to: nil)

    The prompt to use. Defaults to the built-in prompt.

  • kwargs (Hash)

    Additional arguments to pass to the train. wants_next_actions: true



16
17
18
19
20
# File 'lib/boxcars/train/zero_shot.rb', line 16

def initialize(boxcars:, engine: nil, name: 'Zero Shot', description: 'Zero Shot Train', prompt: nil, **kwargs)
  @wants_next_actions = kwargs.fetch(:wants_next_actions, false)
  prompt ||= my_prompt
  super(engine: engine, boxcars: boxcars, prompt: prompt, name: name, description: description, **kwargs)
end

Instance Attribute Details

#boxcarsObject (readonly)

Returns the value of attribute boxcars.



7
8
9
# File 'lib/boxcars/train/zero_shot.rb', line 7

def boxcars
  @boxcars
end

#observation_prefixObject (readonly)

Returns the value of attribute observation_prefix.



7
8
9
# File 'lib/boxcars/train/zero_shot.rb', line 7

def observation_prefix
  @observation_prefix
end

#wants_next_actionsObject

Returns the value of attribute wants_next_actions.



8
9
10
# File 'lib/boxcars/train/zero_shot.rb', line 8

def wants_next_actions
  @wants_next_actions
end

Instance Method Details

#extract_boxcar_and_input(text) ⇒ Array<Boxcars::Boxcar, String>

Extract the boxcar and input from the engine output.

Parameters:

  • text (String)

    The output from the engine.

Returns:



30
31
32
33
34
# File 'lib/boxcars/train/zero_shot.rb', line 30

def extract_boxcar_and_input(text)
  get_action_and_input(engine_output: text)
rescue StandardError => e
  [:error, e.message]
end

#prediction_additional(_inputs) ⇒ Object

Returns Hash The additional variables for this boxcar.

Returns:

  • Hash The additional variables for this boxcar.



23
24
25
# File 'lib/boxcars/train/zero_shot.rb', line 23

def prediction_additional(_inputs)
  { boxcar_names: boxcar_names, boxcar_descriptions: boxcar_descriptions, next_actions: next_actions }.merge super
end