add README.md 文档

This commit is contained in:
2026-07-21 16:14:02 +08:00
parent 482f8df508
commit 95ef842d92
3 changed files with 79 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
# 插件目录
每个子目录代表一个 Worker 插件,包含以下约定结构:
```text
plugin_name/
├── init.py # 提供 create_workers 和 cleanup 工厂函数
├── router/ # RPC 方法实现(使用 @rpc_method)
├── models/ # 由 gen_models 生成的 Pydantic 模型(自动生成,勿手动修改)
├── global_var.py # 全局状态管理(如数据库连接)
└── README.md # 插件说明
```
## 开发新插件
1. 在 `config/workers/` 下创建同名目录,编写路由 TOML
2. 运行 `uv run gen_models config/workers/<plugin> src/plugins/<plugin>`
3. 实现 `router/*.py` 中的业务逻辑
4. 在 `__init__.py` 中实现 `create_workers` 工厂函数
+38
View File
@@ -0,0 +1,38 @@
# Doubao Worker 插件
火山引擎豆包(Doubao)视觉理解模型集成,支持图像分析。
## 功能
- 接收 base64 编码的图片和提示词
- 调用火山引擎豆包视觉模型(支持思考模式)
- 返回模型描述结果
## 配置
在 `config/workers/doubao/config.toml` 中设置:
- `api_key`:火山引擎 API Key(也可通过环境变量 `VOLC_ACCESSKEY` 提供)
- `base_url`:API 端点(默认 `https://ark.cn-beijing.volces.com/api/v3`)
- `model`:模型名称(如 `doubao-seed-evolving`)
## 调用示例
```http
POST /api/v1/doubao/analyze
Content-Type: application/json
{
"image_base64": "data:image/png;base64,iVBORw0KG...",
"prompt": "描述这个图片的内容"
}
```
响应示例:
```json
{
"result": "图片中是一只猫坐在沙发上...",
"error": ""
}
```
+22
View File
@@ -0,0 +1,22 @@
# Example Worker 插件
演示 `@rpc_method` 与显式模型绑定的用法。
## 实现的功能
- 加、减、乘、除四则运算(GET / POST)
- 基于 `modelvault` 的访问计数器
## 如何工作
1. 配置位于 `config/workers/example/*.toml`
2. 模型由 `gen_models` 生成,位于 `models/pydantic.py`
3. 路由实现在 `router/` 下,使用 `@rpc_method` 装饰
4. 工厂函数 `create_workers` 初始化数据库并启动 Worker
## 调用示例
```bash
curl "http://localhost:8000/api/v1/calc/add?a=3&b=4"
# {"result":7,"operation":"add","timestamp":...}
```