Class: Langchain::Tool::Calculator
- Inherits:
-
Object
- Object
- Langchain::Tool::Calculator
- Extended by:
- Langchain::ToolDefinition
- Includes:
- DependencyHelper
- Defined in:
- lib/langchain/tool/calculator.rb
Overview
Instance Method Summary collapse
-
#execute(input:) ⇒ String
Evaluates a pure math expression or if equation contains non-math characters (e.g.: “12F in Celsius”) then it uses the google search calculator to evaluate the expression.
-
#initialize ⇒ Calculator
constructor
A new instance of Calculator.
Methods included from Langchain::ToolDefinition
define_function, function_schemas, tool_name
Methods included from DependencyHelper
Constructor Details
#initialize ⇒ Calculator
Returns a new instance of Calculator.
22 23 24 |
# File 'lib/langchain/tool/calculator.rb', line 22 def initialize depends_on "eqn" end |
Instance Method Details
#execute(input:) ⇒ String
Evaluates a pure math expression or if equation contains non-math characters (e.g.: “12F in Celsius”) then it uses the google search calculator to evaluate the expression
30 31 32 33 34 35 36 |
# File 'lib/langchain/tool/calculator.rb', line 30 def execute(input:) Langchain.logger.debug("#{self.class} - Executing \"#{input}\"") Eqn::Calculator.calc(input) rescue Eqn::ParseError, Eqn::NoVariableValueError "\"#{input}\" is an invalid mathematical expression" end |