docs: 插件注册方式更新 — plugins.json代码生成替代硬编码

This commit is contained in:
2026-06-24 19:31:49 +08:00
parent cfebf5480e
commit 65ff530ce4
+43 -4
View File
@@ -94,13 +94,52 @@ func (t *HelloTool) Validate(args map[string]interface{}) error { return nil }
## 注册到 Cyrene
`ai-core/cmd/main.go` 的工具注册区添加一行:
### 方式一:plugins.json(推荐)
```go
registerPluginTools(toolRegistry, &myplugin.HelloPlugin{})
1. 将插件代码放到 `backend/plugins/<插件名>/`
2.`backend/ai-core/plugins.json` 中添加条目:
```json
{ "name": "my-hello", "import": "git.yeij.top/AskaEth/Cyrene-Plugins/my-hello", "struct": "HelloPlugin" }
```
重启 ai-core,LLM 即可在对话中自动调用 `hello` 工具。
3. 运行代码生成器:
```bash
cd backend/ai-core/cmd && go run gen_plugins.go
```
4. 重新编译 ai-core
### 方式二:直接注册(需要构造参数的插件)
`ai-core/cmd/main.go` 中添加:
```go
for _, t := range (&myplugin.HelloPlugin{}).Tools() {
toolRegistry.Register(t)
}
```
### 插件目录结构
```
backend/plugins/ ← 第三方插件目录
my-hello/
plugin.json ← 插件声明(name, version, struct
main.go ← 插件入口
```
`plugin.json` 格式:
```json
{
"name": "my-hello",
"version": "1.0.0",
"author": "your-name",
"description": "我的第一个插件"
}
```
---