Files
cim_summary/backend/simple-llm-test.js
Jon 57770fd99d feat: Implement hybrid LLM approach with enhanced prompts for CIM analysis
🎯 Major Features:
- Hybrid LLM configuration: Claude 3.7 Sonnet (primary) + GPT-4.5 (fallback)
- Task-specific model selection for optimal performance
- Enhanced prompts for all analysis types with proven results

🔧 Technical Improvements:
- Enhanced financial analysis with fiscal year mapping (100% success rate)
- Business model analysis with scalability assessment
- Market positioning analysis with TAM/SAM extraction
- Management team assessment with succession planning
- Creative content generation with GPT-4.5

📊 Performance & Cost Optimization:
- Claude 3.7 Sonnet: /5 per 1M tokens (82.2% MATH score)
- GPT-4.5: Premium creative content (5/50 per 1M tokens)
- ~80% cost savings using Claude for analytical tasks
- Automatic fallback system for reliability

 Proven Results:
- Successfully extracted 3-year financial data from STAX CIM
- Correctly mapped fiscal years (2023→FY-3, 2024→FY-2, 2025E→FY-1, LTM Mar-25→LTM)
- Identified revenue: 4M→1M→1M→6M (LTM)
- Identified EBITDA: 8.9M→3.9M→1M→7.2M (LTM)

🚀 Files Added/Modified:
- Enhanced LLM service with task-specific model selection
- Updated environment configuration for hybrid approach
- Enhanced prompt builders for all analysis types
- Comprehensive testing scripts and documentation
- Updated frontend components for improved UX

📚 References:
- Eden AI Model Comparison: Claude 3.7 Sonnet vs GPT-4.5
- Artificial Analysis Benchmarks for performance metrics
- Cost optimization based on model strengths and pricing
2025-07-28 16:46:06 -04:00

233 lines
11 KiB
JavaScript

