add first commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
# 配置文件说明
|
||||||
|
|
||||||
|
本目录存放应用所有 TOML 配置文件。
|
||||||
|
|
||||||
|
## 主要文件
|
||||||
|
|
||||||
|
- `config.toml`:应用主配置(环境、服务器、日志、安全、缓存等)
|
||||||
|
- `zenoh_config.json5`:Zenoh 会话配置(JSON5 格式)
|
||||||
|
- `workers/config.toml`:Worker 插件加载列表(指定模块、工厂函数、副本数)
|
||||||
|
- `workers/<worker_type>/*.toml`:每个 Worker 的路由定义(如 `add.toml`, `divide.toml`)
|
||||||
|
|
||||||
|
## Worker 路由配置格式
|
||||||
|
|
||||||
|
每个接口文件(如 `add.toml`)包含 HTTP 方法节(`[GET]`, `[POST]` 等):
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[GET]
|
||||||
|
summary = "Add two numbers"
|
||||||
|
params = ["a: float", "b: float"]
|
||||||
|
response_model = { result = { type = "float", required = true }, operation = { type = "str", default = "add" } }
|
||||||
|
```
|
||||||
|
|
||||||
|
执行 `uv run gen_models config/workers/example src/plugins/example` 可自动生成对应的 Pydantic 模型。
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[worker]
|
||||||
|
name = "auth"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "鉴权管理"
|
||||||
|
config_version = "1.0"
|
||||||
|
defaults = { method = "GET", ttl = 30, timeout = 2.0, auth_required = true, cacheable = false }
|
||||||
|
|
||||||
|
[worker.registration]
|
||||||
|
router_prefix = "/auth"
|
||||||
|
tags = ["auth"]
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[POST]
|
||||||
|
cacheable = false
|
||||||
|
auth_required = false
|
||||||
|
summary = "登录"
|
||||||
|
docstring = "根据用户名和密码进行登录,登录成功返回token,获取请求需带式token进行请求"
|
||||||
|
params = ["username: str", "password: str"]
|
||||||
|
|
||||||
|
[POST.response_model]
|
||||||
|
result = {type = "str", required = true}
|
||||||
|
token = {type = "str", required = true}
|
||||||
|
message = {type = "str", required = true}
|
||||||
|
timestamp = {type = "float", required = false}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
[[workers]]
|
||||||
|
type = "example"
|
||||||
|
module = "plugins.example"
|
||||||
|
factory = "create_workers"
|
||||||
|
cleanup = "cleanup"
|
||||||
|
count = 3
|
||||||
|
|
||||||
|
[workers.config]
|
||||||
|
type = "example"
|
||||||
|
data_dir = "./data"
|
||||||
|
|
||||||
|
[[workers]]
|
||||||
|
type = "doubao"
|
||||||
|
module = "plugins.doubao"
|
||||||
|
factory = "create_workers"
|
||||||
|
cleanup = "cleanup"
|
||||||
|
count = 3
|
||||||
|
|
||||||
|
[workers.config]
|
||||||
|
type = "doubao"
|
||||||
|
api_key = " ark-b149df84-a057-4ca0-b1a0-82a22c4e3c70-33cde" # 或通过环境变量 VOLC_ACCESSKEY 提供
|
||||||
|
base_url = "https://ark.cn-beijing.volces.com/api/v3"
|
||||||
|
model = "doubao-seed-evolving"
|
||||||
|
|
||||||
|
[[workers]]
|
||||||
|
type = "auth"
|
||||||
|
module = "plugins.auth"
|
||||||
|
factory = "create_workers"
|
||||||
|
cleanup = "cleanup"
|
||||||
|
count = 3
|
||||||
|
|
||||||
|
[workers.config]
|
||||||
|
type = "auth"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[POST]
|
||||||
|
summary = "分析图片内容"
|
||||||
|
docstring = "发送图片(base64或路径)到豆包视觉模型,返回描述"
|
||||||
|
params = [
|
||||||
|
"image_base64: str",
|
||||||
|
"prompt: str"
|
||||||
|
]
|
||||||
|
response_model = { result = { type = "str", required = true }, error = { type = "str", required = false, default = "" } }
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[worker]
|
||||||
|
name = "doubao"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "火山引擎豆包视觉理解 worker"
|
||||||
|
config_version = "1.0"
|
||||||
|
defaults = { method = "POST", timeout = 30.0, auth_required = false }
|
||||||
|
|
||||||
|
[worker.registration]
|
||||||
|
router_prefix = "/doubao"
|
||||||
|
tags = ["vision", "ai"]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# add 接口 — 按请求类型分节
|
||||||
|
# subject 会带上方法后缀: example.add.GET / example.add.POST
|
||||||
|
|
||||||
|
[GET]
|
||||||
|
cacheable = true
|
||||||
|
summary = "Add two numbers"
|
||||||
|
docstring = "Add two numbers via GET query params"
|
||||||
|
params = ["a: float", "b: float"]
|
||||||
|
auth_required = false
|
||||||
|
|
||||||
|
[GET.response_model]
|
||||||
|
result = { type = "float", required = true }
|
||||||
|
operation = { type = "str", default = "add" }
|
||||||
|
timestamp = { type = "float", required = false, default = 0.0 }
|
||||||
|
|
||||||
|
[POST]
|
||||||
|
cacheable = true
|
||||||
|
summary = "Add two numbers (POST)"
|
||||||
|
docstring = "Add two numbers via POST JSON body"
|
||||||
|
params = ["a: float", "b: float"]
|
||||||
|
|
||||||
|
[POST.response_model]
|
||||||
|
result = { type = "float", required = true }
|
||||||
|
operation = { type = "str", default = "add" }
|
||||||
|
timestamp = { type = "float", required = false, default = 0.0 }
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[worker]
|
||||||
|
name = "example"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "chongming worker example — demonstrates new config features"
|
||||||
|
config_version = "1.0"
|
||||||
|
defaults = { method = "GET", ttl = 30, timeout = 2.0, auth_required = true, cacheable = false }
|
||||||
|
|
||||||
|
[worker.registration]
|
||||||
|
router_prefix = "/calc"
|
||||||
|
tags = ["example"]
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# count.toml
|
||||||
|
[GET]
|
||||||
|
summary = "Get visit count and increment"
|
||||||
|
docstring = "Increments a counter and returns current value"
|
||||||
|
params = [] # 无参数
|
||||||
|
response_model = { name = { type = "str", required = true }, value = { type = "int", required = true } }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# divide 接口
|
||||||
|
|
||||||
|
[GET]
|
||||||
|
summary = "Divide two numbers"
|
||||||
|
docstring = "Divide two numbers via GET query params (a / b). Returns error if b == 0."
|
||||||
|
params = ["a: float", "b: float"]
|
||||||
|
|
||||||
|
[GET.response_model]
|
||||||
|
result = { type = "float", required = false, default = 0.0 }
|
||||||
|
operation = { type = "str", default = "divide" }
|
||||||
|
timestamp = { type = "float", required = false, default = 0.0 }
|
||||||
|
error = { type = "str", required = false, default = "" }
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# multiply 接口
|
||||||
|
|
||||||
|
[GET]
|
||||||
|
summary = "Multiply two numbers"
|
||||||
|
docstring = "Multiply two numbers via GET query params (a * b)"
|
||||||
|
params = ["a: float", "b: float"]
|
||||||
|
|
||||||
|
[GET.response_model]
|
||||||
|
result = { type = "float", required = true }
|
||||||
|
operation = { type = "str", default = "multiply" }
|
||||||
|
timestamp = { type = "float", required = false, default = 0.0 }
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# subtract 接口
|
||||||
|
|
||||||
|
[GET]
|
||||||
|
summary = "Subtract two numbers"
|
||||||
|
docstring = "Subtract two numbers via GET query params (a - b)"
|
||||||
|
params = ["a: float", "b: float"]
|
||||||
|
|
||||||
|
[GET.response_model]
|
||||||
|
result = { type = "float", required = true }
|
||||||
|
operation = { type = "str", default = "subtract" }
|
||||||
|
timestamp = { type = "float", required = false, default = 0.0 }
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
mode: "peer",
|
||||||
|
connect: {
|
||||||
|
endpoints: ["tcp/127.0.0.1:7447"],
|
||||||
|
},
|
||||||
|
scouting: {
|
||||||
|
multicast: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
transport: {
|
||||||
|
shared_memory: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user