Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

merge main

leonzh0u242bbbc13a0f
diff --cc examples/search_with_specific_engine.py
index b4da84f47,d63981c88..c91769859
--- a/examples/search_with_specific_engine.py
+++ b/examples/search_with_specific_engine.py
@@@ -3,13 -3,14 +3,14 @@@ import asynci
from metagpt.roles import Searcher
from metagpt.tools import SearchEngineType
+
async def main():
# Serper API
- await Searcher(engine=SearchEngineType.SERPER_GOOGLE).run("What are some good sun protection products?")
+ await Searcher(engine = SearchEngineType.SERPER_GOOGLE).run(["What are some good sun protection products?","What are some of the best beaches?"])
# Serper API
- #await Searcher(engine = SearchEngineType.SERPAPI_GOOGLE).run("What are the best ski brands for skiers?")
+ # await Searcher(engine=SearchEngineType.SERPAPI_GOOGLE).run("What are the best ski brands for skiers?")
# Google API
- #await Searcher(engine = SearchEngineType.DIRECT_GOOGLE).run("What are the most interesting human facts?")
+ # await Searcher(engine=SearchEngineType.DIRECT_GOOGLE).run("What are the most interesting human facts?")
if __name__ == '__main__':
asyncio.run(main())
diff --cc metagpt/tools/search_engine.py
index fb666f952,69670df6f..1f229a72a
--- a/metagpt/tools/search_engine.py
+++ b/metagpt/tools/search_engine.py
@@@ -55,11 -56,11 +53,11 @@@ class SearchEngine
return rsp
--def google_official_search(query: str, num_results: int = 8, focus=['snippet', 'link', 'title']) -> dict | list[dict]:
-- """Return the results of a Google search using the official Google API
++def google_official_search(queries: list[str], num_results: int = 8, focus=['snippet', 'link', 'title']) -> dict | list[dict]:
++ """Return the results of a batch of Google search using the official Google API
Args:
-- query (str): The search query.
++ queries (list[str]): A batch of search queries.
num_results (int): The number of results to return.
Returns:
@@@ -73,8 -74,8 +71,12 @@@
api_key = config.google_api_key
custom_search_engine_id = config.google_cse_id
-- service = build("customsearch", "v1", developerKey=api_key)
--
++ service = build("customsearch", "v2", developerKey=api_key)
++ batch = service.new_batch_http_request()
++ for query in queries:
++ batch.add(service.cse()
++ .list(q=query, cx=custom_search_engine_id, num=num_results))
++ batch.execute()
result = (
service.cse()
.list(q=query, cx=custom_search_engine_id, num=num_results)