JoaoPito / ayanami-bot

Your AI-powered assistant that customizes itself to automate your tasks, conveniently in a Telegram bot
GNU General Public License v3.0
0 stars 0 forks source link

Issue: FileSystemToolkit cannot move file to new subdirectory or create a new directory #15

Open JoaoPito opened 4 months ago

JoaoPito commented 4 months ago

If you have existing files inside a directory and want to move them to subdirectories FileSystemToolkit returns an error when using the move tool: Error: [Errno 2] No such file or directory . Looking inside the implementation for the move tool we can see that it does not check if destination folder exists and don't try to create subfolders as needed:

.venv/lib64/python3.12/site-packages/langchain_community/tools/file_management/move.py (line 49):

        try:
            # shutil.move expects str args in 3.8
            shutil.move(str(source_path_), destination_path_)
            return f"File moved successfully from {source_path} to {destination_path}."
        except Exception as e:
            return "Error: " + str(e)

The same happens for copy.py, but write.py (tool to create a new file) creates subdirectories.

This is useful for when trying to reorganize files that already exists inside a parent directory into one or more subdirectories.

A solution to that would be to check if destination directory exists before trying to move the file, and if it doesn't exist create subdirectories. But for that we need to create a new toolkit based on the official LangChain implementation.