browse.py 1.6 KB

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