Skip to content

Commit

Permalink
remove base_path from file actions (All-Hands-AI#320)
Browse files Browse the repository at this point in the history
* remove base_path from file actions

* unused imports
  • Loading branch information
rbren authored Mar 29, 2024
1 parent 7c27e59 commit 0322693
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
10 changes: 4 additions & 6 deletions opendevin/action/fileop.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def resolve_path(base_path, file_path):
@dataclass
class FileReadAction(ExecutableAction):
path: str
base_path: str = ""

def run(self, *args, **kwargs) -> FileReadObservation:
path = resolve_path(self.base_path, self.path)
def run(self, controller) -> FileReadObservation:
path = resolve_path(controller.workdir, self.path)
with open(path, 'r', encoding='utf-8') as file:
return FileReadObservation(
path=path,
Expand All @@ -35,10 +34,9 @@ def message(self) -> str:
class FileWriteAction(ExecutableAction):
path: str
contents: str
base_path: str = ""

def run(self, *args, **kwargs) -> FileWriteObservation:
path = resolve_path(self.base_path, self.path)
def run(self, controller) -> FileWriteObservation:
path = resolve_path(controller.workdir, self.path)
with open(path, 'w', encoding='utf-8') as file:
file.write(self.contents)
return FileWriteObservation(content="", path=self.path)
Expand Down
9 changes: 1 addition & 8 deletions opendevin/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from opendevin.action import (
Action,
NullAction,
FileReadAction,
FileWriteAction,
AgentFinishAction,
)
from opendevin.observation import (
Expand Down Expand Up @@ -97,12 +95,7 @@ async def step(self, i: int):
if isinstance(action, AgentFinishAction):
print_with_indent("\nFINISHED")
return True
if isinstance(action, (FileReadAction, FileWriteAction)):
action_cls = action.__class__
_kwargs = action.__dict__
_kwargs["base_path"] = self.workdir
action = action_cls(**_kwargs)
print(action, flush=True)

if action.executable:
try:
observation = action.run(self)
Expand Down

0 comments on commit 0322693

Please sign in to comment.