browse.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from dataclasses import dataclass, field
  2. from openhands.core.schema import ObservationType
  3. from openhands.events.observation.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. error: bool = False
  10. observation: str = ObservationType.BROWSE
  11. # do not include in the memory
  12. open_pages_urls: list = field(default_factory=list)
  13. active_page_index: int = -1
  14. dom_object: dict = field(default_factory=dict, repr=False) # don't show in repr
  15. axtree_object: dict = field(default_factory=dict, repr=False) # don't show in repr
  16. extra_element_properties: dict = field(
  17. default_factory=dict, repr=False
  18. ) # don't show in repr
  19. last_browser_action: str = ''
  20. last_browser_action_error: str = ''
  21. focused_element_bid: str = ''
  22. @property
  23. def message(self) -> str:
  24. return 'Visited ' + self.url
  25. def __str__(self) -> str:
  26. return (
  27. '**BrowserOutputObservation**\n'
  28. f'URL: {self.url}\n'
  29. f'Error: {self.error}\n'
  30. f'Open pages: {self.open_pages_urls}\n'
  31. f'Active page index: {self.active_page_index}\n'
  32. f'Last browser action: {self.last_browser_action}\n'
  33. f'Last browser action error: {self.last_browser_action_error}\n'
  34. f'Focused element bid: {self.focused_element_bid}\n'
  35. f'axTree: {self.axtree_object}\n'
  36. f'CONTENT: {self.content}\n'
  37. )