// Import the compiled JavaScript version const { llmService } = require('./dist/services/llmService'); const fs = require('fs'); const path = require('path'); // Load environment variables require('dotenv').config({ path: path.join(__dirname, '.env') }); async function debugLLMProcessing() { try { console.log('šŸ” Debugging LLM Processing...\n'); // Sample CIM text for testing const sampleCIMText = ` CONFIDENTIAL INFORMATION MEMORANDUM COMPANY: Sample Manufacturing Corp. INDUSTRY: Industrial Manufacturing LOCATION: Cleveland, OH EMPLOYEES: 150 REVENUE: $25M (2023), $28M (2024) EBITDA: $4.2M (2023), $4.8M (2024) BUSINESS DESCRIPTION: Sample Manufacturing Corp. is a leading manufacturer of precision industrial components serving the automotive and aerospace industries. The company has been in business for 25 years and operates from a 50,000 sq ft facility in Cleveland, OH. KEY PRODUCTS: - Precision machined parts (60% of revenue) - Assembly services (25% of revenue) - Engineering consulting (15% of revenue) CUSTOMERS: - Top 5 customers represent 45% of revenue - Long-term contracts with major automotive OEMs - Growing aerospace segment FINANCIAL PERFORMANCE: FY 2022: Revenue $22M, EBITDA $3.8M FY 2023: Revenue $25M, EBITDA $4.2M FY 2024: Revenue $28M, EBITDA $4.8M MANAGEMENT: CEO: John Smith (15 years experience) CFO: Sarah Johnson (10 years experience) COO: Mike Davis (12 years experience) REASON FOR SALE: Founder looking to retire and seeking strategic partner for growth. `; console.log('šŸ“„ Sample CIM Text Length:', sampleCIMText.length, 'characters'); console.log('šŸ”„ Testing LLM processing...\n'); // Test the LLM processing const result = await llmService.processCIMDocument(sampleCIMText, { taskType: 'complex', priority: 'quality' }); console.log('āœ… LLM Processing Result:'); console.log(' Model Used:', result.model); console.log(' Tokens Used:', result.tokensUsed); console.log(' Cost:', result.cost); console.log(' Processing Time:', result.processingTime, 'ms'); console.log('\nšŸ“‹ Raw LLM Response:'); console.log(' Content Length:', result.content.length, 'characters'); console.log(' Content Preview:', result.content.substring(0, 500) + '...'); console.log('\nšŸ” Analysis Data:'); console.log(' Analysis Data Type:', typeof result.analysisData); console.log(' Analysis Data Keys:', Object.keys(result.analysisData)); if (result.analysisData && Object.keys(result.analysisData).length > 0) { console.log(' Analysis Data Preview:', JSON.stringify(result.analysisData, null, 2).substring(0, 1000) + '...'); } else { console.log(' āŒ Analysis Data is empty or missing!'); } // Check if the response contains JSON const jsonMatch = result.content.match(/\{[\s\S]*\}/); if (jsonMatch) { console.log('\nšŸ” JSON Extraction:'); console.log(' JSON Found:', 'Yes'); console.log(' JSON Length:', jsonMatch[0].length); console.log(' JSON Preview:', jsonMatch[0].substring(0, 500) + '...'); try { const parsedJson = JSON.parse(jsonMatch[0]); console.log(' āœ… JSON Parsing: Success'); console.log(' Parsed Keys:', Object.keys(parsedJson)); } catch (parseError) { console.log(' āŒ JSON Parsing: Failed -', parseError.message); } } else { console.log('\nāŒ No JSON found in LLM response!'); } } catch (error) { console.error('āŒ Debug failed:', error.message); console.error(' Error details:', error); } } debugLLMProcessing();