mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-27 17:56:23 +02:00
fix batch query:
This commit is contained in:
parent
242bbbc13a
commit
3e13a00003
4 changed files with 18 additions and 22 deletions
|
|
@ -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 API
|
||||
|
||||
Args:
|
||||
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=['sni
|
|||
api_key = config.google_api_key
|
||||
custom_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 response
|
||||
search_results = result.get("items", [])
|
||||
|
||||
# Create a list of only the URLs from the search results
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue