Class: ActAsAgent::Tools::ReadFile

Inherits:
Object
  • Object
show all
Defined in:
lib/act_as_agent/tools/read_file.rb

Constant Summary collapse

ERROR =
ActAsAgent::Errors::ToolIncorrectArgsError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path: nil) ⇒ ReadFile

Returns a new instance of ReadFile.



12
13
14
# File 'lib/act_as_agent/tools/read_file.rb', line 12

def initialize(file_path: nil)
  @file_path = file_path
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



10
11
12
# File 'lib/act_as_agent/tools/read_file.rb', line 10

def file_path
  @file_path
end

Instance Method Details

#call(args = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/act_as_agent/tools/read_file.rb', line 35

def call(args = {})
  path = args.fetch("file_path", nil)

  return File.read(path) unless path.nil? || path.chomp == ""
  return File.read(file_path) unless file_path.nil?

  ERROR.new("Incorrect params have been given to list files tool")
end

#descriptionObject



20
21
22
# File 'lib/act_as_agent/tools/read_file.rb', line 20

def description
  "Read file by the given path"
end

#input_schemaObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/act_as_agent/tools/read_file.rb', line 24

def input_schema
  {
    type: "object",
    properties: {
      file_path: { type: "string",
                   description: "File path to read" }
    },
    required: []
  }
end

#nameObject



16
17
18
# File 'lib/act_as_agent/tools/read_file.rb', line 16

def name
  self.class.to_s.gsub("::", "__")
end