feat: Docker 打包、交付链路与命名脱敏

镜像与构建
- 六阶段 Dockerfile(base/wheels/deps/manifest/core|guard),core 不含 torch
- 构建期自证:gen_manifest --strict 拦未登记模块,core 阶段重算 sha256
- compose 四服务 host 网络(llm.url 强制回环),config.core/local 可挂载覆盖

无 docker 环境的四段链路
- pull_oci_image.py      直拉 OCI 镜像 rootfs(纯标准库,走加速器)
- replay_image_build.sh  按 stage chroot 重放 Dockerfile
- run_image_chroot.sh    等价 docker run(uid 10001 + 入口 + host 网络)
- pack_image.py          封成 docker save 格式包,自带 diff_id 校验

交付
- make_package.sh 生成自包含目录:镜像包 + 溯源清单 + 构建输入 + 脚本 + 源码快照
- 文档:从零复现指南、docker 打包方案、镜像构建限制与替代方案、交付包 README

命名
- Qwen 品牌名统一替换为 large_model / small_model / large_model_guard,
  覆盖 vLLM 服务名、模型目录、配置、脚本、测试与文档
- 模型架构字段(architectures / model_type / tokenizer_class)属上游定义,
  改名会导致加载失败,保留原值;check_local_model.py 的架构判断同理

验证:smoke 6/6;test.py 20 通过 0 失败 1 警告;gen --strict 67 文件 / 22 进镜像
This commit is contained in:
chenleixu committed 2026-11-27 18:20:16 +00:00
1 parent bfdc5e9168
commit b82e44ec32
46 files changed
+10271 -484

No files matched your search

+82 -1
View File
@@ -446,6 +446,47 @@ local function input_prompt(part, index, total)
return string.format("(part %d of %d)\n%s", index, total, part)
end
-- 二级复核:0.6B 判危险后,用更大的模型对同一段原文再判一次。
-- 传的是「同一份原文 + 同一份上下文」,不是 0.6B 的判决对象;0.6B 的类别最多
-- 拼进 prompt 当弱提示。返回 nil 表示"复核不可用",调用方必须回落首判(fail-closed)。
local function review_call(kind, part, index, total, context, first)
local model = config.review_model
if not model then return nil end
local prefix = config.review_prefix or ""
local request
if kind == "output" then
local prompt = (type(context) == "string" and context ~= "") and context
or "Evaluate the safety of the assistant reply."
request = { task = "response_moderation",
prompt = prefix ~= "" and (prefix .. "\n\n" .. prompt) or prompt,
response = part }
else
local text = input_prompt(part, index, total)
if type(context) == "string" and context ~= "" then
text = context .. "\n\n" .. text
end
request = { task = "prompt_moderation",
prompt = prefix ~= "" and (prefix .. "\n\n" .. text) or text }
end
local ok, result = pcall(host.llm.call, model, request)
if not ok or type(result) ~= "table" then return nil end
if result.safety == "Safe" then return { allow = true } end
if result.safety == "Controversial" and not config.block_controversial then
return { allow = true }
end
if result.safety == "Unsafe" or result.safety == "Controversial" then
local categories = type(result.categories) == "table" and result.categories or {}
local first_cat = categories[1]
local category = type(first_cat) == "string" and first_cat
or (type(first) == "table" and first.category) or "other"
return { allow = false, category = category }
end
return nil -- safety 落在枚举外,视为复核不可用
end
local function judge_call(kind, part, index, total, context)
local request
if kind == "output" then
@@ -479,7 +520,20 @@ local function judge_call(kind, part, index, total, context)
if safety == "Unsafe" or safety == "Controversial" then
local categories = type(result.categories) == "table" and result.categories or {}
local first = categories[1]
return { allow = false, category = type(first) == "string" and first or "other" }
local verdict = { allow = false, category = type(first) == "string" and first or "other" }
-- 二级复核:默认只放松(8B 说 Safe 就放行),override 则让 8B 终裁
local want = (safety == "Unsafe") or config.review_scope_controversial
if want and config.review_model then
local second = review_call(kind, part, index, total, context, verdict)
if second then
if config.review_mode == "override" or second.allow == true then
return second
end
end
end
-- 复核不可用 / 复核也判危险:保持首判(fail-closed)
return verdict
end
-- safety 落在枚举外说明模型输出不可信,按 fail-closed 处理
return nil, "judge_invalid_safety"
@@ -777,8 +831,35 @@ function plugin.init(ctx, options)
error("response_guard: config.multiturn_context_bytes must not exceed " .. MAX_CONTEXT_BYTES)
end
-- 二级复核配置:review_model 必须在宿主的 llm.allow 里,否则调用直接失败
local review_model = o.review_model
if review_model ~= nil and (type(review_model) ~= "string" or review_model == "") then
error("response_guard: config.review_model must be a non-empty string or absent")
end
local review_mode = o.review_mode or "relax"
if review_mode ~= "relax" and review_mode ~= "override" then
error("response_guard: config.review_mode must be 'relax' or 'override'")
end
local review_scope_controversial = false
if o.review_scope ~= nil then
if type(o.review_scope) ~= "table" then
error("response_guard: config.review_scope must be a list like [Unsafe]")
end
for _, name in ipairs(o.review_scope) do
if name == "Controversial" then review_scope_controversial = true end
end
end
local review_prefix = o.review_prefix
if review_prefix ~= nil and (type(review_prefix) ~= "string" or review_prefix == "") then
error("response_guard: config.review_prefix must be a non-empty string or absent")
end
config = {
model = o.model,
review_model = review_model,
review_mode = review_mode,
review_scope_controversial = review_scope_controversial,
review_prefix = review_prefix,
prompt_prefix = prompt_prefix,
stub_model = stub_model,
stub_max_tokens = stub_max_tokens,