mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-11 02:04:24 +01:00
Enable open_file and open_folder
This commit is contained in:
@@ -23,7 +23,7 @@ from autogpt.models.context_item import FileContextItem, FolderContextItem
|
||||
from .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 None
|
||||
|
||||
created = False
|
||||
if 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 None
|
||||
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"open_folder {path} failed: no such file or directory")
|
||||
|
||||
@@ -19,6 +19,7 @@ from autogpt.command_decorator import command
|
||||
from autogpt.memory.vector import MemoryItem, VectorMemory
|
||||
|
||||
from .decorators import sanitize_path_arg
|
||||
from .file_context import open_file, open_folder # NOQA
|
||||
from .file_operations_utils import read_textual_file
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@@ -5,6 +6,8 @@ from typing import Optional
|
||||
|
||||
from autogpt.commands.file_operations_utils import read_textual_file
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ContextItem(ABC):
|
||||
@property
|
||||
@@ -48,7 +51,7 @@ class FileContextItem(ContextItem):
|
||||
|
||||
@property
|
||||
def content(self) -> str:
|
||||
return read_textual_file(self.file_path)
|
||||
return read_textual_file(self.file_path, logger)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user