From 223a018083a8821ce3dc03ca1381e07bbdc70e2d Mon Sep 17 00:00:00 2001 From: Igor Pechersky Date: Wed, 19 Jun 2024 09:46:41 +0000 Subject: [PATCH 1/2] https://github.com/geekan/MetaGPT/issues/1356 --- metagpt/roles/researcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/roles/researcher.py b/metagpt/roles/researcher.py index fd40960e2..5c6c1d9f4 100644 --- a/metagpt/roles/researcher.py +++ b/metagpt/roles/researcher.py @@ -58,7 +58,7 @@ class Researcher(Role): ) elif isinstance(todo, WebBrowseAndSummarize): links = instruct_content.links - todos = (todo.run(*url, query=query, system_text=research_system_text) for (query, url) in links.items()) + todos = (todo.run(*url, query=query, system_text=research_system_text) for (query, url) in links.items() if url) if self.enable_concurrency: summaries = await asyncio.gather(*todos) else: From 1028184a1f03639ab54ed0962d5cb36aef45f9f5 Mon Sep 17 00:00:00 2001 From: Igor Pechersky Date: Wed, 19 Jun 2024 10:04:12 +0000 Subject: [PATCH 2/2] Got error from SerpAPI: Google hasn't returned any results for this query. --- metagpt/actions/research.py | 2 ++ metagpt/tools/search_engine_serpapi.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/metagpt/actions/research.py b/metagpt/actions/research.py index 2a99a8d99..5086f10cf 100644 --- a/metagpt/actions/research.py +++ b/metagpt/actions/research.py @@ -161,6 +161,8 @@ class CollectLinks(Action): """ max_results = max(num_results * 2, 6) results = await self.search_engine.run(query, max_results=max_results, as_string=False) + if len(results) == 0: + return [] _results = "\n".join(f"{i}: {j}" for i, j in zip(range(max_results), results)) prompt = COLLECT_AND_RANKURLS_PROMPT.format(topic=topic, query=query, results=_results) logger.debug(prompt) diff --git a/metagpt/tools/search_engine_serpapi.py b/metagpt/tools/search_engine_serpapi.py index 5744b1b62..15bcdf8b4 100644 --- a/metagpt/tools/search_engine_serpapi.py +++ b/metagpt/tools/search_engine_serpapi.py @@ -87,8 +87,11 @@ class SerpAPIWrapper(BaseModel): get_focused = lambda x: {i: j for i, j in x.items() if i in focus} if "error" in res.keys(): - raise ValueError(f"Got error from SerpAPI: {res['error']}") - if "answer_box" in res.keys() and "answer" in res["answer_box"].keys(): + if res["error"] == "Google hasn't returned any results for this query.": + toret = "No good search result found" + else: + raise ValueError(f"Got error from SerpAPI: {res['error']}") + elif "answer_box" in res.keys() and "answer" in res["answer_box"].keys(): toret = res["answer_box"]["answer"] elif "answer_box" in res.keys() and "snippet" in res["answer_box"].keys(): toret = res["answer_box"]["snippet"]