feat: use llm for fact extraction

This commit is contained in:
Codex
2026-06-21 23:43:02 +08:00
parent 864b1c72f9
commit 0c36f4b8a3
2 changed files with 83 additions and 0 deletions
+16
View File
@@ -1,9 +1,25 @@
import type { ArticleInput, CandidateFactCard } from "../domain/types";
import { candidateFactCardSchema } from "../domain/validation";
import { generateValidatedJson } from "../llm/client";
import {
FACT_EXTRACTOR_SYSTEM_PROMPT,
buildFactExtractorPrompt,
} from "../llm/prompts";
export async function extractCandidateFactCard(
input: ArticleInput,
): Promise<CandidateFactCard> {
const llmCard = await generateValidatedJson({
schema: candidateFactCardSchema,
system: FACT_EXTRACTOR_SYSTEM_PROMPT,
prompt: buildFactExtractorPrompt(input),
temperature: 0.1,
});
return llmCard ?? extractCandidateFactCardFallback(input);
}
function extractCandidateFactCardFallback(input: ArticleInput): CandidateFactCard {
const text = `${input.title}\n${input.body}`;
const uncertainItems: string[] = [];
const companyFullName = findCompanyFullName(text);