Files
cim_summary/backend/manual-llm-process.js
Jon c67dab22b4 Add comprehensive CIM processing features and UI improvements
- Add new database migrations for analysis data and job tracking
- Implement enhanced document processing service with LLM integration
- Add processing progress and queue status components
- Create testing guides and utility scripts for CIM processing
- Update frontend components for better user experience
- Add environment configuration and backup files
- Implement job queue service and upload progress tracking
2025-07-27 20:25:46 -04:00

131 lines
4.1 KiB
JavaScript

const { Pool } = require('pg');
const fs = require('fs');
const pdfParse = require('pdf-parse');
// Simple LLM processing simulation
async function processWithLLM(text) {
console.log('🤖 Simulating LLM processing...');
console.log('📊 This would normally call your OpenAI/Anthropic API');
console.log('📝 Processing text length:', text.length, 'characters');
// Simulate processing time
await new Promise(resolve => setTimeout(resolve, 2000));
return {
summary: "STAX Holding Company, LLC - Confidential Information Presentation",
analysis: {
companyName: "Stax Holding Company, LLC",
documentType: "Confidential Information Presentation",
date: "April 2025",
pages: 71,
keySections: [
"Executive Summary",
"Company Overview",
"Financial Highlights",
"Management Team",
"Investment Terms"
]
}
};
}
const pool = new Pool({
connectionString: 'postgresql://postgres:password@localhost:5432/cim_processor'
});
async function manualLLMProcess() {
try {
console.log('🚀 Starting Manual LLM Processing for STAX CIM');
console.log('==============================================');
// Find the STAX CIM document
const docResult = await pool.query(`
SELECT id, original_file_name, status, user_id, file_path
FROM documents
WHERE original_file_name = 'stax-cim-test.pdf'
ORDER BY created_at DESC
LIMIT 1
`);
if (docResult.rows.length === 0) {
console.log('❌ No STAX CIM document found');
return;
}
const document = docResult.rows[0];
console.log(`📄 Document: ${document.original_file_name}`);
console.log(`📁 File: ${document.file_path}`);
// Check if file exists
if (!fs.existsSync(document.file_path)) {
console.log('❌ File not found');
return;
}
console.log('✅ File found, extracting text...');
// Extract text from PDF
const dataBuffer = fs.readFileSync(document.file_path);
const pdfData = await pdfParse(dataBuffer);
console.log(`📊 Extracted ${pdfData.text.length} characters from ${pdfData.numpages} pages`);
// Update document status
await pool.query(`
UPDATE documents
SET status = 'processing_llm',
updated_at = CURRENT_TIMESTAMP
WHERE id = $1
`, [document.id]);
console.log('🔄 Status updated to processing_llm');
// Process with LLM
console.log('🤖 Starting LLM analysis...');
const llmResult = await processWithLLM(pdfData.text);
console.log('✅ LLM processing completed!');
console.log('📋 Results:');
console.log('- Summary:', llmResult.summary);
console.log('- Company:', llmResult.analysis.companyName);
console.log('- Document Type:', llmResult.analysis.documentType);
console.log('- Pages:', llmResult.analysis.pages);
console.log('- Key Sections:', llmResult.analysis.keySections.join(', '));
// Update document with results
await pool.query(`
UPDATE documents
SET status = 'completed',
generated_summary = $1,
updated_at = CURRENT_TIMESTAMP
WHERE id = $2
`, [llmResult.summary, document.id]);
console.log('💾 Results saved to database');
// Update processing jobs
await pool.query(`
UPDATE processing_jobs
SET status = 'completed',
progress = 100,
completed_at = CURRENT_TIMESTAMP
WHERE document_id = $1
`, [document.id]);
console.log('🎉 Processing completed successfully!');
console.log('');
console.log('📊 Next Steps:');
console.log('1. Go to http://localhost:3000');
console.log('2. Login with user1@example.com / user123');
console.log('3. Check the Documents tab');
console.log('4. You should see the STAX CIM document as completed');
console.log('5. Click on it to view the analysis results');
} catch (error) {
console.error('❌ Error during processing:', error.message);
} finally {
await pool.end();
}
}
manualLLMProcess();