mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
from dataclasses import dataclass
|
|
|
|
from openhands.core.schema import ObservationType
|
|
from openhands.events.observation.observation import Observation
|
|
|
|
|
|
@dataclass
|
|
class CmdOutputObservation(Observation):
|
|
"""This data class represents the output of a command."""
|
|
|
|
command_id: int
|
|
command: str
|
|
exit_code: int = 0
|
|
hidden: bool = False
|
|
observation: str = ObservationType.RUN
|
|
interpreter_details: str = ''
|
|
|
|
@property
|
|
def error(self) -> bool:
|
|
return self.exit_code != 0
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return f'Command `{self.command}` executed with exit code {self.exit_code}.'
|
|
|
|
@property
|
|
def success(self) -> bool:
|
|
return not self.error
|
|
|
|
def __str__(self) -> str:
|
|
return f'**CmdOutputObservation (source={self.source}, exit code={self.exit_code})**\n{self.content}'
|
|
|
|
|
|
@dataclass
|
|
class IPythonRunCellObservation(Observation):
|
|
"""This data class represents the output of a IPythonRunCellAction."""
|
|
|
|
code: str
|
|
observation: str = ObservationType.RUN_IPYTHON
|
|
|
|
@property
|
|
def error(self) -> bool:
|
|
return False # IPython cells do not return exit codes
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return 'Code executed in IPython cell.'
|
|
|
|
@property
|
|
def success(self) -> bool:
|
|
return True # IPython cells are always considered successful
|
|
|
|
def __str__(self) -> str:
|
|
return f'**IPythonRunCellObservation**\n{self.content}'
|