review: durée review Ollama (durationMs), timeout 15s, tooltip durée; délai min configurable via OLLAMA_MIN_REVIEW_MS

This commit is contained in:
4NK IA 2025-09-18 12:59:58 +00:00
parent 1e207f734e
commit 984c3838ae
2 changed files with 15 additions and 7 deletions

View File

@ -1077,6 +1077,7 @@ function generateStandardJSON(documentInfo, ocrResult, entities, processingTime)
async function reviewWithOllama(payload) {
try {
const http = require('http')
const startAt = Date.now()
const data = JSON.stringify({
model: process.env.OLLAMA_MODEL || 'llama3.1',
prompt:
@ -1094,7 +1095,7 @@ async function reviewWithOllama(payload) {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data),
},
timeout: 8000,
timeout: 15000,
}
const responseBody = await new Promise((resolve, reject) => {
const req = http.request(options, (res) => {
@ -1120,13 +1121,20 @@ async function reviewWithOllama(payload) {
const match = String(txt).match(/\{[\s\S]*\}$/)
if (!match) throw new Error('Réponse non JSON')
const parsed = JSON.parse(match[0])
const durationMs = Date.now() - startAt
// Respecter un délai minimal si souhaité
const minDelay = Math.max(0, Number(process.env.OLLAMA_MIN_REVIEW_MS || 0))
if (minDelay > 0 && durationMs < minDelay) {
await new Promise((r) => setTimeout(r, minDelay - durationMs))
}
return {
score: Math.max(0, Math.min(1, Number(parsed.score) || 0)),
corrections: Array.isArray(parsed.corrections) ? parsed.corrections : [],
avis: typeof parsed.avis === 'string' ? parsed.avis : '',
durationMs: Math.max(durationMs, minDelay || 0),
}
} catch (e) {
return { score: null, corrections: [], avis: '' }
return { score: null, corrections: [], avis: '', durationMs: null }
}
}

View File

@ -163,6 +163,7 @@ const DocumentListItem = memo(({ doc, index, onPreview, onDelete, onReplace, onC
(anyDoc?.metadata?.quality?.ollamaScore as number | undefined) ??
(anyDoc?.status?.review?.score as number | undefined)
const avis: string | undefined = anyDoc?.status?.review?.avis
const dur: number | undefined = anyDoc?.status?.review?.durationMs
if (doc.status === 'completed' && typeof score === 'number') {
const chip = (
<Chip
@ -172,13 +173,12 @@ const DocumentListItem = memo(({ doc, index, onPreview, onDelete, onReplace, onC
variant="outlined"
/>
)
return typeof avis === 'string' && avis.length > 0 ? (
<Tooltip title={avis}>
const tip = `${avis ? avis : ''}${dur ? (avis ? ' — ' : '') + 'durée: ' + dur + ' ms' : ''}`
return tip ? (
<Tooltip title={tip}>
<span>{chip}</span>
</Tooltip>
) : (
chip
)
) : chip
}
return null
})()}