browse.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from dataclasses import dataclass, field
  2. from opendevin.core.schema import ObservationType
  3. from .observation import Observation
  4. @dataclass
  5. class BrowserOutputObservation(Observation):
  6. """This data class represents the output of a browser."""
  7. url: str
  8. screenshot: str = field(repr=False) # don't show in repr
  9. status_code: int = 200
  10. error: bool = False
  11. observation: str = ObservationType.BROWSE
  12. # do not include in the memory
  13. open_pages_urls: list = field(default_factory=list)
  14. active_page_index: int = -1
  15. dom_object: dict = field(default_factory=dict, repr=False) # don't show in repr
  16. axtree_object: dict = field(default_factory=dict, repr=False) # don't show in repr
  17. extra_element_properties: dict = field(
  18. default_factory=dict, repr=False
  19. ) # don't show in repr
  20. last_browser_action: str = ''
  21. last_browser_action_error: str = ''
  22. focused_element_bid: str = ''
  23. @property
  24. def message(self) -> str:
  25. return 'Visited ' + self.url
  26. def __str__(self) -> str:
  27. return (
  28. '**BrowserOutputObservation**\n'
  29. f'URL: {self.url}\n'
  30. f'Status code: {self.status_code}\n'
  31. f'Error: {self.error}\n'
  32. f'Open pages: {self.open_pages_urls}\n'
  33. f'Active page index: {self.active_page_index}\n'
  34. f'Last browser action: {self.last_browser_action}\n'
  35. f'Last browser action error: {self.last_browser_action_error}\n'
  36. f'Focused element bid: {self.focused_element_bid}\n'
  37. f'CONTENT: {self.content}\n'
  38. )