/** * Layout prompt and decoder contract shared with okraPDF's parser-gemini * implementation. Kept in this standalone package so a public checkout can * install and build without monorepo workspace dependencies. * * Derived from ParseBench and @okrapdf/parser-gemini (MIT). */ export type DecodedLayoutBlock = { bbox: [number, number, number, number]; label: string; text: string; page?: number; }; const DIV_BLOCK = /
| , | )\n' +
'- For existing tables in the document: use colspan ' +
'and rowspan attributes to preserve merged cells ' +
'and hierarchical headers\n' +
'- For charts/graphs being converted to tables: use ' +
'flat combined column headers (e.g., ' +
'"Primary 2015" not separate rows) so each data ' +
"cell's row contains all its labels\n" +
'- Describe images/figures briefly in square brackets ' +
'like [Figure: description]\n' +
'- Preserve any code blocks with appropriate syntax ' +
'highlighting\n' +
'- Maintain reading order (left-to-right, ' +
'top-to-bottom for Western documents)\n' +
'- Do not add commentary or explanations ' +
'- only output the parsed content' +
'\n\n' +
'Additionally, wrap each layout element in a tag with:\n' +
'- data-bbox="[x1, y1, x2, y2]" — bounding box in normalized 0-1000 ' +
'coordinates where x is horizontal (left edge = 0, right edge = 1000) ' +
'and y is vertical (top = 0, bottom = 1000). ' +
'x1,y1 is the top-left corner and x2,y2 is the bottom-right corner.\n' +
'- data-label=" wrapper.';
export const USER_PROMPT_LAYOUT =
'Parse this document page and output its content as ' +
'clean markdown, with each layout element wrapped in a ' +
' tag. ' +
'Use HTML tables for any tabular data. ' +
'For charts/graphs, use flat combined column headers. ' +
'Output ONLY the parsed content with div wrappers, ' +
'no explanations.';
export const SYSTEM_PROMPT_LAYOUT_GEMINI = SYSTEM_PROMPT_LAYOUT.replace(
'"[x1, y1, x2, y2]" — bounding box in normalized 0-1000 ' +
'coordinates where x is horizontal (left edge = 0, right edge = 1000) ' +
'and y is vertical (top = 0, bottom = 1000). ' +
'x1,y1 is the top-left corner and x2,y2 is the bottom-right corner.',
'"[y_min, x_min, y_max, x_max]" — bounding box in normalized 0-1000 ' +
'coordinates where x is horizontal (left edge = 0, right edge = 1000) ' +
'and y is vertical (top = 0, bottom = 1000). ' +
'The order is [y_min, x_min, y_max, x_max].',
);
export const USER_PROMPT_LAYOUT_GEMINI = USER_PROMPT_LAYOUT.replace(
'[x1,y1,x2,y2]',
'[y_min,x_min,y_max,x_max]',
);
|
|---|