mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-15 13:56:53 +08:00
chore(api/core): apply ruff reformatting (#7624)
This commit is contained in:
@@ -13,11 +13,8 @@ class SearchAPIProvider(BuiltinToolProviderController):
|
||||
"credentials": credentials,
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_parameters={
|
||||
"query": "SearchApi dify",
|
||||
"result_type": "link"
|
||||
},
|
||||
user_id="",
|
||||
tool_parameters={"query": "SearchApi dify", "result_type": "link"},
|
||||
)
|
||||
except Exception as e:
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
||||
|
||||
@@ -7,6 +7,7 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
SEARCH_API_URL = "https://www.searchapi.io/api/v1/search"
|
||||
|
||||
|
||||
class SearchAPI:
|
||||
"""
|
||||
SearchAPI tool provider.
|
||||
@@ -80,25 +81,29 @@ class SearchAPI:
|
||||
toret = "No good search result found"
|
||||
return toret
|
||||
|
||||
|
||||
class GoogleTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
def _invoke(
|
||||
self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
"""
|
||||
Invoke the SearchApi tool.
|
||||
"""
|
||||
query = tool_parameters['query']
|
||||
result_type = tool_parameters['result_type']
|
||||
query = tool_parameters["query"]
|
||||
result_type = tool_parameters["result_type"]
|
||||
num = tool_parameters.get("num", 10)
|
||||
google_domain = tool_parameters.get("google_domain", "google.com")
|
||||
gl = tool_parameters.get("gl", "us")
|
||||
hl = tool_parameters.get("hl", "en")
|
||||
location = tool_parameters.get("location")
|
||||
|
||||
api_key = self.runtime.credentials['searchapi_api_key']
|
||||
result = SearchAPI(api_key).run(query, result_type=result_type, num=num, google_domain=google_domain, gl=gl, hl=hl, location=location)
|
||||
api_key = self.runtime.credentials["searchapi_api_key"]
|
||||
result = SearchAPI(api_key).run(
|
||||
query, result_type=result_type, num=num, google_domain=google_domain, gl=gl, hl=hl, location=location
|
||||
)
|
||||
|
||||
if result_type == 'text':
|
||||
if result_type == "text":
|
||||
return self.create_text_message(text=result)
|
||||
return self.create_link_message(link=result)
|
||||
|
||||
@@ -7,6 +7,7 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
SEARCH_API_URL = "https://www.searchapi.io/api/v1/search"
|
||||
|
||||
|
||||
class SearchAPI:
|
||||
"""
|
||||
SearchAPI tool provider.
|
||||
@@ -50,7 +51,16 @@ class SearchAPI:
|
||||
if type == "text":
|
||||
if "jobs" in res.keys() and "title" in res["jobs"][0].keys():
|
||||
for item in res["jobs"]:
|
||||
toret += "title: " + item["title"] + "\n" + "company_name: " + item["company_name"] + "content: " + item["description"] + "\n"
|
||||
toret += (
|
||||
"title: "
|
||||
+ item["title"]
|
||||
+ "\n"
|
||||
+ "company_name: "
|
||||
+ item["company_name"]
|
||||
+ "content: "
|
||||
+ item["description"]
|
||||
+ "\n"
|
||||
)
|
||||
if toret == "":
|
||||
toret = "No good search result found"
|
||||
|
||||
@@ -62,16 +72,18 @@ class SearchAPI:
|
||||
toret = "No good search result found"
|
||||
return toret
|
||||
|
||||
|
||||
class GoogleJobsTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
def _invoke(
|
||||
self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
"""
|
||||
Invoke the SearchApi tool.
|
||||
"""
|
||||
query = tool_parameters['query']
|
||||
result_type = tool_parameters['result_type']
|
||||
query = tool_parameters["query"]
|
||||
result_type = tool_parameters["result_type"]
|
||||
is_remote = tool_parameters.get("is_remote")
|
||||
google_domain = tool_parameters.get("google_domain", "google.com")
|
||||
gl = tool_parameters.get("gl", "us")
|
||||
@@ -80,9 +92,11 @@ class GoogleJobsTool(BuiltinTool):
|
||||
|
||||
ltype = 1 if is_remote else None
|
||||
|
||||
api_key = self.runtime.credentials['searchapi_api_key']
|
||||
result = SearchAPI(api_key).run(query, result_type=result_type, google_domain=google_domain, gl=gl, hl=hl, location=location, ltype=ltype)
|
||||
api_key = self.runtime.credentials["searchapi_api_key"]
|
||||
result = SearchAPI(api_key).run(
|
||||
query, result_type=result_type, google_domain=google_domain, gl=gl, hl=hl, location=location, ltype=ltype
|
||||
)
|
||||
|
||||
if result_type == 'text':
|
||||
if result_type == "text":
|
||||
return self.create_text_message(text=result)
|
||||
return self.create_link_message(link=result)
|
||||
|
||||
@@ -7,6 +7,7 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
SEARCH_API_URL = "https://www.searchapi.io/api/v1/search"
|
||||
|
||||
|
||||
class SearchAPI:
|
||||
"""
|
||||
SearchAPI tool provider.
|
||||
@@ -68,25 +69,29 @@ class SearchAPI:
|
||||
toret = "No good search result found"
|
||||
return toret
|
||||
|
||||
|
||||
class GoogleNewsTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
def _invoke(
|
||||
self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
"""
|
||||
Invoke the SearchApi tool.
|
||||
"""
|
||||
query = tool_parameters['query']
|
||||
result_type = tool_parameters['result_type']
|
||||
query = tool_parameters["query"]
|
||||
result_type = tool_parameters["result_type"]
|
||||
num = tool_parameters.get("num", 10)
|
||||
google_domain = tool_parameters.get("google_domain", "google.com")
|
||||
gl = tool_parameters.get("gl", "us")
|
||||
hl = tool_parameters.get("hl", "en")
|
||||
location = tool_parameters.get("location")
|
||||
|
||||
api_key = self.runtime.credentials['searchapi_api_key']
|
||||
result = SearchAPI(api_key).run(query, result_type=result_type, num=num, google_domain=google_domain, gl=gl, hl=hl, location=location)
|
||||
api_key = self.runtime.credentials["searchapi_api_key"]
|
||||
result = SearchAPI(api_key).run(
|
||||
query, result_type=result_type, num=num, google_domain=google_domain, gl=gl, hl=hl, location=location
|
||||
)
|
||||
|
||||
if result_type == 'text':
|
||||
if result_type == "text":
|
||||
return self.create_text_message(text=result)
|
||||
return self.create_link_message(link=result)
|
||||
|
||||
@@ -7,6 +7,7 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
SEARCH_API_URL = "https://www.searchapi.io/api/v1/search"
|
||||
|
||||
|
||||
class SearchAPI:
|
||||
"""
|
||||
SearchAPI tool provider.
|
||||
@@ -55,18 +56,20 @@ class SearchAPI:
|
||||
|
||||
return toret
|
||||
|
||||
|
||||
class YoutubeTranscriptsTool(BuiltinTool):
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
def _invoke(
|
||||
self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
"""
|
||||
Invoke the SearchApi tool.
|
||||
"""
|
||||
video_id = tool_parameters['video_id']
|
||||
language = tool_parameters.get('language', "en")
|
||||
video_id = tool_parameters["video_id"]
|
||||
language = tool_parameters.get("language", "en")
|
||||
|
||||
api_key = self.runtime.credentials['searchapi_api_key']
|
||||
api_key = self.runtime.credentials["searchapi_api_key"]
|
||||
result = SearchAPI(api_key).run(video_id, language=language)
|
||||
|
||||
return self.create_text_message(text=result)
|
||||
|
||||
Reference in New Issue
Block a user