mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-08 08:44:23 +01:00
Remove delete file
Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ if TYPE_CHECKING:
|
||||
from autogpt.llm.base import ChatModelResponse, ChatSequence, Message
|
||||
from autogpt.llm.providers.openai import OPEN_AI_CHAT_MODELS, get_openai_command_specs
|
||||
from autogpt.llm.utils import count_message_tokens, create_chat_completion
|
||||
from autogpt.logs import logger
|
||||
from autogpt.logs import CURRENT_CONTEXT_FILE_NAME, logger
|
||||
from autogpt.memory.message_history import MessageHistory
|
||||
from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT
|
||||
|
||||
@@ -105,7 +105,13 @@ class BaseAgent(metaclass=ABCMeta):
|
||||
|
||||
prompt: ChatSequence = self.construct_prompt(instruction)
|
||||
prompt = self.on_before_think(prompt, instruction)
|
||||
|
||||
self.log_cycle_handler.log_cycle(
|
||||
self.ai_config.ai_name,
|
||||
self.created_at,
|
||||
self.cycle_count,
|
||||
prompt.raw(),
|
||||
CURRENT_CONTEXT_FILE_NAME,
|
||||
)
|
||||
raw_response = create_chat_completion(
|
||||
prompt,
|
||||
self.config,
|
||||
|
||||
@@ -274,37 +274,6 @@ def append_to_file(
|
||||
return f"Error: {err}"
|
||||
|
||||
|
||||
@command(
|
||||
"delete_file",
|
||||
"Deletes a file",
|
||||
{
|
||||
"filename": {
|
||||
"type": "string",
|
||||
"description": "The name of the file to delete",
|
||||
"required": True,
|
||||
}
|
||||
},
|
||||
)
|
||||
@sanitize_path_arg("filename")
|
||||
def delete_file(filename: str, agent: Agent) -> str:
|
||||
"""Delete a file
|
||||
|
||||
Args:
|
||||
filename (str): The name of the file to delete
|
||||
|
||||
Returns:
|
||||
str: A message indicating success or failure
|
||||
"""
|
||||
if is_duplicate_operation("delete", filename, agent):
|
||||
return "Error: File has already been deleted."
|
||||
try:
|
||||
os.remove(filename)
|
||||
log_operation("delete", filename, agent)
|
||||
return "File deleted successfully."
|
||||
except Exception as err:
|
||||
return f"Error: {err}"
|
||||
|
||||
|
||||
@command(
|
||||
"list_files",
|
||||
"Lists Files in a Directory",
|
||||
|
||||
@@ -17,7 +17,6 @@ ABILITIES = (
|
||||
'analyze_code: Analyze Code, args: "code": "<full_code_string>"',
|
||||
'execute_python_file: Execute Python File, args: "filename": "<filename>"',
|
||||
'append_to_file: Append to file, args: "filename": "<filename>", "text": "<text>"',
|
||||
'delete_file: Delete file, args: "filename": "<filename>"',
|
||||
'list_files: List Files in Directory, args: "directory": "<directory>"',
|
||||
'read_file: Read a file, args: "filename": "<filename>"',
|
||||
'write_to_file: Write to file, args: "filename": "<filename>", "text": "<text>"',
|
||||
|
||||
@@ -282,24 +282,6 @@ def test_append_to_file_uses_checksum_from_appended_file(
|
||||
)
|
||||
|
||||
|
||||
def test_delete_file(test_file_with_content_path: Path, agent: Agent):
|
||||
result = file_ops.delete_file(str(test_file_with_content_path), agent=agent)
|
||||
assert result == "File deleted successfully."
|
||||
assert os.path.exists(test_file_with_content_path) is False
|
||||
|
||||
|
||||
def test_delete_missing_file(agent: Agent):
|
||||
filename = "path/to/file/which/does/not/exist"
|
||||
# confuse the log
|
||||
file_ops.log_operation("write", filename, agent=agent, checksum="fake")
|
||||
try:
|
||||
os.remove(agent.workspace.get_path(filename))
|
||||
except FileNotFoundError as err:
|
||||
assert str(err) in file_ops.delete_file(filename, agent=agent)
|
||||
return
|
||||
assert False, f"Failed to test delete_file; {filename} not expected to exist"
|
||||
|
||||
|
||||
def test_list_files(workspace: Workspace, test_directory: Path, agent: Agent):
|
||||
# Case 1: Create files A and B, search for A, and ensure we don't return A and B
|
||||
file_a = workspace.get_path("file_a.txt")
|
||||
|
||||
Reference in New Issue
Block a user