extraction error logging

This commit is contained in:
Storme-bit
2026-04-20 23:44:26 -07:00
parent 5de64ba68e
commit 72b41056a5

View File

@@ -22,17 +22,19 @@ function buildExtractionPrompt(userMessage, aiResponse, knownEntities = []) {
'You are a named entity extractor. You output only valid JSON.', 'You are a named entity extractor. You output only valid JSON.',
'<|im_end|>', '<|im_end|>',
'<|im_start|>user', '<|im_start|>user',
'Extract all named entities from this conversation.', 'Read the conversation below and extract every named entity mentioned.',
`Valid types: ${ENTITY_TYPES.join(', ')}`, `Entity types to extract: ${ENTITY_TYPES.join(', ')}`,
'For each entity found, provide: name, type, and a one-sentence notes field.',
'Return your answer as: { "entities": [ ... ] }',
'', '',
knownBlock, knownBlock,
'Return a JSON object: { "entities": [ { "name": "...", "type": "...", "notes": "..." } ] }', '--- CONVERSATION ---', // clear delimiter helps smaller models
'Only include items where type is one of the valid types.',
'',
`User: ${userMessage}`, `User: ${userMessage}`,
`Assistant: ${aiResponse}`, `Assistant: ${aiResponse}`,
'--- END CONVERSATION ---',
'<|im_end|>', '<|im_end|>',
'<|im_start|>assistant', '<|im_start|>assistant',
'{"entities":', // primer nudges it to start filling the array
].join('\n'); ].join('\n');
} }
@@ -58,6 +60,10 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
const db = require('../db').getDB(); const db = require('../db').getDB();
const knownEntities = db.prepare(`SELECT name, type FROM entities ORDER BY name`).all(); const knownEntities = db.prepare(`SELECT name, type FROM entities ORDER BY name`).all();
const promptw = buildExtractionPrompt(userMessage, aiResponse, knownEntities);
console.log('[entities] prompt preview:', JSON.stringify(promptw.slice(0, 500)));
const res = await fetch(`${EXTRACTION_URL}/api/generate`, { const res = await fetch(`${EXTRACTION_URL}/api/generate`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },