Class: OxAiWorkers::Tool::Eval
- Inherits:
-
Object
- Object
- OxAiWorkers::Tool::Eval
- Includes:
- DependencyHelper, LoadI18n, OxAiWorkers::ToolDefinition
- Defined in:
- lib/oxaiworkers/tool/eval.rb
Instance Attribute Summary
Attributes included from LoadI18n
Attributes included from OxAiWorkers::ToolDefinition
Instance Method Summary collapse
-
#initialize(only: nil) ⇒ Eval
constructor
A new instance of Eval.
- #ruby(input:) ⇒ Object
- #sh(input:) ⇒ Object
Methods included from LoadI18n
Methods included from DependencyHelper
Methods included from OxAiWorkers::ToolDefinition
#define_function, #full_function_name, #function_schemas, #init_white_list_with, #tool_name
Constructor Details
#initialize(only: nil) ⇒ Eval
Returns a new instance of Eval.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/oxaiworkers/tool/eval.rb', line 12 def initialize(only: nil) store_locale init_white_list_with only define_function :ruby, description: I18n.t('oxaiworkers.tool.eval.ruby.description') do property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.ruby.input'), required: true end define_function :sh, description: I18n.t('oxaiworkers.tool.eval.sh.description') do property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.sh.input'), required: true end end |
Instance Method Details
#ruby(input:) ⇒ Object
26 27 28 29 |
# File 'lib/oxaiworkers/tool/eval.rb', line 26 def ruby(input:) OxAiWorkers.logger.info("Executing ruby: \"#{input}\"", for: self.class) eval(input) end |
#sh(input:) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oxaiworkers/tool/eval.rb', line 31 def sh(input:) OxAiWorkers.logger.info("Executing sh: \"#{input}\"", for: self.class) begin stdout_and_stderr_s, status = Open3.capture2e(input) return stdout_and_stderr_s if stdout_and_stderr_s.present? status.to_s rescue StandardError => e OxAiWorkers.logger.debug(e., for: self.class) e. end end |