- 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
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
const { Pool } = require('pg');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Import the document processing service
|
|
const { documentProcessingService } = require('./src/services/documentProcessingService');
|
|
|
|
const pool = new Pool({
|
|
connectionString: 'postgresql://postgres:password@localhost:5432/cim_processor'
|
|
});
|
|
|
|
async function processStaxManually() {
|
|
try {
|
|
console.log('🔍 Finding STAX CIM document...');
|
|
|
|
// 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(`📄 Found document: ${document.original_file_name} (${document.status})`);
|
|
console.log(`📁 File path: ${document.file_path}`);
|
|
|
|
// Check if file exists
|
|
if (!fs.existsSync(document.file_path)) {
|
|
console.log('❌ File not found at path:', document.file_path);
|
|
return;
|
|
}
|
|
|
|
console.log('✅ File found, starting manual processing...');
|
|
|
|
// Update document status to processing
|
|
await pool.query(`
|
|
UPDATE documents
|
|
SET status = 'processing_llm',
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`, [document.id]);
|
|
|
|
console.log('🚀 Starting document processing with LLM...');
|
|
console.log('📊 This will use your OpenAI/Anthropic API keys');
|
|
console.log('⏱️ Processing may take 2-3 minutes for the 71-page document...');
|
|
|
|
// Process the document
|
|
const result = await documentProcessingService.processDocument(document.id, {
|
|
extractText: true,
|
|
generateSummary: true,
|
|
performAnalysis: true,
|
|
});
|
|
|
|
console.log('✅ Document processing completed!');
|
|
console.log('📋 Results:', result);
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error processing document:', error.message);
|
|
console.error('Full error:', error);
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
processStaxManually();
|