files.py 847 B

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