-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_document_processor.js
More file actions
138 lines (116 loc) · 4.55 KB
/
Copy pathtest_document_processor.js
File metadata and controls
138 lines (116 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const path = require('path');
async function testDocumentProcessor() {
console.log('🚀 开始测试文档处理器节点...\n');
try {
// 检查测试文件是否存在
const testFilePath = path.join(__dirname, 'test.pdf');
if (!fs.existsSync(testFilePath)) {
console.log('❌ 测试文件 test.pdf 不存在');
return;
}
console.log('📁 找到测试文件:', testFilePath);
// 创建表单数据
const formData = new FormData();
formData.append('file', fs.createReadStream(testFilePath));
formData.append('processorConfig', JSON.stringify({
extractText: true,
extractMetadata: true,
enableOCR: false,
chunkContent: true
}));
console.log('📤 发送文档处理器测试请求...');
// 发送测试请求
const response = await axios.post('http://localhost:7000/api/test/document-processor', formData, {
headers: {
...formData.getHeaders(),
},
timeout: 30000
});
console.log('✅ 测试成功!\n');
console.log('📊 测试结果:');
console.log('─'.repeat(50));
console.log(JSON.stringify(response.data, null, 2));
console.log('─'.repeat(50));
// 分析结果
const result = response.data;
if (result.success) {
console.log('\n🎉 文档处理器节点工作正常!');
console.log('📄 处理文件:', result.file_info.name);
console.log('⏱️ 处理时间:', result.processing_stats.extraction_time);
console.log('📊 文本长度:', result.processing_stats.text_length);
console.log('🔗 创建分段:', result.processing_stats.chunks_created);
console.log('\n💡 下一步建议:');
result.recommendations.forEach(rec => {
console.log(` • ${rec}`);
});
}
} catch (error) {
console.log('❌ 测试失败:\n');
if (error.response) {
console.log('状态码:', error.response.status);
console.log('错误信息:', error.response.data);
} else {
console.log('错误:', error.message);
}
}
}
async function checkWorkflowConfig() {
console.log('\n🔧 检查工作流配置建议...\n');
try {
const response = await axios.get('http://localhost:7000/api/test/workflow-config');
const config = response.data;
console.log('📋 工作流配置状态:', config.workflow_status);
console.log('\n🔍 配置建议:');
config.recommendations.forEach((rec, index) => {
console.log(`\n${index + 1}. ${rec.component}`);
console.log(` 状态: ${rec.status}`);
console.log(` 重要性: ${rec.importance}`);
console.log(` 说明: ${rec.description}`);
});
console.log('\n📖 配置步骤:');
Object.entries(config.setup_guide).forEach(([step, description]) => {
console.log(` ${step}: ${description}`);
});
} catch (error) {
console.log('❌ 配置检查失败:', error.message);
}
}
// 运行测试
async function runAllTests() {
console.log('🎯 文档处理器节点测试工具');
console.log('='.repeat(60));
console.log('🚀 测试你的Dify文档处理器节点配置');
console.log('='.repeat(60));
await testDocumentProcessor();
await checkWorkflowConfig();
console.log('\n✅ 测试完成!');
console.log('\n🌐 访问测试页面获取更多信息:');
console.log(' http://localhost:7000/document_processor_test.html');
console.log(' http://localhost:7000/dify_workflow_test.html');
}
// 检查服务器是否运行
async function checkServer() {
try {
await axios.get('http://localhost:7000/api/health', { timeout: 5000 });
return true;
} catch (error) {
console.log('❌ 服务器未运行,请先启动服务器');
console.log(' 命令: node server.js');
return false;
}
}
// 主函数
async function main() {
const serverRunning = await checkServer();
if (serverRunning) {
await runAllTests();
}
}
// 运行程序
main().catch(error => {
console.error('程序运行失败:', error);
process.exit(1);
});