chore(api/core): apply ruff reformatting (#7624)

This commit is contained in:
Bowen Liang
2024-09-10 17:00:20 +08:00
committed by GitHub
parent 178730266d
commit 2cf1187b32
724 changed files with 21180 additions and 21123 deletions

View File

@@ -13,11 +13,8 @@ class SerperProvider(BuiltinToolProviderController):
"credentials": credentials,
}
).invoke(
user_id='',
tool_parameters={
"query": "test",
"result_type": "link"
},
user_id="",
tool_parameters={"query": "test", "result_type": "link"},
)
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))

View File

@@ -9,7 +9,6 @@ SERPER_API_URL = "https://google.serper.dev/search"
class SerperSearchTool(BuiltinTool):
def _parse_response(self, response: dict) -> dict:
result = {}
if "knowledgeGraph" in response:
@@ -17,28 +16,19 @@ class SerperSearchTool(BuiltinTool):
result["description"] = response["knowledgeGraph"].get("description", "")
if "organic" in response:
result["organic"] = [
{
"title": item.get("title", ""),
"link": item.get("link", ""),
"snippet": item.get("snippet", "")
}
{"title": item.get("title", ""), "link": item.get("link", ""), "snippet": item.get("snippet", "")}
for item in response["organic"]
]
return result
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
params = {
"q": tool_parameters['query'],
"gl": "us",
"hl": "en"
}
headers = {
'X-API-KEY': self.runtime.credentials['serperapi_api_key'],
'Content-Type': 'application/json'
}
response = requests.get(url=SERPER_API_URL, params=params,headers=headers)
def _invoke(
self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
params = {"q": tool_parameters["query"], "gl": "us", "hl": "en"}
headers = {"X-API-KEY": self.runtime.credentials["serperapi_api_key"], "Content-Type": "application/json"}
response = requests.get(url=SERPER_API_URL, params=params, headers=headers)
response.raise_for_status()
valuable_res = self._parse_response(response.json())
return self.create_json_message(valuable_res)