commands.py 1.2 KB

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