mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-24 18:23:07 +08:00
chore(api/core): apply ruff reformatting (#7624)
This commit is contained in:
@@ -12,10 +12,12 @@ class TiandituProvider(BuiltinToolProviderController):
|
||||
runtime={
|
||||
"credentials": credentials,
|
||||
}
|
||||
).invoke(user_id='',
|
||||
tool_parameters={
|
||||
'content': '北京',
|
||||
'specify': '156110000',
|
||||
})
|
||||
).invoke(
|
||||
user_id="",
|
||||
tool_parameters={
|
||||
"content": "北京",
|
||||
"specify": "156110000",
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
||||
|
||||
@@ -8,26 +8,26 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
|
||||
class GeocoderTool(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 tools
|
||||
invoke tools
|
||||
"""
|
||||
base_url = 'http://api.tianditu.gov.cn/geocoder'
|
||||
|
||||
keyword = tool_parameters.get('keyword', '')
|
||||
base_url = "http://api.tianditu.gov.cn/geocoder"
|
||||
|
||||
keyword = tool_parameters.get("keyword", "")
|
||||
if not keyword:
|
||||
return self.create_text_message('Invalid parameter keyword')
|
||||
|
||||
tk = self.runtime.credentials['tianditu_api_key']
|
||||
|
||||
return self.create_text_message("Invalid parameter keyword")
|
||||
|
||||
tk = self.runtime.credentials["tianditu_api_key"]
|
||||
|
||||
params = {
|
||||
'keyWord': keyword,
|
||||
"keyWord": keyword,
|
||||
}
|
||||
|
||||
result = requests.get(base_url + '?ds=' + json.dumps(params, ensure_ascii=False) + '&tk=' + tk).json()
|
||||
|
||||
result = requests.get(base_url + "?ds=" + json.dumps(params, ensure_ascii=False) + "&tk=" + tk).json()
|
||||
|
||||
return self.create_json_message(result)
|
||||
|
||||
@@ -8,38 +8,51 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
|
||||
class PoiSearchTool(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 tools
|
||||
invoke tools
|
||||
"""
|
||||
geocoder_base_url = 'http://api.tianditu.gov.cn/geocoder'
|
||||
base_url = 'http://api.tianditu.gov.cn/v2/search'
|
||||
|
||||
keyword = tool_parameters.get('keyword', '')
|
||||
geocoder_base_url = "http://api.tianditu.gov.cn/geocoder"
|
||||
base_url = "http://api.tianditu.gov.cn/v2/search"
|
||||
|
||||
keyword = tool_parameters.get("keyword", "")
|
||||
if not keyword:
|
||||
return self.create_text_message('Invalid parameter keyword')
|
||||
|
||||
baseAddress = tool_parameters.get('baseAddress', '')
|
||||
return self.create_text_message("Invalid parameter keyword")
|
||||
|
||||
baseAddress = tool_parameters.get("baseAddress", "")
|
||||
if not baseAddress:
|
||||
return self.create_text_message('Invalid parameter baseAddress')
|
||||
|
||||
tk = self.runtime.credentials['tianditu_api_key']
|
||||
|
||||
base_coords = requests.get(geocoder_base_url + '?ds=' + json.dumps({'keyWord': baseAddress,}, ensure_ascii=False) + '&tk=' + tk).json()
|
||||
|
||||
return self.create_text_message("Invalid parameter baseAddress")
|
||||
|
||||
tk = self.runtime.credentials["tianditu_api_key"]
|
||||
|
||||
base_coords = requests.get(
|
||||
geocoder_base_url
|
||||
+ "?ds="
|
||||
+ json.dumps(
|
||||
{
|
||||
"keyWord": baseAddress,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
+ "&tk="
|
||||
+ tk
|
||||
).json()
|
||||
|
||||
params = {
|
||||
'keyWord': keyword,
|
||||
'queryRadius': 5000,
|
||||
'queryType': 3,
|
||||
'pointLonlat': base_coords['location']['lon'] + ',' + base_coords['location']['lat'],
|
||||
'start': 0,
|
||||
'count': 100,
|
||||
"keyWord": keyword,
|
||||
"queryRadius": 5000,
|
||||
"queryType": 3,
|
||||
"pointLonlat": base_coords["location"]["lon"] + "," + base_coords["location"]["lat"],
|
||||
"start": 0,
|
||||
"count": 100,
|
||||
}
|
||||
|
||||
result = requests.get(base_url + '?postStr=' + json.dumps(params, ensure_ascii=False) + '&type=query&tk=' + tk).json()
|
||||
|
||||
result = requests.get(
|
||||
base_url + "?postStr=" + json.dumps(params, ensure_ascii=False) + "&type=query&tk=" + tk
|
||||
).json()
|
||||
|
||||
return self.create_json_message(result)
|
||||
|
||||
@@ -8,29 +8,42 @@ from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
|
||||
class PoiSearchTool(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 tools
|
||||
invoke tools
|
||||
"""
|
||||
|
||||
geocoder_base_url = 'http://api.tianditu.gov.cn/geocoder'
|
||||
base_url = 'http://api.tianditu.gov.cn/staticimage'
|
||||
|
||||
keyword = tool_parameters.get('keyword', '')
|
||||
if not keyword:
|
||||
return self.create_text_message('Invalid parameter keyword')
|
||||
|
||||
tk = self.runtime.credentials['tianditu_api_key']
|
||||
|
||||
keyword_coords = requests.get(geocoder_base_url + '?ds=' + json.dumps({'keyWord': keyword,}, ensure_ascii=False) + '&tk=' + tk).json()
|
||||
coords = keyword_coords['location']['lon'] + ',' + keyword_coords['location']['lat']
|
||||
|
||||
result = requests.get(base_url + '?center=' + coords + '&markers=' + coords + '&width=400&height=300&zoom=14&tk=' + tk).content
|
||||
|
||||
return self.create_blob_message(blob=result,
|
||||
meta={'mime_type': 'image/png'},
|
||||
save_as=self.VARIABLE_KEY.IMAGE.value)
|
||||
geocoder_base_url = "http://api.tianditu.gov.cn/geocoder"
|
||||
base_url = "http://api.tianditu.gov.cn/staticimage"
|
||||
|
||||
keyword = tool_parameters.get("keyword", "")
|
||||
if not keyword:
|
||||
return self.create_text_message("Invalid parameter keyword")
|
||||
|
||||
tk = self.runtime.credentials["tianditu_api_key"]
|
||||
|
||||
keyword_coords = requests.get(
|
||||
geocoder_base_url
|
||||
+ "?ds="
|
||||
+ json.dumps(
|
||||
{
|
||||
"keyWord": keyword,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
+ "&tk="
|
||||
+ tk
|
||||
).json()
|
||||
coords = keyword_coords["location"]["lon"] + "," + keyword_coords["location"]["lat"]
|
||||
|
||||
result = requests.get(
|
||||
base_url + "?center=" + coords + "&markers=" + coords + "&width=400&height=300&zoom=14&tk=" + tk
|
||||
).content
|
||||
|
||||
return self.create_blob_message(
|
||||
blob=result, meta={"mime_type": "image/png"}, save_as=self.VARIABLE_KEY.IMAGE.value
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user