Fix all commands and cleanup

This commit is contained in:
BillSchumacher
2023-04-19 18:17:04 -05:00
parent 23c650ca10
commit d7679d755f
16 changed files with 63 additions and 83 deletions

View File

@@ -9,11 +9,13 @@ import requests
from colorama import Back, Fore
from requests.adapters import HTTPAdapter, Retry
from autogpt.config import Config
from autogpt.commands.command import command
from autogpt.spinner import Spinner
from autogpt.utils import readable_file_size
from autogpt.workspace import WORKSPACE_PATH, path_in_workspace
CFG = Config()
LOG_FILE = "file_logger.txt"
LOG_FILE_PATH = WORKSPACE_PATH / LOG_FILE
@@ -82,7 +84,7 @@ def split_file(
start += max_length - overlap
@command("read_file", "Read file", '"file": "<file>"')
@command("read_file", "Read file", '"filename": "<filename>"')
def read_file(filename: str) -> str:
"""Read a file and return the contents
@@ -135,7 +137,7 @@ def ingest_file(
print(f"Error while ingesting file '{filename}': {str(e)}")
@command("write_to_file", "Write to file", '"file": "<file>", "text": "<text>"')
@command("write_to_file", "Write to file", '"filename": "<filename>", "text": "<text>"')
def write_to_file(filename: str, text: str) -> str:
"""Write text to a file
@@ -161,7 +163,7 @@ def write_to_file(filename: str, text: str) -> str:
return f"Error: {str(e)}"
@command("append_to_file", "Append to file", '"file": "<file>", "text": "<text>"')
@command("append_to_file", "Append to file", '"filename": "<filename>", "text": "<text>"')
def append_to_file(filename: str, text: str, shouldLog: bool = True) -> str:
"""Append text to a file
@@ -185,7 +187,7 @@ def append_to_file(filename: str, text: str, shouldLog: bool = True) -> str:
return f"Error: {str(e)}"
@command("delete_file", "Delete file", '"file": "<file>"')
@command("delete_file", "Delete file", '"filename": "<filename>"')
def delete_file(filename: str) -> str:
"""Delete a file
@@ -233,6 +235,8 @@ def search_files(directory: str) -> list[str]:
return found_files
@command("download_file", "Search Files", '"url": "<url>", "filename": "<filename>"', CFG.allow_downloads, "Error: You do not have user authorization to download files locally.")
def download_file(url, filename):
"""Downloads a file
Args: