fix file write observations (#225)

* fix file write observations

* empty content for file write
This commit is contained in:
Robert Brennan
2024-03-27 01:07:14 -04:00
committed by GitHub
parent 95c128c3d6
commit ea10809a96
2 changed files with 14 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
import os
from dataclasses import dataclass
from opendevin.observation import Observation, FileReadObservation
from opendevin.observation import FileReadObservation, FileWriteObservation
from .base import ExecutableAction
# This is the path where the workspace is mounted in the container
@@ -37,11 +37,11 @@ class FileWriteAction(ExecutableAction):
contents: str
base_path: str = ""
def run(self, *args, **kwargs) -> Observation:
def run(self, *args, **kwargs) -> FileWriteObservation:
path = resolve_path(self.base_path, self.path)
with open(path, 'w', encoding='utf-8') as file:
file.write(self.contents)
return Observation(f"File written to {path}")
return FileWriteObservation(content="", path=self.path)
@property
def message(self) -> str:

View File

@@ -61,6 +61,17 @@ class FileReadObservation(Observation):
def message(self) -> str:
return f"I read the file {self.path}."
@dataclass
class FileWriteObservation(Observation):
"""
This data class represents a file write operation
"""
path: str
@property
def message(self) -> str:
return f"I wrote to the file {self.path}."
@dataclass
class BrowserOutputObservation(Observation):