Skip to content

Commit 31321bf

Browse files
committed
update
1 parent aa253ba commit 31321bf

File tree

1 file changed

+107
-1
lines changed

1 file changed

+107
-1
lines changed

zh/dev/star/guides/plugin-config.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ AstrBot 提供了”强大“的配置解析和可视化功能。能够让用户
4343
}
4444
```
4545

46-
- `type`: **此项必填**。配置的类型。支持 `string`, `text`, `int`, `float`, `bool`, `object`, `list`。当类型为 `text` 时,将会可视化为一个更大的可拖拽宽高的 textarea 组件,以适应大文本。
46+
- `type`: **此项必填**。配置的类型。支持 `string`, `text`, `int`, `float`, `bool`, `object`, `list`, `dict`, `template_list`。当类型为 `text` 时,将会可视化为一个更大的可拖拽宽高的 textarea 组件,以适应大文本。
4747
- `description`: 可选。配置的描述。建议一句话描述配置的行为。
4848
- `hint`: 可选。配置的提示信息,表现在上图中右边的问号按钮,当鼠标悬浮在问号按钮上时显示。
4949
- `obvious_hint`: 可选。配置的 hint 是否醒目显示。如上图的 `token`
@@ -66,6 +66,112 @@ AstrBot 提供了”强大“的配置解析和可视化功能。能够让用户
6666

6767
![image](/source/images/plugin/image.png)
6868

69+
### dict 类型的 schema
70+
71+
用于可视化编辑一个 Python 的 dict 类型的配置。如 AstrBot Core 中的自定义请求体参数配置项:
72+
73+
```py
74+
"custom_extra_body": {
75+
"description": "自定义请求体参数",
76+
"type": "dict",
77+
"items": {},
78+
"hint": "用于在请求时添加额外的参数,如 temperature、top_p、max_tokens 等。",
79+
"template_schema": { # 可选填写 template schema,当设置之后,用户可以透过 WebUI 快速编辑。
80+
"temperature": {
81+
"name": "Temperature",
82+
"description": "温度参数",
83+
"hint": "控制输出的随机性,范围通常为 0-2。值越高越随机。",
84+
"type": "float",
85+
"default": 0.6,
86+
"slider": {"min": 0, "max": 2, "step": 0.1},
87+
},
88+
"top_p": {
89+
"name": "Top-p",
90+
"description": "Top-p 采样",
91+
"hint": "核采样参数,范围通常为 0-1。控制模型考虑的概率质量。",
92+
"type": "float",
93+
"default": 1.0,
94+
"slider": {"min": 0, "max": 1, "step": 0.01},
95+
},
96+
"max_tokens": {
97+
"name": "Max Tokens",
98+
"description": "最大令牌数",
99+
"hint": "生成的最大令牌数。",
100+
"type": "int",
101+
"default": 8192,
102+
},
103+
},
104+
}
105+
```
106+
107+
### template_list 类型的 schema
108+
109+
> [!NOTE]
110+
> v4.10.4 引入。更多信息请查看:[#4208](https://github.com/AstrBotDevs/AstrBot/pull/4208)
111+
112+
插件开发者可以在_conf_schema中按照以下格式添加模板配置项(有点类似于原有的嵌套配置)
113+
114+
```json
115+
"field_id": {
116+
"type": "template_list",
117+
"description": "Template List Field",
118+
"templates": {
119+
"template_1": {
120+
"name": "Template One",
121+
"hint":"hint",
122+
"items": {
123+
"attr_a": {
124+
"description": "Attribute A",
125+
"type": "int",
126+
"default": 10
127+
},
128+
"attr_b": {
129+
"description": "Attribute B",
130+
"hint": "This is a boolean attribute",
131+
"type": "bool",
132+
"default": true
133+
}
134+
}
135+
},
136+
"template_2": {
137+
"name": "Template Two",
138+
"hint":"hint",
139+
"items": {
140+
"attr_c": {
141+
"description": "Attribute A",
142+
"type": "int",
143+
"default": 10
144+
},
145+
"attr_d": {
146+
"description": "Attribute B",
147+
"hint": "This is a boolean attribute",
148+
"type": "bool",
149+
"default": true
150+
}
151+
}
152+
}
153+
}
154+
}
155+
```
156+
保存后的 config 为
157+
158+
```json
159+
"field_id": [
160+
{
161+
"__template_key": "template_1",
162+
"attr_a": 10,
163+
"attr_b": true
164+
},
165+
{
166+
"__template_key": "template_2",
167+
"attr_c": 10,
168+
"attr_d": true
169+
}
170+
]
171+
```
172+
173+
<img width="1000" alt="image" src="https://github.com/user-attachments/assets/74876d30-11a4-491b-a7a0-8ebe8d603782" />
174+
69175
## 在插件中使用配置
70176

71177
AstrBot 在载入插件时会检测插件目录下是否有 `_conf_schema.json` 文件,如果有,会自动解析配置并保存在 `data/config/<plugin_name>_config.json` 下(依照 Schema 创建的配置文件实体),并在实例化插件类时传入给 `__init__()`

0 commit comments

Comments
 (0)