Compare commits
5 Commits
fix-pdfpar
...
627706228b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
627706228b | ||
|
|
a5f2294440 | ||
| 25ddd6b7ed | |||
|
|
3e481d5a55 | ||
| cf24d5dc26 |
@@ -30,6 +30,7 @@ ENV NODE_ENV=production
|
|||||||
COPY --from=build /app/backend/dist ./dist
|
COPY --from=build /app/backend/dist ./dist
|
||||||
COPY --from=build /app/backend/package.json ./package.json
|
COPY --from=build /app/backend/package.json ./package.json
|
||||||
COPY --from=build /app/node_modules ./node_modules
|
COPY --from=build /app/node_modules ./node_modules
|
||||||
|
COPY --from=build /app/backend/node_modules/ ./node_modules/
|
||||||
COPY backend/.env .env
|
COPY backend/.env .env
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
@@ -63,9 +63,15 @@ export function isPdfConversionError(r: unknown): r is PdfConversionError {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pdf-parse v1 default export: (buffer, options?) => Promise<{ text, numpages, info }>
|
// Lazy-loaded so the app starts even if pdf-parse is missing from node_modules.
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
let _pdfParse: ((buf: Buffer) => Promise<{ text: string }>) | undefined;
|
||||||
const pdfParse: (buf: Buffer) => Promise<{ text: string }> = require('pdf-parse');
|
function getPdfParse() {
|
||||||
|
if (!_pdfParse) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
|
_pdfParse = require('pdf-parse') as (buf: Buffer) => Promise<{ text: string }>;
|
||||||
|
}
|
||||||
|
return _pdfParse;
|
||||||
|
}
|
||||||
|
|
||||||
export async function convertPdfToStatement(
|
export async function convertPdfToStatement(
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
@@ -80,7 +86,7 @@ export async function convertPdfToStatement(
|
|||||||
|
|
||||||
let text: string;
|
let text: string;
|
||||||
try {
|
try {
|
||||||
const result = await pdfParse(buffer);
|
const result = await getPdfParse()(buffer);
|
||||||
text = result.text || '';
|
text = result.text || '';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('PDF extraction error:', err);
|
console.error('PDF extraction error:', err);
|
||||||
@@ -113,7 +119,6 @@ export async function convertPdfToStatement(
|
|||||||
],
|
],
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
max_tokens: 32768,
|
max_tokens: 32768,
|
||||||
response_format: { type: 'json_object' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const content = completion.choices[0]?.message?.content?.trim();
|
const content = completion.choices[0]?.message?.content?.trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user