mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Update serper_dev_tool.py
This commit is contained in:
@@ -27,7 +27,7 @@ class SerperDevTool(BaseTool):
|
|||||||
location: Optional[str] = None
|
location: Optional[str] = None
|
||||||
locale: Optional[str] = None
|
locale: Optional[str] = None
|
||||||
n_results: int = Field(default=10, description="Number of search results to return")
|
n_results: int = Field(default=10, description="Number of search results to return")
|
||||||
save_file: bool = Field(default=False, description="Flag to determine whether to save the results to a file")
|
save_file: bool = Field(default=False, description="Flag to determine whether to save the results to a file")
|
||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
self,
|
self,
|
||||||
@@ -35,22 +35,19 @@ class SerperDevTool(BaseTool):
|
|||||||
) -> Any:
|
) -> Any:
|
||||||
|
|
||||||
search_query = kwargs.get('search_query') or kwargs.get('query')
|
search_query = kwargs.get('search_query') or kwargs.get('query')
|
||||||
save_file = kwargs.get('save_file', self.save_file)
|
save_file = kwargs.get('save_file', self.save_file)
|
||||||
n_results = kwargs.get('n_results', self.n_results)
|
n_results = kwargs.get('n_results', self.n_results)
|
||||||
|
|
||||||
payload = json.dumps(
|
payload = { "q": search_query, "num": n_results }
|
||||||
{
|
payload["gl"] = self.country if self.country
|
||||||
"q": search_query,
|
payload["location"] = self.country if self.location
|
||||||
"num": n_results,
|
payload["hl"] = self.country if self.locale
|
||||||
"gl": self.country,
|
|
||||||
"location": self.location,
|
payload = json.dumps(payload)
|
||||||
"hl": self.locale,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'X-API-KEY': os.environ['SERPER_API_KEY'],
|
'X-API-KEY': os.environ['SERPER_API_KEY'],
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
}
|
}
|
||||||
response = requests.request("POST", self.search_url, headers=headers, data=payload)
|
response = requests.request("POST", self.search_url, headers=headers, data=payload)
|
||||||
results = response.json()
|
results = response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user