commands.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from dataclasses import dataclass
  2. from typing import ClassVar
  3. from opendevin.core.schema import ActionType
  4. from .action import Action
  5. @dataclass
  6. class CmdRunAction(Action):
  7. command: str
  8. background: bool = False
  9. thought: str = ''
  10. action: str = ActionType.RUN
  11. runnable: ClassVar[bool] = True
  12. @property
  13. def message(self) -> str:
  14. return f'Running command: {self.command}'
  15. def __str__(self) -> str:
  16. ret = '**CmdRunAction**\n'
  17. if self.thought:
  18. ret += f'THOUGHT: {self.thought}\n'
  19. ret += f'COMMAND:\n{self.command}'
  20. return ret
  21. @dataclass
  22. class CmdKillAction(Action):
  23. command_id: int
  24. thought: str = ''
  25. action: str = ActionType.KILL
  26. runnable: ClassVar[bool] = True
  27. @property
  28. def message(self) -> str:
  29. return f'Killing command: {self.command_id}'
  30. def __str__(self) -> str:
  31. return f'**CmdKillAction**\n{self.command_id}'
  32. @dataclass
  33. class IPythonRunCellAction(Action):
  34. code: str
  35. thought: str = ''
  36. action: str = ActionType.RUN_IPYTHON
  37. runnable: ClassVar[bool] = True
  38. kernel_init_code: str = '' # code to run in the kernel (if the kernel is restarted)
  39. def __str__(self) -> str:
  40. ret = '**IPythonRunCellAction**\n'
  41. if self.thought:
  42. ret += f'THOUGHT: {self.thought}\n'
  43. ret += f'CODE:\n{self.code}'
  44. return ret
  45. @property
  46. def message(self) -> str:
  47. return f'Running Python code interactively: {self.code}'