Fix CIM template data linkage issues - update field mapping to use proper nested paths
This commit is contained in:
@@ -461,9 +461,13 @@ export class OptimizedAgenticRAGProcessor {
|
||||
// Use the existing LLM service to generate CIM review
|
||||
const result = await llmService.processCIMDocument(text, 'BPCP CIM Review Template');
|
||||
|
||||
// Generate a comprehensive summary from the analysis data
|
||||
const analysisData = result.jsonOutput || {} as CIMReview;
|
||||
const summary = this.generateSummaryFromAnalysis(analysisData);
|
||||
|
||||
return {
|
||||
summary: 'Document processed with optimized agentic RAG',
|
||||
analysisData: result.jsonOutput || {} as CIMReview
|
||||
summary,
|
||||
analysisData
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(`Failed to generate LLM analysis for document: ${documentId}`, error);
|
||||
@@ -474,6 +478,114 @@ export class OptimizedAgenticRAGProcessor {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a comprehensive summary from analysis data
|
||||
*/
|
||||
private generateSummaryFromAnalysis(analysisData: CIMReview): string {
|
||||
let summary = '# CIM Review Summary\n\n';
|
||||
|
||||
// Add deal overview
|
||||
if (analysisData.dealOverview?.targetCompanyName) {
|
||||
summary += `## Deal Overview\n\n`;
|
||||
summary += `**Target Company:** ${analysisData.dealOverview.targetCompanyName}\n\n`;
|
||||
|
||||
if (analysisData.dealOverview.industrySector) {
|
||||
summary += `**Industry:** ${analysisData.dealOverview.industrySector}\n\n`;
|
||||
}
|
||||
if (analysisData.dealOverview.transactionType) {
|
||||
summary += `**Transaction Type:** ${analysisData.dealOverview.transactionType}\n\n`;
|
||||
}
|
||||
if (analysisData.dealOverview.geography) {
|
||||
summary += `**Geography:** ${analysisData.dealOverview.geography}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add financial summary
|
||||
if (analysisData.financialSummary?.financials) {
|
||||
summary += `## Financial Summary\n\n`;
|
||||
const financials = analysisData.financialSummary.financials;
|
||||
|
||||
if (financials.fy3) {
|
||||
summary += `### FY3 (Latest)\n\n`;
|
||||
if (financials.fy3.revenue) summary += `- **Revenue:** ${financials.fy3.revenue}\n`;
|
||||
if (financials.fy3.ebitda) summary += `- **EBITDA:** ${financials.fy3.ebitda}\n`;
|
||||
if (financials.fy3.ebitdaMargin) summary += `- **EBITDA Margin:** ${financials.fy3.ebitdaMargin}\n`;
|
||||
if (financials.fy3.revenueGrowth) summary += `- **Revenue Growth:** ${financials.fy3.revenueGrowth}\n\n`;
|
||||
}
|
||||
|
||||
if (financials.fy2) {
|
||||
summary += `### FY2\n\n`;
|
||||
if (financials.fy2.revenue) summary += `- **Revenue:** ${financials.fy2.revenue}\n`;
|
||||
if (financials.fy2.ebitda) summary += `- **EBITDA:** ${financials.fy2.ebitda}\n`;
|
||||
if (financials.fy2.ebitdaMargin) summary += `- **EBITDA Margin:** ${financials.fy2.ebitdaMargin}\n`;
|
||||
if (financials.fy2.revenueGrowth) summary += `- **Revenue Growth:** ${financials.fy2.revenueGrowth}\n\n`;
|
||||
}
|
||||
|
||||
if (financials.fy1) {
|
||||
summary += `### FY1\n\n`;
|
||||
if (financials.fy1.revenue) summary += `- **Revenue:** ${financials.fy1.revenue}\n`;
|
||||
if (financials.fy1.ebitda) summary += `- **EBITDA:** ${financials.fy1.ebitda}\n`;
|
||||
if (financials.fy1.ebitdaMargin) summary += `- **EBITDA Margin:** ${financials.fy1.ebitdaMargin}\n`;
|
||||
if (financials.fy1.revenueGrowth) summary += `- **Revenue Growth:** ${financials.fy1.revenueGrowth}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add business description
|
||||
if (analysisData.businessDescription?.coreOperationsSummary) {
|
||||
summary += `## Business Description\n\n`;
|
||||
summary += `**Core Operations:** ${analysisData.businessDescription.coreOperationsSummary}\n\n`;
|
||||
|
||||
if (analysisData.businessDescription.keyProductsServices) {
|
||||
summary += `**Key Products/Services:** ${analysisData.businessDescription.keyProductsServices}\n\n`;
|
||||
}
|
||||
if (analysisData.businessDescription.uniqueValueProposition) {
|
||||
summary += `**Unique Value Proposition:** ${analysisData.businessDescription.uniqueValueProposition}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add key questions and next steps
|
||||
if (analysisData.keyQuestionsNextSteps?.criticalQuestions) {
|
||||
summary += `## Key Questions & Next Steps\n\n`;
|
||||
summary += `**Critical Questions:** ${analysisData.keyQuestionsNextSteps.criticalQuestions}\n\n`;
|
||||
|
||||
if (analysisData.keyQuestionsNextSteps.preliminaryRecommendation) {
|
||||
summary += `**Preliminary Recommendation:** ${analysisData.keyQuestionsNextSteps.preliminaryRecommendation}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add management team
|
||||
if (analysisData.managementTeamOverview?.keyLeaders) {
|
||||
summary += `## Management Team\n\n`;
|
||||
summary += `**Key Leaders:** ${analysisData.managementTeamOverview.keyLeaders}\n\n`;
|
||||
|
||||
if (analysisData.managementTeamOverview.managementQualityAssessment) {
|
||||
summary += `**Quality Assessment:** ${analysisData.managementTeamOverview.managementQualityAssessment}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add market analysis
|
||||
if (analysisData.marketIndustryAnalysis?.estimatedMarketSize) {
|
||||
summary += `## Market & Industry Analysis\n\n`;
|
||||
summary += `**Market Size:** ${analysisData.marketIndustryAnalysis.estimatedMarketSize}\n\n`;
|
||||
|
||||
if (analysisData.marketIndustryAnalysis.keyIndustryTrends) {
|
||||
summary += `**Industry Trends:** ${analysisData.marketIndustryAnalysis.keyIndustryTrends}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add investment thesis
|
||||
if (analysisData.preliminaryInvestmentThesis?.keyAttractions) {
|
||||
summary += `## Investment Thesis\n\n`;
|
||||
summary += `**Key Attractions:** ${analysisData.preliminaryInvestmentThesis.keyAttractions}\n\n`;
|
||||
|
||||
if (analysisData.preliminaryInvestmentThesis.potentialRisks) {
|
||||
summary += `**Potential Risks:** ${analysisData.preliminaryInvestmentThesis.potentialRisks}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
|
||||
export const optimizedAgenticRAGProcessor = new OptimizedAgenticRAGProcessor();
|
||||
Reference in New Issue
Block a user