Class: SharedTools::Tools::EvalTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::EvalTool
- Defined in:
- lib/shared_tools/tools/eval_tool.rb
Overview
A tool for evaluating code in different programming languages
Defined Under Namespace
Modules: Action
Constant Summary collapse
- ACTIONS =
[ Action::RUBY, Action::PYTHON, Action::SHELL, ].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(action:, code: nil, command: nil) ⇒ Hash, String
Execution result.
-
#initialize(logger: nil) ⇒ EvalTool
constructor
A new instance of EvalTool.
Constructor Details
#initialize(logger: nil) ⇒ EvalTool
Returns a new instance of EvalTool.
82 83 84 |
# File 'lib/shared_tools/tools/eval_tool.rb', line 82 def initialize(logger: nil) @logger = logger || RubyLLM.logger end |
Class Method Details
.name ⇒ Object
9 |
# File 'lib/shared_tools/tools/eval_tool.rb', line 9 def self.name = 'eval_tool' |
Instance Method Details
#execute(action:, code: nil, command: nil) ⇒ Hash, String
Returns execution result.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/shared_tools/tools/eval_tool.rb', line 91 def execute(action:, code: nil, command: nil) @logger.info("EvalTool#execute action=#{action}") case action.to_s.downcase when Action::RUBY require_param!(:code, code) ruby_eval_tool.execute(code: code) when Action::PYTHON require_param!(:code, code) python_eval_tool.execute(code: code) when Action::SHELL require_param!(:command, command) shell_eval_tool.execute(command: command) else { error: "Unsupported action: #{action}. Supported actions are: #{ACTIONS.join(', ')}" } end rescue StandardError => e @logger.error("EvalTool execution failed: #{e.message}") { error: e. } end |