🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fix batch query:
leonzh0u3e13a00003af
diff --git a/examples/search_with_specific_engine.py b/examples/search_with_specific_engine.pyindex c91769859..7cc431cd4 100644--- a/examples/search_with_specific_engine.py+++ b/examples/search_with_specific_engine.py@@ -6,11 +6,11 @@ from metagpt.tools import SearchEngineTypeasync def main():# Serper API- 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.SERPER_GOOGLE).run(["What are some good sun protection products?","What are some of the best beaches?"])+ # SerpAPI+ #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 --git a/metagpt/roles/role.py b/metagpt/roles/role.pyindex 1ce85491d..e99b0d199 100644--- a/metagpt/roles/role.py+++ b/metagpt/roles/role.py@@ -226,7 +226,7 @@ class Role:if isinstance(message, Message):self.recv(message)if isinstance(message, list):- self.recv(Message("|".join(message)))+ self.recv(Message("\n".join(message)))elif not await self._observe():# 如果没有任何新信息,挂起等待logger.debug(f"{self._setting}: no news. waiting.")diff --git a/metagpt/tools/search_engine.py b/metagpt/tools/search_engine.pyindex 1f229a72a..cfd4e8789 100644--- a/metagpt/tools/search_engine.py+++ b/metagpt/tools/search_engine.py@@ -53,11 +53,11 @@ class SearchEngine:return rsp-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+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 APIArgs:- queries (list[str]): A batch of search queries.+ query (str): The search query.num_results (int): The number of results to return.Returns:@@ -71,19 +71,15 @@ def google_official_search(queries: list[str], num_results: int = 8, focus=['sniapi_key = config.google_api_keycustom_search_engine_id = config.google_cse_id- 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)- .execute()- )+ with build("customsearch", "v1", developerKey=api_key) as service:- # Extract the search result items from the response+ result = (+ service.cse()+ .list(q=query, cx=custom_search_engine_id, num=num_results)+ .execute()+ )+ logger.info(result)+ # Extract the search result items from the responsesearch_results = result.get("items", [])# Create a list of only the URLs from the search resultsdiff --git a/metagpt/tools/search_engine_serper.py b/metagpt/tools/search_engine_serper.pyindex fefaa1eb5..80c2f8001 100644--- a/metagpt/tools/search_engine_serper.py+++ b/metagpt/tools/search_engine_serper.py@@ -38,8 +38,8 @@ class SerperWrapper(BaseModel):async def run(self, query: str, **kwargs: Any) -> str:"""Run query through Serper and parse result async."""- queries = query.split("|")- return "|".join([self._process_response(res) for res in await self.results(queries)])+ queries = query.split("\n")+ return "\n".join([self._process_response(res) for res in await self.results(queries)])async def results(self, queries: list[str]) -> dict:"""Use aiohttp to run query through Serper and return the results async."""