feat(invoices): add hybrid OCR + vision invoice/document parsing with PaddleOCR, consensus voting, and prompt/test refactors
This commit is contained in:
@@ -45,7 +45,8 @@ async function extractOcrText(imageBase64: string): Promise<string> {
|
||||
* Build prompt with optional OCR text
|
||||
*/
|
||||
function buildPrompt(ocrText: string): string {
|
||||
const base = `You are an invoice parser. Extract the following fields from this invoice:
|
||||
const base = `/nothink
|
||||
You are an invoice parser. Extract the following fields from this invoice:
|
||||
|
||||
1. invoice_number: The invoice/receipt number
|
||||
2. invoice_date: Date in YYYY-MM-DD format
|
||||
@@ -62,11 +63,17 @@ If a field is not visible, use null for strings or 0 for numbers.
|
||||
No explanation, just the JSON object.`;
|
||||
|
||||
if (ocrText) {
|
||||
// Limit OCR text to prevent context overflow
|
||||
const maxOcrLength = 4000;
|
||||
const truncatedOcr = ocrText.length > maxOcrLength
|
||||
? ocrText.substring(0, maxOcrLength) + '\n... (truncated)'
|
||||
: ocrText;
|
||||
|
||||
return `${base}
|
||||
|
||||
OCR text extracted from the invoice:
|
||||
OCR text extracted from the invoice (use for reference):
|
||||
---
|
||||
${ocrText}
|
||||
${truncatedOcr}
|
||||
---
|
||||
|
||||
Cross-reference the image with the OCR text above for accuracy.`;
|
||||
|
||||
Reference in New Issue
Block a user