Class: RCrewAI::Tools::PdfProcessor
- Defined in:
- lib/rcrewai/tools/pdf_processor.rb
Constant Summary
Constants included from RCrewAI::ToolSchema
Instance Method Summary collapse
- #execute(**params) ⇒ Object
-
#initialize(**options) ⇒ PdfProcessor
constructor
A new instance of PdfProcessor.
Methods inherited from Base
available_tools, create_tool, #description, #execute_with_validation, #json_schema, list_available_tools, #name, #validate_params!
Methods included from RCrewAI::ToolSchema
#description, extended, #json_schema, #param, #params, #tool_name
Constructor Details
#initialize(**options) ⇒ PdfProcessor
Returns a new instance of PdfProcessor.
22 23 24 25 26 27 28 |
# File 'lib/rcrewai/tools/pdf_processor.rb', line 22 def initialize(**) super() @max_file_size = .fetch(:max_file_size, 50_000_000) # 50MB @max_pages = .fetch(:max_pages, 100) @extract_metadata = .fetch(:extract_metadata, true) @working_directory = [:working_directory] || Dir.pwd end |
Instance Method Details
#execute(**params) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rcrewai/tools/pdf_processor.rb', line 30 def execute(**params) validate_params!( params, required: [:file_path], optional: %i[pages extract_text extract_metadata output_format] ) file_path = params[:file_path] pages = params[:pages] # Can be array [1,2,3] or range "1-5" or "all" extract_text = params.fetch(:extract_text, true) = params.fetch(:extract_metadata, @extract_metadata) output_format = params.fetch(:output_format, 'text') # 'text', 'json', 'markdown' begin validate_pdf_file!(file_path) result = process_pdf(file_path, pages, extract_text, ) format_pdf_result(result, output_format) rescue StandardError => e "PDF processing failed: #{e.}" end end |