AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Enable `open_file` and `open_folder`
Reinier van der Leer2a8cc4816e7d
diff --git a/autogpt/commands/file_context.py b/autogpt/commands/file_context.pyindex bfcaba5eec..9a64539325 100644--- a/autogpt/commands/file_context.py+++ b/autogpt/commands/file_context.py@@ -23,7 +23,7 @@ from autogpt.models.context_item import FileContextItem, FolderContextItemfrom .decorators import sanitize_path_arg-def compatible_with_agent(agent: BaseAgent):+def compatible_with_agent(agent: BaseAgent) -> bool:return isinstance(agent, ContextMixin)@@ -54,10 +54,7 @@ def open_file(file_path: Path, agent: Agent) -> tuple[str, FileContextItem]:with contextlib.suppress(ValueError):file_path = file_path.relative_to(agent.workspace.root)- if (agent_context := get_agent_context(agent)) is None:- raise NotImplementedError(- f"{agent.__class__.__name__} does not implement context"- )+ assert (agent_context := get_agent_context(agent)) is not Nonecreated = Falseif not file_path.exists():@@ -103,10 +100,7 @@ def open_folder(path: Path, agent: Agent) -> tuple[str, FolderContextItem]:with contextlib.suppress(ValueError):path = path.relative_to(agent.workspace.root)- if (agent_context := get_agent_context(agent)) is None:- raise NotImplementedError(- f"{agent.__class__.__name__} does not implement context"- )+ assert (agent_context := get_agent_context(agent)) is not Noneif not path.exists():raise FileNotFoundError(f"open_folder {path} failed: no such file or directory")diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.pyindex e4280a3ca2..9e4faaabbf 100644--- a/autogpt/commands/file_operations.py+++ b/autogpt/commands/file_operations.py@@ -19,6 +19,7 @@ from autogpt.command_decorator import commandfrom autogpt.memory.vector import MemoryItem, VectorMemoryfrom .decorators import sanitize_path_arg+from .file_context import open_file, open_folder # NOQAfrom .file_operations_utils import read_textual_filelogger = logging.getLogger(__name__)diff --git a/autogpt/models/context_item.py b/autogpt/models/context_item.pyindex 6a626c64db..eec579f7ca 100644--- a/autogpt/models/context_item.py+++ b/autogpt/models/context_item.py@@ -1,3 +1,4 @@+import loggingfrom abc import ABC, abstractmethodfrom dataclasses import dataclassfrom pathlib import Path@@ -5,6 +6,8 @@ from typing import Optionalfrom autogpt.commands.file_operations_utils import read_textual_file+logger = logging.getLogger(__name__)+class ContextItem(ABC):@property@@ -48,7 +51,7 @@ class FileContextItem(ContextItem):@propertydef content(self) -> str:- return read_textual_file(self.file_path)+ return read_textual_file(self.file_path, logger)@dataclass