29 lines
2.6 KiB
TypeScript
29 lines
2.6 KiB
TypeScript
export const LAYOUT_REPLACE_SUPPORT_PROMPT = [
|
||
"只观察这张图中主体商品本身的下缘与支撑方式,不比较其他图片,不根据商品类别或广告文案猜测。",
|
||
"supportType只能选:flush=下缘连续且没有可见独立支脚,包含贴地底座;legs=实际可见独立柜腿、支撑脚或脚轮;suspended=明确悬挂;not_applicable=该类别不适用支撑结构检查(如服装、食品);unclear=主体下缘被完全遮住或图片无法辨认。",
|
||
"这是可见结构识别,不是力学分析:不要因无法证明柜底每处都与地面接触、看不到背面或不确定隐藏的支撑而填写unclear。清楚可见连续下缘而没有独立腿脚就填flush;实际可见腿脚就填legs。",
|
||
"贴地底座的接触阴影不是腿。只有实际看到独立支撑才选legs,不要凭空想象隐藏的脚。关注实际商品,忽略海报图标、数字及其他独立摆件。",
|
||
'只返回JSON,supportType填写上述英文枚举之一:{"supportType":"从枚举中选择","confidence":0.95}。',
|
||
].join("\n");
|
||
|
||
export type LayoutReplaceSupport = "flush" | "legs" | "suspended" | "not_applicable" | "unclear";
|
||
|
||
export function parseLayoutReplaceSupport(text: string) {
|
||
let value: { supportType?: unknown; confidence?: unknown };
|
||
try { value = JSON.parse(text.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "")); }
|
||
catch { throw new Error("商品支撑结构检查未返回有效结论"); }
|
||
if (!value || !["flush", "legs", "suspended", "not_applicable", "unclear"].includes(String(value.supportType)) ||
|
||
typeof value.confidence !== "number" || value.confidence < 0 || value.confidence > 1) throw new Error("商品支撑结构检查不完整");
|
||
return { supportType: value.supportType as LayoutReplaceSupport, confidence: value.confidence };
|
||
}
|
||
|
||
export function compareLayoutReplaceSupport(source: ReturnType<typeof parseLayoutReplaceSupport>, result: ReturnType<typeof parseLayoutReplaceSupport>) {
|
||
if (source.supportType === "not_applicable") return { passed: true, reason: "" };
|
||
if (source.supportType === "unclear" || result.supportType === "unclear" || source.confidence < .8 || result.confidence < .8) {
|
||
return { passed: false, reason: "无法可靠确认商品下缘的支撑结构" };
|
||
}
|
||
const names = { flush: "贴地底座", legs: "独立腿脚或脚轮", suspended: "悬挂", not_applicable: "类别不适用", unclear: "不清晰" };
|
||
return source.supportType === result.supportType ? { passed: true, reason: "" }
|
||
: { passed: false, reason: `原商品为${names[source.supportType]},结果却为${names[result.supportType]},支撑结构已改变` };
|
||
}
|