Class: RCrewAI::Tools::FileReader
- Defined in:
- lib/rcrewai/tools/file_reader.rb
Constant Summary
Constants included from RCrewAI::ToolSchema
Instance Method Summary collapse
- #execute(**params) ⇒ Object
-
#initialize(**options) ⇒ FileReader
constructor
A new instance of FileReader.
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) ⇒ FileReader
Returns a new instance of FileReader.
18 19 20 21 22 |
# File 'lib/rcrewai/tools/file_reader.rb', line 18 def initialize(**) super() @max_file_size = .fetch(:max_file_size, 10_000_000) # 10MB @allowed_extensions = .fetch(:allowed_extensions, %w[.txt .md .json .yaml .yml .csv .log]) end |
Instance Method Details
#execute(**params) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rcrewai/tools/file_reader.rb', line 24 def execute(**params) validate_params!(params, required: [:file_path], optional: %i[encoding lines]) file_path = params[:file_path] encoding = params[:encoding] || 'utf-8' lines = params[:lines] # Optional: read only N lines begin read_file(file_path, encoding, lines) rescue StandardError => e "File read failed: #{e.}" end end |