const axios = require('axios');
require('dotenv').config();
async function testLLMDirectly() {
console.log('🔍 Testing LLM API directly...\n');
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
console.error('❌ OPENAI_API_KEY not found in environment');
return;
}
const testText = `
CONFIDENTIAL INFORMATION MEMORANDUM
STAX Technology Solutions
Executive Summary:
STAX Technology Solutions is a leading provider of enterprise software solutions with headquarters in Charlotte, North Carolina. The company was founded in 2010 and has grown to serve over 500 enterprise clients.
Business Overview:
The company provides cloud-based software solutions for enterprise resource planning, customer relationship management, and business intelligence. Core products include STAX ERP, STAX CRM, and STAX Analytics.
Financial Performance:
Revenue has grown from $25M in FY-3 to $32M in FY-2, $38M in FY-1, and $42M in LTM. EBITDA margins have improved from 18% to 22% over the same period.
Market Position:
STAX serves the technology (40%), manufacturing (30%), and healthcare (30%) markets. Key customers include Fortune 500 companies across these sectors.
Management Team:
CEO Sarah Johnson has been with the company for 8 years, previously serving as CTO. CFO Michael Chen joined from a public software company. The management team is experienced and committed to growth.
Growth Opportunities:
The company has identified opportunities to expand into the AI/ML market and increase international presence. There are also opportunities for strategic acquisitions.
Reason for Sale:
The founding team is looking to partner with a larger organization to accelerate growth and expand market reach.
`;
const systemPrompt = `You are an expert investment analyst at BPCP (Blue Point Capital Partners) reviewing a Confidential Information Memorandum (CIM). Your task is to analyze CIM documents and return a comprehensive, structured JSON object that follows the BPCP CIM Review Template format EXACTLY.
CRITICAL REQUIREMENTS:
1. **JSON OUTPUT ONLY**: Your entire response MUST be a single, valid JSON object. Do not include any text or explanation before or after the JSON object.
2. **BPCP TEMPLATE FORMAT**: The JSON object MUST follow the BPCP CIM Review Template structure exactly as specified.
3. **COMPLETE ALL FIELDS**: You MUST provide a value for every field. Use "Not specified in CIM" for any information that is not available in the document.
4. **NO PLACEHOLDERS**: Do not use placeholders like "..." or "TBD". Use "Not specified in CIM" instead.
5. **PROFESSIONAL ANALYSIS**: The content should be high-quality and suitable for BPCP's investment committee.
6. **BPCP FOCUS**: Focus on companies in 5+MM EBITDA range in consumer and industrial end markets, with emphasis on M&A, technology & data usage, supply chain and human capital optimization.
7. **BPCP PREFERENCES**: BPCP prefers companies which are founder/family-owned and within driving distance of Cleveland and Charlotte.
8. **EXACT FIELD NAMES**: Use the exact field names and descriptions from the BPCP CIM Review Template.
9. **FINANCIAL DATA**: For financial metrics, use actual numbers if available, otherwise use "Not specified in CIM".
10. **VALID JSON**: Ensure your response is valid JSON that can be parsed without errors.`;
const userPrompt = `Please analyze the following CIM document and return a JSON object with the following structure:
{
"dealOverview": {
"targetCompanyName": "Target Company Name",
"industrySector": "Industry/Sector",
"geography": "Geography (HQ & Key Operations)",
"dealSource": "Deal Source",
"transactionType": "Transaction Type",
"dateCIMReceived": "Date CIM Received",
"dateReviewed": "Date Reviewed",
"reviewers": "Reviewer(s)",
"cimPageCount": "CIM Page Count",
"statedReasonForSale": "Stated Reason for Sale (if provided)"
},
"businessDescription": {
"coreOperationsSummary": "Core Operations Summary (3-5 sentences)",
"keyProductsServices": "Key Products/Services & Revenue Mix (Est. % if available)",
"uniqueValueProposition": "Unique Value Proposition (UVP) / Why Customers Buy",
"customerBaseOverview": {
"keyCustomerSegments": "Key Customer Segments/Types",
"customerConcentrationRisk": "Customer Concentration Risk (Top 5 and/or Top 10 Customers as % Revenue - if stated/inferable)",
"typicalContractLength": "Typical Contract Length / Recurring Revenue % (if applicable)"
},
"keySupplierOverview": {
"dependenceConcentrationRisk": "Dependence/Concentration Risk"
}
},
"marketIndustryAnalysis": {
"estimatedMarketSize": "Estimated Market Size (TAM/SAM - if provided)",
"estimatedMarketGrowthRate": "Estimated Market Growth Rate (% CAGR - Historical & Projected)",
"keyIndustryTrends": "Key Industry Trends & Drivers (Tailwinds/Headwinds)",
"competitiveLandscape": {
"keyCompetitors": "Key Competitors Identified",
"targetMarketPosition": "Target's Stated Market Position/Rank",
"basisOfCompetition": "Basis of Competition"
},
"barriersToEntry": "Barriers to Entry / Competitive Moat (Stated/Inferred)"
},
"financialSummary": {
"financials": {
"fy3": {
"revenue": "Revenue amount for FY-3",
"revenueGrowth": "N/A (baseline year)",
"grossProfit": "Gross profit amount for FY-3",
"grossMargin": "Gross margin % for FY-3",
"ebitda": "EBITDA amount for FY-3",
"ebitdaMargin": "EBITDA margin % for FY-3"
},
"fy2": {
"revenue": "Revenue amount for FY-2",
"revenueGrowth": "Revenue growth % for FY-2",
"grossProfit": "Gross profit amount for FY-2",
"grossMargin": "Gross margin % for FY-2",
"ebitda": "EBITDA amount for FY-2",
"ebitdaMargin": "EBITDA margin % for FY-2"
},
"fy1": {
"revenue": "Revenue amount for FY-1",
"revenueGrowth": "Revenue growth % for FY-1",
"grossProfit": "Gross profit amount for FY-1",
"grossMargin": "Gross margin % for FY-1",
"ebitda": "EBITDA amount for FY-1",
"ebitdaMargin": "EBITDA margin % for FY-1"
},
"ltm": {
"revenue": "Revenue amount for LTM",
"revenueGrowth": "Revenue growth % for LTM",
"grossProfit": "Gross profit amount for LTM",
"grossMargin": "Gross margin % for LTM",
"ebitda": "EBITDA amount for LTM",
"ebitdaMargin": "EBITDA margin % for LTM"
}
},
"qualityOfEarnings": "Quality of earnings/adjustments impression",
"revenueGrowthDrivers": "Revenue growth drivers (stated)",
"marginStabilityAnalysis": "Margin stability/trend analysis",
"capitalExpenditures": "Capital expenditures (LTM % of revenue)",
"workingCapitalIntensity": "Working capital intensity impression",
"freeCashFlowQuality": "Free cash flow quality impression"
},
"managementTeamOverview": {
"keyLeaders": "Key Leaders Identified (CEO, CFO, COO, Head of Sales, etc.)",
"managementQualityAssessment": "Initial Assessment of Quality/Experience (Based on Bios)",
"postTransactionIntentions": "Management's Stated Post-Transaction Role/Intentions (if mentioned)",
"organizationalStructure": "Organizational Structure Overview (Impression)"
},
"preliminaryInvestmentThesis": {
"keyAttractions": "Key Attractions / Strengths (Why Invest?)",
"potentialRisks": "Potential Risks / Concerns (Why Not Invest?)",
"valueCreationLevers": "Initial Value Creation Levers (How PE Adds Value)",
"alignmentWithFundStrategy": "Alignment with Fund Strategy (BPCP is focused on companies in 5+MM EBITDA range in consumer and industrial end markets. M&A, increased technology & data usage, supply chain and human capital optimization are key value-levers. Also a preference companies which are founder / family-owned and within driving distance of Cleveland and Charlotte.)"
},
"keyQuestionsNextSteps": {
"criticalQuestions": "Critical Questions / Missing Information",
"preliminaryRecommendation": "Preliminary Recommendation (Pass / Pursue / Hold)",
"rationale": "Rationale for Recommendation",
"nextSteps": "Next Steps / Due Diligence Requirements"
}
}
CIM Document to analyze:
${testText}`;
try {
console.log('1. Making API call to OpenAI...');
const response = await axios.post('https://api.openai.com/v1/chat/completions', {
model: 'gpt-4o',
messages: [
{
role: 'system',
content: systemPrompt
},
{
role: 'user',
content: userPrompt
}
],
max_tokens: 4000,
temperature: 0.1
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
timeout: 60000
});
console.log('2. API Response received');
console.log('Model:', response.data.model);
console.log('Usage:', response.data.usage);
const content = response.data.choices[0]?.message?.content;
console.log('3. Raw LLM Response:');
console.log('Content length:', content?.length || 0);
console.log('First 500 chars:', content?.substring(0, 500));
console.log('Last 500 chars:', content?.substring(content.length - 500));
// Try to extract JSON
console.log('\n4. Attempting to parse JSON...');
try {
// Look for JSON in code blocks
const jsonMatch = content.match(/```json\n([\s\S]*?)\n```/);
const jsonString = jsonMatch ? jsonMatch[1] : content;
// Find first and last curly braces
const startIndex = jsonString.indexOf('{');
const endIndex = jsonString.lastIndexOf('}');
if (startIndex !== -1 && endIndex !== -1) {
const extractedJson = jsonString.substring(startIndex, endIndex + 1);
const parsed = JSON.parse(extractedJson);
console.log('✅ JSON parsed successfully!');
console.log('Parsed structure:', Object.keys(parsed));
// Check if all required fields are present
const requiredFields = ['dealOverview', 'businessDescription', 'marketIndustryAnalysis', 'financialSummary', 'managementTeamOverview', 'preliminaryInvestmentThesis', 'keyQuestionsNextSteps'];
const missingFields = requiredFields.filter(field => !parsed[field]);
if (missingFields.length > 0) {
console.log('❌ Missing required fields:', missingFields);
} else {
console.log('✅ All required fields present');
}
return parsed;
} else {
console.log('❌ No JSON object found in response');
}
} catch (parseError) {
console.log('❌ JSON parsing failed:', parseError.message);
}
} catch (error) {
console.error('❌ API call failed:', error.response?.data || error.message);
}
}
testLLMDirectly();