-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api-endpoint.js
More file actions
70 lines (57 loc) · 2.33 KB
/
test-api-endpoint.js
File metadata and controls
70 lines (57 loc) · 2.33 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
/**
* Test the actual API endpoint locally
*/
import fs from 'fs';
import FormData from 'form-data';
import fetch from 'node-fetch';
async function testAPIEndpoint() {
console.log('🧪 Testing API Endpoint');
console.log('=======================\n');
try {
// Create a small test video file
const testVideoData = Buffer.from('fake video data for testing API endpoint');
const tempFile = 'temp_test_video.mp4';
fs.writeFileSync(tempFile, testVideoData);
console.log('📹 Created test video file:', tempFile);
console.log('📊 File size:', testVideoData.length, 'bytes');
// Test the predict-with-agents endpoint
console.log('\n🚀 Testing /api/predict-with-agents...');
const form = new FormData();
form.append('file', fs.createReadStream(tempFile), {
filename: 'test_video.mp4',
contentType: 'video/mp4'
});
const response = await fetch('http://localhost:5173/api/predict-with-agents', {
method: 'POST',
body: form,
headers: form.getHeaders()
});
console.log('📡 Response status:', response.status);
console.log('📡 Response headers:', Object.fromEntries(response.headers.entries()));
if (response.ok) {
const result = await response.json();
console.log('\n✅ SUCCESS! API Response:');
console.log('- Prediction:', result.prediction);
console.log('- Confidence:', (result.confidence * 100).toFixed(1) + '%');
console.log('- Models used:', result.models_used?.join(', '));
console.log('- Enhanced by agents:', result.enhanced_by_agents);
if (result.ondemand_analysis) {
console.log('- Agents used:', result.ondemand_analysis.agents_used);
console.log('- Preprocessing complete:', result.ondemand_analysis.preprocessing_complete);
console.log('- Confidence adjustment:', (result.ondemand_analysis.confidence_adjustment * 100).toFixed(1) + '%');
}
} else {
const errorText = await response.text();
console.log('\n❌ ERROR! API Response:');
console.log('Status:', response.status);
console.log('Error:', errorText);
}
// Clean up
fs.unlinkSync(tempFile);
console.log('\n🧹 Cleaned up test file');
} catch (error) {
console.error('\n💥 Test failed:', error.message);
console.error('Stack:', error.stack);
}
}
testAPIEndpoint();