上一版把自定义指令塞进 prompt、并在 response_moderation 里丢了用户提问,与 Qwen3Guard-Gen 的实际用法不符: - 输入:prompt 就是待审原文,不再加指令和 <BEGIN CONTENT> 包裹 - 输出:prompt=用户原问题(截断 2000 字节)、response=模型输出,恢复问答上下文 - 自定义指令改为可选的 prompt_prefix,默认不发送 宿主的 parse_guard_output 与九个类别名逐字对应 Qwen3Guard-Gen,已在注释和自检脚本里写明必须用该族模型。 验证:verify_plugins.py 104 项全通过;用假模型目录跑 load_settings + LLMRegistry, 确认 5 插件/1 启用、guard_model adapter 与两项能力正常建立;luac -p 通过。
77 lines
2.3 KiB
YAML
77 lines
2.3 KiB
YAML
upstream: http://127.0.0.1:8000
|
||
listen_host: 0.0.0.0
|
||
listen_port: 8080
|
||
|
||
limits:
|
||
max_sessions: 4
|
||
# 本地模型串行推理(max_concurrency 固定 1),按单段最慢几十毫秒到数秒留
|
||
hook_timeout_seconds: 120
|
||
upstream_timeout_seconds: 120
|
||
max_attachment_files: 8
|
||
max_attachment_fields: 128
|
||
max_attachment_text_bytes: 1048576
|
||
max_attachment_unpacked_bytes: 33554432
|
||
max_attachment_zip_entries: 2048
|
||
attachment_timeout_seconds: 30
|
||
max_attachment_reads: 64
|
||
|
||
# 本地守卫模型。必须是 Qwen3Guard-Gen(0.6B/4B/8B):宿主的 parse_guard_output 按它的
|
||
# "Safety: / Categories: / Refusal:" 格式与九个类别名解析,换别的模型会全部 503。
|
||
# file 指向 HuggingFace 目录(config.json + 权重 + tokenizer),缺失时宿主启动即失败。
|
||
# 部署前跑 tools/check_local_model.py 自检。
|
||
llm:
|
||
- id: guard_model
|
||
type: guard
|
||
file: models/guard_model
|
||
load:
|
||
device: cpu
|
||
dtype: auto
|
||
limits:
|
||
max_input_tokens: 8192
|
||
max_new_tokens: 64
|
||
timeout_seconds: 60
|
||
queue_size: 32
|
||
|
||
plugins:
|
||
- id: response-guard
|
||
file: plugins/response_guard.lua
|
||
match:
|
||
paths: ["/v1/chat/completions"]
|
||
# 必须与 llm 段的 id 一致,否则 host.llm.call 一定失败
|
||
llm:
|
||
allow: [guard_model]
|
||
config:
|
||
model: guard_model
|
||
block_status: 400
|
||
# buffered 则整条响应只判一次,但客户端看不到增量
|
||
stream_mode: incremental
|
||
flush_chars: 512
|
||
force_flush_bytes: 4096
|
||
# 8 段 × judge_chunk_bytes
|
||
max_buffer_bytes: 65536
|
||
judge_chunk_bytes: 8192
|
||
check_input: true
|
||
check_output: true
|
||
# Controversial 也按不安全处理;误伤多时设 false
|
||
block_controversial: true
|
||
# 拦截后替换给上游的占位请求:客户端没给 model 时用它兜底
|
||
# stub_model: your-upstream-model
|
||
# stub_max_tokens: false
|
||
|
||
- id: stream-redact
|
||
enabled: false
|
||
file: plugins/stream_redact.lua
|
||
match:
|
||
paths: ["/v1/chat/completions"]
|
||
config:
|
||
content_path: choices.*.delta.content
|
||
max_buffer_bytes: 262144
|
||
|
||
- id: request-rewrite
|
||
enabled: false
|
||
file: plugins/request_rewrite.lua
|
||
match:
|
||
paths: ["/v1/chat/completions"]
|
||
config:
|
||
prefix: "[checked] "
|