mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 05:54:26 +01:00
AutoGPT: Improve output format of web commands
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|||||||
Reference in New Issue
Block a user