match.paths 里配了 /v1/completions,但插件默认内容路径是 choices.*.delta.content / message.content,而 legacy completions 的正文在 choices[*].text,不在路径上,导致这类响应不经过审核直接放行。显式配置 content_path_stream / content_path_full 同时覆盖两种格式。 已用 middleware.config.load_settings 校验通过。
139 lines
5.5 KiB
YAML
139 lines
5.5 KiB
YAML
upstream: http://127.0.0.1:8000
|
||
listen_host: 0.0.0.0
|
||
listen_port: 8080
|
||
|
||
limits:
|
||
max_sessions: 4
|
||
# 判定走远程 /chat/completions:单次 1~5s,最多切 8 段,留足余量
|
||
hook_timeout_seconds: 45
|
||
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
|
||
|
||
# 本地守卫模型已停用,判定统一走下面的 OpenAI 兼容接口。
|
||
# models/guard_model 在当前环境中不存在,保留本段会导致网关启动失败,故整段注释。
|
||
# 若要把本地守卫模型加回来:取消注释,并把模型文件放到 models/guard_model。
|
||
# llm:
|
||
# - id: guard_model
|
||
# type: guard
|
||
# file: models/guard_model
|
||
# load: {device: cpu}
|
||
# limits:
|
||
# max_input_tokens: 8192
|
||
# max_new_tokens: 32
|
||
# timeout_seconds: 30
|
||
# queue_size: 8
|
||
|
||
plugins:
|
||
# ---------------------------------------------------------------------------
|
||
# 旧协议遗留(/upload),依赖上面已停用的 guard_model,并且宿主没有 host.files
|
||
# 能力,实际无法工作。文件保留在 plugins/ 下,配置停用;需要时再恢复。
|
||
# ---------------------------------------------------------------------------
|
||
- id: file-content-review
|
||
enabled: false
|
||
file: plugins/file_content_review.lua
|
||
match:
|
||
paths: ["/upload"]
|
||
config:
|
||
model: guard_model
|
||
allowed_extensions: [txt, doc, docx]
|
||
max_review_bytes: 8192
|
||
max_files: 8
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 旧协议遗留(/chat/stream),外部审核服务白名单转发,本来就是停用状态。
|
||
# ---------------------------------------------------------------------------
|
||
- id: network-review
|
||
enabled: false
|
||
file: plugins/network_review.lua
|
||
match:
|
||
paths: ["/chat/stream"]
|
||
network:
|
||
allow:
|
||
- domain: review.example.com
|
||
scheme: https
|
||
ports: [443]
|
||
timeout_seconds: 5
|
||
max_response_bytes: 1048576
|
||
config:
|
||
url: https://review.example.com/check
|
||
fields: [messages]
|
||
headers: {x-api-key: "injected-by-admin"}
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 输入 + 输出内容安全(OpenAI 协议)
|
||
# 请求侧:判定不通过 → 请求体换成 stub(原文不发给模型)→ 响应侧返回 400
|
||
# 响应侧:逐段审核 → 脱敏 → 放行;不安全/审核不可用 → OpenAI 错误体
|
||
# ---------------------------------------------------------------------------
|
||
- id: response-guard
|
||
file: plugins/response_guard.lua
|
||
match:
|
||
paths: ["/v1/chat/completions", "/v1/completions"]
|
||
network:
|
||
allow:
|
||
- domain: ai.leapstella.com
|
||
scheme: https
|
||
ports: [443]
|
||
timeout_seconds: 20
|
||
max_response_bytes: 1048576
|
||
config:
|
||
base_url: https://ai.leapstella.com/v1
|
||
# 部署时填入自己的密钥;仓库里只有占位符,真实密钥不入库
|
||
api_key: "sk-REPLACE_ME"
|
||
model: deepseek-flash
|
||
# 拦截状态码:400 = OpenAI 内容策略拒绝的标准形态
|
||
block_status: 400
|
||
# incremental: 攒够 flush_chars 且遇到句边界就审核放行(有增量输出)
|
||
# buffered : 整条响应结束再一次审核(1 次判定,但客户端看不到增量)
|
||
stream_mode: incremental
|
||
flush_chars: 512
|
||
force_flush_bytes: 4096
|
||
# 上限与判定能力对齐:8 段 × judge_chunk_bytes(16KB) = 128KB
|
||
max_buffer_bytes: 131072
|
||
# 必须显式列出两条路径:
|
||
# chat 格式正文在 choices[*].delta.content / message.content
|
||
# legacy completions(match.paths 里配了 /v1/completions)正文在 choices[*].text
|
||
# 只用默认值会漏审 completions 的正文,风险内容直接放行。
|
||
content_path_stream: ["choices.*.delta.content", "choices.*.text"]
|
||
content_path_full: ["choices.*.message.content", "choices.*.text"]
|
||
# 工具调用参数也要审核时,在上面数组里追加:
|
||
# "choices.*.delta.tool_calls.*.function.arguments"
|
||
# "choices.*.message.tool_calls.*.function.arguments"
|
||
|
||
judge_chunk_bytes: 16384
|
||
judge_max_tokens: 512
|
||
# deepseek 系列默认带思维链,判定用不到;none 可省 ~0.3s 且避免思维链吃光 token。
|
||
# 换后端若报 400,删掉这一行即可。
|
||
judge_reasoning_effort: none
|
||
check_input: true
|
||
check_output: true
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 最后一条 user 消息打标;会重写整个 body,默认关闭
|
||
# ---------------------------------------------------------------------------
|
||
- id: request-rewrite
|
||
enabled: false
|
||
file: plugins/request_rewrite.lua
|
||
match:
|
||
paths: ["/v1/chat/completions"]
|
||
config:
|
||
prefix: "[checked] "
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 全缓冲 PII 兜底(跨帧拆分的证件号/手机号)
|
||
# 代价:流式退化为一次性输出,与 response_guard 的增量放行冲突,默认关闭
|
||
# ---------------------------------------------------------------------------
|
||
- 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
|