Class: Langchain::Tool::RubyCodeInterpreter
- Inherits:
-
Object
- Object
- Langchain::Tool::RubyCodeInterpreter
- Extended by:
- Langchain::ToolDefinition
- Includes:
- DependencyHelper
- Defined in:
- lib/langchain/tool/ruby_code_interpreter.rb
Overview
Instance Method Summary collapse
-
#execute(input:) ⇒ String
Executes Ruby code in a sandboxes environment.
-
#initialize(timeout: 30) ⇒ RubyCodeInterpreter
constructor
A new instance of RubyCodeInterpreter.
- #safe_eval(code) ⇒ Object
Methods included from Langchain::ToolDefinition
define_function, function_schemas, tool_name
Methods included from DependencyHelper
Constructor Details
#initialize(timeout: 30) ⇒ RubyCodeInterpreter
Returns a new instance of RubyCodeInterpreter.
21 22 23 24 25 |
# File 'lib/langchain/tool/ruby_code_interpreter.rb', line 21 def initialize(timeout: 30) depends_on "safe_ruby" @timeout = timeout end |
Instance Method Details
#execute(input:) ⇒ String
Executes Ruby code in a sandboxes environment.
31 32 33 34 35 |
# File 'lib/langchain/tool/ruby_code_interpreter.rb', line 31 def execute(input:) Langchain.logger.debug("#{self.class} - Executing \"#{input}\"") safe_eval(input) end |
#safe_eval(code) ⇒ Object
37 38 39 |
# File 'lib/langchain/tool/ruby_code_interpreter.rb', line 37 def safe_eval(code) SafeRuby.eval(code, timeout: @timeout) end |