commands.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from dataclasses import dataclass
  2. from typing import ClassVar
  3. from opendevin.core.schema import ActionType
  4. from .action import Action, ActionConfirmationStatus
  5. @dataclass
  6. class CmdRunAction(Action):
  7. command: str
  8. thought: str = ''
  9. action: str = ActionType.RUN
  10. runnable: ClassVar[bool] = True
  11. is_confirmed: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED
  12. @property
  13. def message(self) -> str:
  14. return f'Running command: {self.command}'
  15. def __str__(self) -> str:
  16. ret = f'**CmdRunAction (source={self.source})**\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 IPythonRunCellAction(Action):
  23. code: str
  24. thought: str = ''
  25. action: str = ActionType.RUN_IPYTHON
  26. runnable: ClassVar[bool] = True
  27. is_confirmed: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED
  28. kernel_init_code: str = '' # code to run in the kernel (if the kernel is restarted)
  29. def __str__(self) -> str:
  30. ret = '**IPythonRunCellAction**\n'
  31. if self.thought:
  32. ret += f'THOUGHT: {self.thought}\n'
  33. ret += f'CODE:\n{self.code}'
  34. return ret
  35. @property
  36. def message(self) -> str:
  37. return f'Running Python code interactively: {self.code}'