feat: show backend optimization progress
This commit is contained in:
@@ -29,6 +29,12 @@ const REQUIRED_RULES: QualityRuleId[] = [
|
||||
"context_sensitive_terms",
|
||||
];
|
||||
|
||||
const HARD_FAILURE_RULES = new Set<QualityRuleId>([
|
||||
"company_name_integrity",
|
||||
"hallucination_risk",
|
||||
"claim_consistency",
|
||||
]);
|
||||
|
||||
const llmQaPatchSchema = z.object({
|
||||
checks: z.array(qaCheckSchema).default([]),
|
||||
});
|
||||
@@ -78,9 +84,13 @@ export async function inspectQualityWithLlm(
|
||||
if (deterministicCheck.status === "fail") {
|
||||
return deterministicCheck;
|
||||
}
|
||||
const status =
|
||||
llmCheck.status === "fail" && !HARD_FAILURE_RULES.has(deterministicCheck.rule_id)
|
||||
? "warn"
|
||||
: llmCheck.status;
|
||||
return {
|
||||
...deterministicCheck,
|
||||
status: llmCheck.status,
|
||||
status,
|
||||
evidence: llmCheck.evidence,
|
||||
reason: llmCheck.reason,
|
||||
suggested_fix: llmCheck.suggested_fix,
|
||||
@@ -107,14 +117,15 @@ function inspectRule(
|
||||
const lower = combined.toLowerCase();
|
||||
|
||||
if (ruleId === "industry_alignment") {
|
||||
const aligned = lower.includes(factCard.target_industry.toLowerCase());
|
||||
const targetIndustry = factCard.target_industry.trim().toLowerCase();
|
||||
const aligned = targetIndustry.length === 0 || lower.includes(targetIndustry);
|
||||
return check(
|
||||
ruleId,
|
||||
aligned ? "pass" : "fail",
|
||||
aligned ? "pass" : "warn",
|
||||
aligned ? factCard.target_industry : article.summary,
|
||||
aligned
|
||||
? "文章内容与事实卡确认的目标行业一致。"
|
||||
: "文章内容偏离事实卡确认的目标行业。",
|
||||
: "文章可能没有充分体现事实卡确认的目标行业。",
|
||||
"围绕事实卡确认的目标行业重写相关段落。",
|
||||
aligned ? null : "body",
|
||||
);
|
||||
@@ -254,11 +265,30 @@ function check(
|
||||
|
||||
function findUnsupportedNumbers(text: string, factCard: ConfirmedFactCard) {
|
||||
const allowed = new Set(
|
||||
[factCard.experience_years]
|
||||
.filter((value): value is number => typeof value === "number")
|
||||
[
|
||||
factCard.experience_years,
|
||||
...extractNumbersFromFactCard(factCard),
|
||||
]
|
||||
.filter((value): value is number | string =>
|
||||
typeof value === "number" || typeof value === "string",
|
||||
)
|
||||
.map(String),
|
||||
);
|
||||
return [...text.matchAll(/\b\d{1,4}\b/g)]
|
||||
.map((match) => match[0])
|
||||
.filter((number) => !allowed.has(number));
|
||||
}
|
||||
|
||||
function extractNumbersFromFactCard(factCard: ConfirmedFactCard) {
|
||||
return [
|
||||
factCard.company_full_name,
|
||||
...factCard.company_short_names,
|
||||
...factCard.brand_names,
|
||||
...factCard.product_names,
|
||||
factCard.target_industry,
|
||||
factCard.target_audience,
|
||||
...factCard.core_claims,
|
||||
...factCard.forbidden_claims,
|
||||
...factCard.image_topics,
|
||||
].flatMap((value) => [...value.matchAll(/\b\d{1,4}\b/g)].map((match) => match[0]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user