Переглянути джерело

fix file write observations (#225)

* fix file write observations

* empty content for file write
Robert Brennan 2 роки тому
батько
коміт
ea10809a96
2 змінених файлів з 14 додано та 3 видалено
  1. 3 3
      opendevin/action/fileop.py
  2. 11 0
      opendevin/observation.py

+ 3 - 3
opendevin/action/fileop.py

@@ -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:

+ 11 - 0
opendevin/observation.py

@@ -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):