Skip to content

Commit

Permalink
AutoGPT: Improve output format of web commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Oct 16, 2023
1 parent 546e08a commit e75073b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions autogpts/autogpt/autogpt/commands/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def web_search(query: str, agent: Agent, num_results: int = 8) -> str:
time.sleep(1)
attempts += 1

search_results = [
{"title": r["title"], "url": r["href"], "description": r["body"]}
for r in search_results
]

results = json.dumps(search_results, ensure_ascii=False, indent=4)
return safe_google_results(results)

Expand Down
3 changes: 2 additions & 1 deletion autogpts/autogpt/autogpt/commands/web_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ async def read_webpage(url: str, agent: Agent, question: str = "") -> str:
links = links[:LINKS_TO_RETURN]

text_fmt = f"'''{text}'''" if "\n" in text else f"'{text}'"
links_fmt = "\n".join(f"- {link}" for link in links)
return (
f"Page content{' (summary)' if summarized else ''}:"
if return_literal_content
else "Answer gathered from webpage:"
) + f" {text_fmt}\n\nLinks: {links}"
) + f" {text_fmt}\n\nLinks:\n{links_fmt}"

except WebDriverException as e:
# These errors are often quite long and include lots of context.
Expand Down
2 changes: 1 addition & 1 deletion autogpts/autogpt/autogpt/processing/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def format_hyperlinks(hyperlinks: list[tuple[str, str]]) -> list[str]:
Returns:
List[str]: The formatted hyperlinks
"""
return [f"{link_text} ({link_url})" for link_text, link_url in hyperlinks]
return [f"{link_text.strip()} ({link_url})" for link_text, link_url in hyperlinks]

0 comments on commit e75073b

Please sign in to comment.