本文最后更新于550 天前,其中的信息可能已经过时,如有错误请联系我的微信CKEEZ7
以https://api.vvhan.com/提供的天气api接口为例。

COZE中添加插件,左下角添加依赖,左上角添加工具。
使用args.input获取传入值:



代码如下
from runtime import Args
from typings.get_weather.get_weather import Input, Output
import requests
"""
Each file needs to export a function named `handler`. This function is the entrance to the Tool.
Parameters:
args: parameters of the entry function.
args.input - input parameters, you can get test input value by args.input.xxx.
args.logger - logger instance used to print logs, injected by runtime.
Remember to fill in input/output in Metadata, it helps LLM to recognize and use tool.
Return:
The return data of the function, which should match the declared output parameters.
"""
def handler(args: Args[Input])->Output:
city = args.input.city
url = "https://api.vvhan.com/api/weather"
params={
"city":city
}
res = requests.get(url=url,params=params).json()
# res.pop("pm2.5")
# 使用pop方法删除
if "air" in res:
pm25_value = res["air"]["pm2.5"]
# 删除旧的 "pm2.5" 键
del res["air"]["pm2.5"]
# 添加新的 "pm25" 键
res["air"]["pm25"] = pm25_value
return res
输出完点击更新输出参数即可:



