Class: Langchain::Tool::FileSystem

Inherits:
Object
  • Object
show all
Extended by:
Langchain::ToolDefinition
Defined in:
lib/langchain/tool/file_system.rb

Overview

A tool that wraps the Ruby file system classes.

Usage:

file_system = Langchain::Tool::FileSystem.new

Instance Method Summary collapse

Methods included from Langchain::ToolDefinition

define_function, function_schemas, tool_name

Instance Method Details

#list_directory(directory_path:) ⇒ Object



26
27
28
29
30
# File 'lib/langchain/tool/file_system.rb', line 26

def list_directory(directory_path:)
  Dir.entries(directory_path)
rescue Errno::ENOENT
  "No such directory: #{directory_path}"
end

#read_file(file_path:) ⇒ Object



32
33
34
35
36
# File 'lib/langchain/tool/file_system.rb', line 32

def read_file(file_path:)
  File.read(file_path)
rescue Errno::ENOENT
  "No such file: #{file_path}"
end

#write_to_file(file_path:, content:) ⇒ Object



38
39
40
41
42
# File 'lib/langchain/tool/file_system.rb', line 38

def write_to_file(file_path:, content:)
  File.write(file_path, content)
rescue Errno::EACCES
  "Permission denied: #{file_path}"
end