feat: use llm for fact extraction
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user