COZE-创建插件
本文最后更新于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

输出完点击更新输出参数即可:

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