chore: reduce layout threshold to 0.2, tune vLLM memory, and add test scripts and reports
This commit is contained in:
1 parent
bdb3a49742
commit
5c7c64e2f4
6 files changed
+2090
-9
No files matched your search
@@ -0,0 +1,109 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const PIPELINE_URL = 'http://localhost:8000/layout-parsing';
|
||||
const PROXY_URL = 'http://localhost:8000/api/vllm-proxy/v1/chat/completions';
|
||||
const UPLOADS_DIR = path.join(__dirname, '..', 'uploads');
|
||||
|
||||
const notFoundImages = [
|
||||
'1782888211457-rotated_1782888204591_rotated_1782888199962_rotated_1782888195402_CAP7202641176939787142.jpg',
|
||||
'1782875064223-CAP2007290974474760139.jpg',
|
||||
'1782884586047-CAP9169719214882332189.jpg',
|
||||
'1782893409879-CAP4330863738757813156.jpg'
|
||||
];
|
||||
|
||||
async function testImage(filename) {
|
||||
console.log(`\n========================================`);
|
||||
console.log(`TESTING FILE: ${filename}`);
|
||||
console.log(`========================================`);
|
||||
|
||||
const filePath = path.join(UPLOADS_DIR, filename);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.error(`File does not exist on disk: ${filePath}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const fileBuffer = fs.readFileSync(filePath);
|
||||
const base64Image = fileBuffer.toString('base64');
|
||||
|
||||
// Test 1: Hit the Layout Parsing Pipeline API
|
||||
console.log('\n--- Test 1: Layout Parsing Pipeline (Standard) ---');
|
||||
try {
|
||||
const res = await fetch(PIPELINE_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
file: base64Image,
|
||||
matchHistoryJob: false,
|
||||
useLayoutDetection: true,
|
||||
fileType: 1,
|
||||
useDocUnwarping: false,
|
||||
useDocOrientationClassify: true
|
||||
})
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
const markdown = data.result?.layoutParsingResults?.[0]?.markdown?.text || data.layoutParsingResults?.[0]?.markdown?.text || '';
|
||||
console.log('Resulting Markdown snippet (first 300 chars):');
|
||||
console.log(markdown.substring(0, 300));
|
||||
console.log(`\nDoes it contain PO, SO, DO or Tanggal?`);
|
||||
console.log(`- "Tanggal": ${/Tanggal/i.test(markdown)}`);
|
||||
console.log(`- "SO": ${/SO/i.test(markdown)}`);
|
||||
console.log(`- "DO": ${/DO/i.test(markdown)}`);
|
||||
console.log(`- "PO": ${/PO/i.test(markdown)}`);
|
||||
} else {
|
||||
console.error(`Pipeline returned status ${res.status}: ${await res.text()}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Pipeline test failed:', err.message);
|
||||
}
|
||||
|
||||
// Test 2: Direct vLLM completions with simple extraction prompt
|
||||
console.log('\n--- Test 2: Direct vLLM Simple Extraction ---');
|
||||
try {
|
||||
const res = await fetch(PROXY_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: "PaddleOCR-VL-1.6-0.9B",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: `data:image/jpeg;base64,${base64Image}` }
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
text: "Read the top right section of the document. Extract Tanggal, No. SO, No. DO, and No. PO."
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
temperature: 0.1,
|
||||
max_tokens: 300
|
||||
})
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
const content = data.choices?.[0]?.message?.content;
|
||||
console.log('vLLM Response:');
|
||||
console.log(content);
|
||||
} else {
|
||||
console.error(`vLLM proxy returned status ${res.status}: ${await res.text()}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('vLLM test failed:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function runAll() {
|
||||
for (const filename of notFoundImages) {
|
||||
await testImage(filename);
|
||||
}
|
||||
}
|
||||
|
||||
runAll();
|
||||
Reference in new issue
Block a user