commands.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from dataclasses import dataclass
  2. from opendevin.core.schema import ObservationType
  3. from .observation import Observation
  4. @dataclass
  5. class CmdOutputObservation(Observation):
  6. """This data class represents the output of a command."""
  7. command_id: int
  8. command: str
  9. exit_code: int = 0
  10. observation: str = ObservationType.RUN
  11. @property
  12. def error(self) -> bool:
  13. return self.exit_code != 0
  14. @property
  15. def message(self) -> str:
  16. return f'Command `{self.command}` executed with exit code {self.exit_code}.'
  17. def __str__(self) -> str:
  18. return f'**CmdOutputObservation (source={self.source}, exit code={self.exit_code})**\n{self.content}'
  19. @dataclass
  20. class IPythonRunCellObservation(Observation):
  21. """This data class represents the output of a IPythonRunCellAction."""
  22. code: str
  23. observation: str = ObservationType.RUN_IPYTHON
  24. @property
  25. def error(self) -> bool:
  26. return False # IPython cells do not return exit codes
  27. @property
  28. def message(self) -> str:
  29. return 'Code executed in IPython cell.'
  30. def __str__(self) -> str:
  31. return f'**IPythonRunCellObservation**\n{self.content}'