files.py 852 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 FileReadAction(Action):
  7. """
  8. Reads a file from a given path.
  9. Can be set to read specific lines using start and end
  10. Default lines 0:-1 (whole file)
  11. """
  12. path: str
  13. start: int = 0
  14. end: int = -1
  15. thought: str = ''
  16. action: str = ActionType.READ
  17. runnable: ClassVar[bool] = True
  18. @property
  19. def message(self) -> str:
  20. return f'Reading file: {self.path}'
  21. @dataclass
  22. class FileWriteAction(Action):
  23. path: str
  24. content: str
  25. start: int = 0
  26. end: int = -1
  27. thought: str = ''
  28. action: str = ActionType.WRITE
  29. runnable: ClassVar[bool] = True
  30. @property
  31. def message(self) -> str:
  32. return f'Writing file: {self.path}'