Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateText, type LLMConfig, type ChatMessage } from '@/lib/llm-client';
import { detectDocumentType, type DocumentType } from '@/lib/document-type';
import { detectDocumentType, detectEarningsContext, type DocumentType } from '@/lib/document-type';
import { getPromptForDocumentType } from '@/lib/prompts';
import type { SummaryMetadata, ExtractionMode } from '@/types/summaryMetadata';

Expand Down Expand Up @@ -109,7 +109,7 @@ async function handleSummarize(
const pdfData = await fetchPDF(pdfUrl);

// LLMで要約
const result = await summarizeWithLLM(pdfData, settings, documentType, extractionMode);
const result = await summarizeWithLLM(pdfData, settings, documentType, extractionMode, title);

return result;
} catch (error) {
Expand Down Expand Up @@ -154,7 +154,8 @@ async function summarizeWithLLM(
pdfData: ArrayBuffer,
settings: Settings,
documentType: DocumentType,
extractionMode: ExtractionMode
extractionMode: ExtractionMode,
title: string
): Promise<{ summary: string; metadata: SummaryMetadata }> {
try {
// 設定の検証
Expand Down Expand Up @@ -194,14 +195,13 @@ async function summarizeWithLLM(
};

// 文書タイプ別プロンプトを使用
const promptText = getPromptForDocumentType(documentType, pdfText);
const earningsContext = documentType === 'earnings' ? detectEarningsContext(title) : undefined;
const { system, user } = getPromptForDocumentType(documentType, pdfText, earningsContext);

// メッセージを構築
const messages: ChatMessage[] = [
{
role: 'user',
content: promptText,
},
{ role: 'system', content: system },
{ role: 'user', content: user },
];

// 統一LLMクライアントを使用して要約を生成
Expand Down
54 changes: 54 additions & 0 deletions src/lib/document-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
* 判定順序が重要:誤判定を防ぐため、特定の順序で判定を行う。
*/

/**
* 決算期区分
*/
export type EarningsPeriod = 'q1' | 'q2' | 'q3' | 'fullYear';

/**
* 会計基準
*/
export type AccountingStandard = 'jpGaap' | 'ifrs' | 'usGaap';

/**
* 決算短信のコンテキスト情報
*/
export interface EarningsContext {
period: EarningsPeriod;
accountingStandard: AccountingStandard;
isConsolidated: boolean;
}

/**
* 文書タイプ
*/
Expand Down Expand Up @@ -69,6 +88,41 @@ export function detectDocumentType(title: string): DocumentType {
return 'other';
}

/**
* 決算短信タイトルからコンテキスト情報を検出
*
* @param title 開示情報のタイトル
* @returns 決算コンテキスト(期区分・会計基準・連結/個別)
*/
export function detectEarningsContext(title: string): EarningsContext {
// 期区分の判定
let period: EarningsPeriod;
if (/第1四半期|1Q/.test(title)) {
period = 'q1';
} else if (/第2四半期|2Q|中間/.test(title)) {
period = 'q2';
} else if (/第3四半期|3Q/.test(title)) {
period = 'q3';
} else {
period = 'fullYear';
}

// 会計基準の判定
let accountingStandard: AccountingStandard;
if (/IFRS|国際会計基準/.test(title)) {
accountingStandard = 'ifrs';
} else if (/米国基準/.test(title)) {
accountingStandard = 'usGaap';
} else {
accountingStandard = 'jpGaap';
}

// 連結/個別の判定
const isConsolidated = !/個別|単体/.test(title);

return { period, accountingStandard, isConsolidated };
}

/**
* 文書タイプの表示名を取得(UI表示用)
*
Expand Down
Loading