Class: Langchain::Tool::FileSystem
- Defined in:
- lib/langchain/tool/file_system/file_system.rb
Constant Summary collapse
- NAME =
A tool that wraps the Ruby file system classes.
Usage:
file_system = Langchain::Tool::FileSystem.new
"file_system"
- ANNOTATIONS_PATH =
Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
Instance Method Summary collapse
- #list_directory(directory_path:) ⇒ Object
- #read_file(file_path:) ⇒ Object
- #write_to_file(file_path:, content:) ⇒ Object
Methods inherited from Base
logger_options, #method_annotations, #name, #to_openai_tools
Methods included from DependencyHelper
Instance Method Details
#list_directory(directory_path:) ⇒ Object
14 15 16 17 18 |
# File 'lib/langchain/tool/file_system/file_system.rb', line 14 def list_directory(directory_path:) Dir.entries(directory_path) rescue Errno::ENOENT "No such directory: #{directory_path}" end |
#read_file(file_path:) ⇒ Object
20 21 22 23 24 |
# File 'lib/langchain/tool/file_system/file_system.rb', line 20 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
26 27 28 29 30 |
# File 'lib/langchain/tool/file_system/file_system.rb', line 26 def write_to_file(file_path:, content:) File.write(file_path, content) rescue Errno::EACCES "Permission denied: #{file_path}" end |