fix: reopen result modal from progress bar, faster progress, handle LLM context error
- Move import modal visibility into ImportContext so the Layout progress pill can reopen the result dialog after the modal was closed. - Raise LLM progress cap from 85% to 98% and drop the intermediate -import 88%- SSE event to eliminate the visual stall after LLM finishes. - Detect LLM context-length errors (n_keep >= n_ctx) and surface a clear message instead of generic -Временная ошибка конвертации-.
This commit is contained in:
@@ -79,12 +79,6 @@ router.post(
|
||||
return;
|
||||
}
|
||||
|
||||
sseWrite(res, {
|
||||
stage: 'import',
|
||||
progress: 88,
|
||||
message: 'Импорт в базу данных...',
|
||||
});
|
||||
|
||||
const result = await importStatement(converted);
|
||||
if (isValidationError(result)) {
|
||||
sseWrite(res, {
|
||||
|
||||
@@ -137,7 +137,7 @@ export async function convertPdfToStatement(
|
||||
return {
|
||||
status: 502,
|
||||
error: 'BAD_GATEWAY',
|
||||
message: 'Временная ошибка конвертации',
|
||||
message: extractLlmErrorMessage(err),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export type ProgressStage = 'pdf' | 'llm' | 'import';
|
||||
export type OnProgress = (stage: ProgressStage, progress: number, message: string) => void;
|
||||
|
||||
const LLM_PROGRESS_MIN = 10;
|
||||
const LLM_PROGRESS_MAX = 85;
|
||||
const LLM_PROGRESS_MAX = 98;
|
||||
const LLM_PROGRESS_RANGE = LLM_PROGRESS_MAX - LLM_PROGRESS_MIN;
|
||||
const THROTTLE_MS = 300;
|
||||
|
||||
@@ -248,11 +248,25 @@ export async function convertPdfToStatementStreaming(
|
||||
return {
|
||||
status: 502,
|
||||
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 'Временная ошибка конвертации';
|
||||
}
|
||||
|
||||
function parseConversionResult(content: string): StatementFile | PdfConversionError {
|
||||
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
||||
const jsonStr = jsonMatch ? jsonMatch[0] : content;
|
||||
|
||||
Reference in New Issue
Block a user