feat: add hybrid llm quality inspection
This commit is contained in:
@@ -16,6 +16,7 @@ vi.mock("../../llm/client", async () => {
|
||||
|
||||
import { extractCandidateFactCard } from "../fact-extractor";
|
||||
import { optimizeArticle } from "../article-optimizer";
|
||||
import { inspectQualityWithLlm } from "../quality-inspector";
|
||||
import { rewriteFailedSections } from "../targeted-rewriter";
|
||||
|
||||
describe("LLM workflow integration", () => {
|
||||
@@ -194,4 +195,77 @@ describe("LLM workflow integration", () => {
|
||||
expect(rewritten.title).toContain("GEO optimization Guide");
|
||||
expect(rewritten.summary).toBe("Original summary");
|
||||
});
|
||||
|
||||
it("uses LLM quality checks to enrich non-failing deterministic checks", async () => {
|
||||
llmMocks.generateValidatedJson.mockResolvedValueOnce({
|
||||
checks: [
|
||||
{
|
||||
rule_id: "platform_fit",
|
||||
status: "warn",
|
||||
evidence: "LLM noticed the article reads like a generic blog post.",
|
||||
reason: "The structure is not specific enough for an official site.",
|
||||
suggested_fix: "Add a clearer brand-owned introduction.",
|
||||
target_agent: "body",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const report = await inspectQualityWithLlm({
|
||||
article: {
|
||||
title: "Example GEO Optimization Guide",
|
||||
summary:
|
||||
"A official site article for Marketing teams about GEO optimization.",
|
||||
body_markdown:
|
||||
"Example Technology Co., Ltd. has 8 years of GEO optimization experience.",
|
||||
image_suggestions: [{ source: "image_1", suggestion: "Use dashboard." }],
|
||||
changed_sections: [],
|
||||
requires_user_confirmation: [],
|
||||
},
|
||||
factCard: confirmedFactCard,
|
||||
platform: "official_site",
|
||||
sourceImages: [{ type: "description", content: "dashboard" }],
|
||||
});
|
||||
|
||||
const platformCheck = report.checks.find(
|
||||
(check) => check.rule_id === "platform_fit",
|
||||
);
|
||||
expect(platformCheck?.status).toBe("warn");
|
||||
expect(platformCheck?.evidence).toContain("LLM noticed");
|
||||
});
|
||||
|
||||
it("does not let LLM downgrade deterministic hard failures", async () => {
|
||||
llmMocks.generateValidatedJson.mockResolvedValueOnce({
|
||||
checks: [
|
||||
{
|
||||
rule_id: "company_name_integrity",
|
||||
status: "pass",
|
||||
evidence: "LLM says it is fine.",
|
||||
reason: "LLM attempted to downgrade a failure.",
|
||||
suggested_fix: "",
|
||||
target_agent: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const report = await inspectQualityWithLlm({
|
||||
article: {
|
||||
title: "Example GEO Optimization Guide",
|
||||
summary:
|
||||
"A official site article for Marketing teams about GEO optimization.",
|
||||
body_markdown: "Example has 8 years of GEO optimization experience.",
|
||||
image_suggestions: [{ source: "image_1", suggestion: "Use dashboard." }],
|
||||
changed_sections: [],
|
||||
requires_user_confirmation: [],
|
||||
},
|
||||
factCard: confirmedFactCard,
|
||||
platform: "official_site",
|
||||
sourceImages: [{ type: "description", content: "dashboard" }],
|
||||
});
|
||||
|
||||
const companyCheck = report.checks.find(
|
||||
(check) => check.rule_id === "company_name_integrity",
|
||||
);
|
||||
expect(companyCheck?.status).toBe("fail");
|
||||
expect(companyCheck?.reason).toContain("公司");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user