mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-21 14:05:17 +02:00
Merge pull request #1357 from igor-pechersky/main
Research role fails if some of Serpapi searches return no results
This commit is contained in:
commit
c99265778f
3 changed files with 8 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue