Class: SharedTools::Tools::DocTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::DocTool
- Defined in:
- lib/shared_tools/tools/doc_tool.rb
Overview
A tool for reading and processing documents
Defined Under Namespace
Modules: Action
Constant Summary collapse
- ACTIONS =
[ Action::PDF_READ, Action::TEXT_READ, Action::DOCX_READ, Action::SPREADSHEET_READ, ].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(action:, doc_path: nil, page_numbers: nil, paragraph_range: nil, sheet: nil, row_range: nil, headers: true) ⇒ Hash
Execution result.
-
#initialize(logger: nil) ⇒ DocTool
constructor
A new instance of DocTool.
Constructor Details
Class Method Details
.name ⇒ Object
9 |
# File 'lib/shared_tools/tools/doc_tool.rb', line 9 def self.name = 'doc_tool' |
Instance Method Details
#execute(action:, doc_path: nil, page_numbers: nil, paragraph_range: nil, sheet: nil, row_range: nil, headers: true) ⇒ Hash
Returns execution result.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/shared_tools/tools/doc_tool.rb', line 147 def execute(action:, doc_path: nil, page_numbers: nil, paragraph_range: nil, sheet: nil, row_range: nil, headers: true) @logger.info("DocTool#execute action=#{action}") case action.to_s.downcase when Action::TEXT_READ require_param!(:doc_path, doc_path) text_reader_tool.execute(doc_path: doc_path) when Action::PDF_READ require_param!(:doc_path, doc_path) require_param!(:page_numbers, page_numbers) pdf_reader_tool.execute(doc_path: doc_path, page_numbers: page_numbers) when Action::DOCX_READ require_param!(:doc_path, doc_path) docx_reader_tool.execute(doc_path: doc_path, paragraph_range: paragraph_range) when Action::SPREADSHEET_READ require_param!(:doc_path, doc_path) spreadsheet_reader_tool.execute(doc_path: doc_path, sheet: sheet, row_range: row_range, headers: headers) else { error: "Unsupported action: #{action}. Supported actions are: #{ACTIONS.join(', ')}" } end rescue StandardError => e @logger.error("DocTool execution failed: #{e.}") { error: e. } end |