Class: Langchain::Tool::FileSystem
Overview
A tool that wraps the Ruby file system classes.
Usage:
file_system = Langchain::Tool::FileSystem.new
Instance Method Summary
collapse
define_function, extended, function_schemas, tool_name
Instance Method Details
permalink
#list_directory(directory_path:) ⇒ Object
[View source]
26
27
28
29
30
|
# File 'lib/langchain/tool/file_system.rb', line 26
def list_directory(directory_path:)
tool_response(content: Dir.entries(directory_path))
rescue Errno::ENOENT
tool_response(content: "No such directory: #{directory_path}")
end
|
permalink
#read_file(file_path:) ⇒ Object
[View source]
32
33
34
35
36
|
# File 'lib/langchain/tool/file_system.rb', line 32
def read_file(file_path:)
tool_response(content: File.read(file_path))
rescue Errno::ENOENT
tool_response(content: "No such file: #{file_path}")
end
|
permalink
#write_to_file(file_path:, content:) ⇒ Object
[View source]
38
39
40
41
42
43
|
# File 'lib/langchain/tool/file_system.rb', line 38
def write_to_file(file_path:, content:)
File.write(file_path, content)
tool_response(content: "File written successfully")
rescue Errno::EACCES
tool_response(content: "Permission denied: #{file_path}")
end
|