browse.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from dataclasses import dataclass
  2. from typing import ClassVar
  3. from openhands.core.schema import ActionType
  4. from openhands.events.action.action import Action, ActionSecurityRisk
  5. @dataclass
  6. class BrowseURLAction(Action):
  7. url: str
  8. thought: str = ''
  9. action: str = ActionType.BROWSE
  10. runnable: ClassVar[bool] = True
  11. security_risk: ActionSecurityRisk | None = None
  12. @property
  13. def message(self) -> str:
  14. return f'I am browsing the URL: {self.url}'
  15. def __str__(self) -> str:
  16. ret = '**BrowseURLAction**\n'
  17. if self.thought:
  18. ret += f'THOUGHT: {self.thought}\n'
  19. ret += f'URL: {self.url}'
  20. return ret
  21. @dataclass
  22. class BrowseInteractiveAction(Action):
  23. browser_actions: str
  24. thought: str = ''
  25. browsergym_send_msg_to_user: str = ''
  26. action: str = ActionType.BROWSE_INTERACTIVE
  27. runnable: ClassVar[bool] = True
  28. security_risk: ActionSecurityRisk | None = None
  29. @property
  30. def message(self) -> str:
  31. return (
  32. f'I am interacting with the browser:\n' f'```\n{self.browser_actions}\n```'
  33. )
  34. def __str__(self) -> str:
  35. ret = '**BrowseInteractiveAction**\n'
  36. if self.thought:
  37. ret += f'THOUGHT: {self.thought}\n'
  38. ret += f'BROWSER_ACTIONS: {self.browser_actions}'
  39. return ret