-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
62 lines (48 loc) · 1.8 KB
/
plugin.py
File metadata and controls
62 lines (48 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Nekro Agent 美的控制插件
"""
from nekro_agent.api.plugin import NekroPlugin, ConfigBase, ExtraField
from nekro_agent.api.schemas import AgentCtx
from pydantic import Field
plugin = NekroPlugin(
name="美的智能家居控制",
module_name="nekro_midea_plugin",
description="给予AI助手通过美的云控制智能家居设备的能力",
version="1.3.2",
author="GeQian",
url="https://github.com/tooplick/nekro_midea_plugin",
)
@plugin.mount_config()
class MideaPluginConfig(ConfigBase):
"""美的智能家居插件配置"""
allowed_users: str = Field(
default="",
title="允许使用的用户QQ号列表",
description="逗号分隔的 QQ 号(如:12345678,87654321),留空表示允许所有人使用",
json_schema_extra=ExtraField(
placeholder="例如: 12345678,87654321"
).model_dump()
)
# 获取配置实例
config: MideaPluginConfig = plugin.get_config(MideaPluginConfig)
@plugin.mount_prompt_inject_method(
name="midea_usage_hint",
description="美的设备控制使用提示"
)
async def inject_midea_hint(_ctx: AgentCtx) -> str:
"""注入美的设备控制的使用提示"""
return """【美的智能家居控制提示】
控制设备之前使用get_midea_devices方法获取设备列表和ID
调用美的设备控制方法后,根据返回值用自然语言回复用户:
- ok: 操作成功
- error:device_offline: 设备离线
- error:not_logged_in: 未登录美的账号
- error:invalid_xxx: 参数错误
"""
@plugin.mount_cleanup_method()
async def clean_up():
"""清理插件资源"""
print("美的插件资源已清理")
# 导入控制器模块以注册沙箱方法
# 必须在 plugin 定义之后导入,否则会导致循环导入
from . import controllers # noqa: E402, F401