Class: Boxcars::Calculator
- Inherits:
-
EngineBoxcar
- Object
- Boxcar
- EngineBoxcar
- Boxcars::Calculator
- Defined in:
- lib/boxcars/boxcar/calculator.rb
Overview
A Boxcar that interprets a prompt and executes Ruby code to do math.
Constant Summary collapse
- CALCDESC =
Default description for this boxcar.
"useful for when you need to answer questions about math"- CTEMPLATE =
Prompt template used by this boxcar.
[ syst("You can do basic math, but for any hard calculations that a human could not do ", "in their head, use the following approach instead. ", "Return code written in the Ruby programming language that prints the results to the console. ", "If anyone gives you a hard math problem, just ", "use the following format and we’ll take care of the rest:\n", "${{Question with hard calculation.}}\n", "reply only with the following format:\n", "```ruby\n${{only Ruby code that prints the answer. " \ "If you use puts, make sure to wrap the expression in parentheses}}\n```\n", "```output\n${{Output of your code}}\n```\n\n", "Otherwise, you should use this simpler format:\n", "${{Question without hard calculation}}\n", "Answer: ${{Answer}}\n\n", "Do not give an explanation of the answer and make sure your answer starts with either 'Answer:' or '```ruby'."), syst("here is a hard example:\n", "the user asks: What is 37593 * 67?\n", "your answer: ```ruby\nputs(37593 * 67)\n```\n```output\n2518731\n```\nAnswer: 2518731"), syst("basic example:\n", "user asks: What is 2518731 + 0?\n", "you answer: Answer: 2518731"), syst("Begin."), user("%<question>s") ].freeze
Constants inherited from Boxcar
Boxcar::SCHEMA_KEY_ALIASES, Boxcar::TYPE_ALIASES
Instance Attribute Summary
Attributes inherited from EngineBoxcar
#engine, #prompt, #stop, #top_k
Attributes inherited from Boxcar
#description, #name, #parameters, #return_direct
Instance Method Summary collapse
-
#initialize(engine: nil, prompt: nil, **kwargs) ⇒ Calculator
constructor
A new instance of Calculator.
Methods inherited from EngineBoxcar
#apply, #call, #extract_code, #generate, #input_keys, #output_key, #output_keys, #predict, #prediction_additional, #prediction_variables
Methods inherited from Boxcar
#apply, assi, #call, #conduct, #conduct_result, hist, #input_keys, #output_keys, #parameters_json_schema, #run, #run_result, #schema, syst, #tool_call_name, #tool_definition, #tool_spec, user, #validate_inputs, #validate_outputs
Constructor Details
#initialize(engine: nil, prompt: nil, **kwargs) ⇒ Calculator
Returns a new instance of Calculator.
13 14 15 16 17 18 19 |
# File 'lib/boxcars/boxcar/calculator.rb', line 13 def initialize(engine: nil, prompt: nil, **kwargs) the_prompt = prompt || my_prompt kwargs[:stop] ||= ["```output"] kwargs[:name] ||= "Calculator" kwargs[:description] ||= CALCDESC super(engine:, prompt: the_prompt, **kwargs) end |