add url info in browsing observation (#3815)

* add url info in browsing observation

* fix integration tests for url

---------

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
Frank Xu 2024-09-11 20:46:39 -04:00 committed by GitHub
parent 41b8f3e4a7
commit fe5ecb6da8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 2 deletions

View File

@ -65,10 +65,15 @@ In order to accomplish my goal I need to send the information asked back to the
"""
def get_prompt(error_prefix: str, cur_axtree_txt: str, prev_action_str: str) -> str:
def get_prompt(
error_prefix: str, cur_url: str, cur_axtree_txt: str, prev_action_str: str
) -> str:
prompt = f"""\
{error_prefix}
# Current Page URL:
{cur_url}
# Current Accessibility Tree:
{cur_axtree_txt}
@ -139,6 +144,7 @@ class BrowsingAgent(Agent):
"""
messages: list[Message] = []
prev_actions = []
cur_url = ''
cur_axtree_txt = ''
error_prefix = ''
last_obs = None
@ -179,6 +185,9 @@ class BrowsingAgent(Agent):
self.error_accumulator += 1
if self.error_accumulator > 5:
return MessageAction('Too many errors encountered. Task failed.')
cur_url = last_obs.url
try:
cur_axtree_txt = flatten_axtree_to_str(
last_obs.axtree_object,
@ -204,7 +213,7 @@ class BrowsingAgent(Agent):
messages.append(Message(role='system', content=[TextContent(text=system_msg)]))
prompt = get_prompt(error_prefix, cur_axtree_txt, prev_action_str)
prompt = get_prompt(error_prefix, cur_url, cur_axtree_txt, prev_action_str)
messages.append(Message(role='user', content=[TextContent(text=prompt)]))
flat_messages = self.llm.format_messages_for_llm(messages)

View File

@ -105,8 +105,12 @@ click('a51')
click('48', button='middle', modifiers=['Shift'])
----------
# Current Page URL:
# Current Accessibility Tree:

View File

@ -105,8 +105,12 @@ click('a51')
click('48', button='middle', modifiers=['Shift'])
----------
# Current Page URL:
http://localhost:8000/
# Current Accessibility Tree:
RootWebArea 'The Ultimate Answer', focused
[8] heading 'The Ultimate Answer'

View File

@ -105,8 +105,12 @@ click('a51')
click('48', button='middle', modifiers=['Shift'])
----------
# Current Page URL:
http://localhost:8000/
# Current Accessibility Tree:
RootWebArea 'The Ultimate Answer', focused
[8] heading 'The Ultimate Answer'

View File

@ -105,8 +105,12 @@ click('a51')
click('48', button='middle', modifiers=['Shift'])
----------
# Current Page URL:
# Current Accessibility Tree:

View File

@ -105,8 +105,12 @@ click('a51')
click('48', button='middle', modifiers=['Shift'])
----------
# Current Page URL:
http://localhost:8000/
# Current Accessibility Tree:
RootWebArea 'The Ultimate Answer', focused
[8] heading 'The Ultimate Answer'

View File

@ -105,8 +105,12 @@ click('a51')
click('48', button='middle', modifiers=['Shift'])
----------
# Current Page URL:
http://localhost:8000/
# Current Accessibility Tree:
RootWebArea 'The Ultimate Answer', focused
[8] heading 'The Ultimate Answer'