Compare commits
20 Commits
fix-pdfpar
...
c50e48d564
| Author | SHA1 | Date | |
|---|---|---|---|
| c50e48d564 | |||
|
|
ba3105bbe5 | ||
| f32a21f87a | |||
|
|
8b57dd987e | ||
| ea234ea007 | |||
|
|
db4d5e4d00 | ||
| 358fcaeff5 | |||
|
|
67fed57118 | ||
| 45a6f3d374 | |||
|
|
aaf8cacf75 | ||
|
|
e28d0f46d0 | ||
| 22be09c101 | |||
|
|
78c4730196 | ||
| f2d0c91488 | |||
|
|
1d7fbea9ef | ||
|
|
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);
|
||||||
@@ -102,6 +108,7 @@ export async function convertPdfToStatement(
|
|||||||
const openai = new OpenAI({
|
const openai = new OpenAI({
|
||||||
apiKey: config.llmApiKey,
|
apiKey: config.llmApiKey,
|
||||||
...(config.llmApiBaseUrl && { baseURL: config.llmApiBaseUrl }),
|
...(config.llmApiBaseUrl && { baseURL: config.llmApiBaseUrl }),
|
||||||
|
timeout: 5 * 60 * 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -113,7 +120,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();
|
||||||
@@ -153,7 +159,21 @@ export async function convertPdfToStatement(
|
|||||||
return {
|
return {
|
||||||
status: 502,
|
status: 502,
|
||||||
error: 'BAD_GATEWAY',
|
error: 'BAD_GATEWAY',
|
||||||
message: 'Временная ошибка конвертации',
|
message: extractLlmErrorMessage(err),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractLlmErrorMessage(err: unknown): string {
|
||||||
|
const raw = String(
|
||||||
|
(err as Record<string, unknown>)?.message ??
|
||||||
|
(err as Record<string, Record<string, unknown>>)?.error?.message ?? '',
|
||||||
|
);
|
||||||
|
if (/context.length|n_ctx|too.many.tokens|maximum.context/i.test(raw)) {
|
||||||
|
return 'PDF-файл слишком большой для обработки. Попробуйте файл с меньшим количеством операций или используйте модель с большим контекстным окном.';
|
||||||
|
}
|
||||||
|
if (/timeout|timed?\s*out|ETIMEDOUT|ECONNREFUSED/i.test(raw)) {
|
||||||
|
return 'LLM-сервер не отвечает. Проверьте, что сервер запущен и доступен.';
|
||||||
|
}
|
||||||
|
return 'Временная ошибка конвертации';
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="theme-color" content="#0f172a" />
|
<meta name="theme-color" content="#0f172a" />
|
||||||
|
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
||||||
<title>Семейный бюджет</title>
|
<title>Семейный бюджет</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
|
|||||||
@@ -3,6 +3,20 @@ server {
|
|||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
|
# Import endpoint — long timeout for LLM processing
|
||||||
|
location /api/import {
|
||||||
|
proxy_pass http://family-budget-backend:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_cookie_path / /;
|
||||||
|
proxy_connect_timeout 5s;
|
||||||
|
proxy_read_timeout 600s;
|
||||||
|
client_max_body_size 15m;
|
||||||
|
}
|
||||||
|
|
||||||
# API — проксируем на backend (сервис из docker-compose)
|
# API — проксируем на backend (сервис из docker-compose)
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://family-budget-backend:3000;
|
proxy_pass http://family-budget-backend:3000;
|
||||||
|
|||||||
4
frontend/public/favicon.svg
Normal file
4
frontend/public/favicon.svg
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">
|
||||||
|
<rect width="32" height="32" rx="8" fill="#0f172a"/>
|
||||||
|
<text x="16" y="23" font-family="Georgia, serif" font-size="20" font-weight="bold" fill="#3b82f6" text-anchor="middle">₽</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 271 B |
Reference in New Issue
Block a user