AutoGPT: Improve output format of web commands

This commit is contained in:
Reinier van der Leer
2023-10-16 15:49:19 -07:00
parent 546e08a5cf
commit e75073b495
3 changed files with 8 additions and 2 deletions

View File

@@ -57,6 +57,11 @@ def web_search(query: str, agent: Agent, num_results: int = 8) -> str:
time.sleep(1) time.sleep(1)
attempts += 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) results = json.dumps(search_results, ensure_ascii=False, indent=4)
return safe_google_results(results) return safe_google_results(results)

View File

@@ -111,11 +111,12 @@ async def read_webpage(url: str, agent: Agent, question: str = "") -> str:
links = links[:LINKS_TO_RETURN] links = links[:LINKS_TO_RETURN]
text_fmt = f"'''{text}'''" if "\n" in text else f"'{text}'" text_fmt = f"'''{text}'''" if "\n" in text else f"'{text}'"
links_fmt = "\n".join(f"- {link}" for link in links)
return ( return (
f"Page content{' (summary)' if summarized else ''}:" f"Page content{' (summary)' if summarized else ''}:"
if return_literal_content if return_literal_content
else "Answer gathered from webpage:" else "Answer gathered from webpage:"
) + f" {text_fmt}\n\nLinks: {links}" ) + f" {text_fmt}\n\nLinks:\n{links_fmt}"
except WebDriverException as e: except WebDriverException as e:
# These errors are often quite long and include lots of context. # These errors are often quite long and include lots of context.

View File

@@ -30,4 +30,4 @@ def format_hyperlinks(hyperlinks: list[tuple[str, str]]) -> list[str]:
Returns: Returns:
List[str]: The formatted hyperlinks 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]