mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
fix file write observations (#225)
* fix file write observations * empty content for file write
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user