extraction error logging
This commit is contained in:
@@ -22,17 +22,19 @@ function buildExtractionPrompt(userMessage, aiResponse, knownEntities = []) {
|
||||
'You are a named entity extractor. You output only valid JSON.',
|
||||
'<|im_end|>',
|
||||
'<|im_start|>user',
|
||||
'Extract all named entities from this conversation.',
|
||||
`Valid types: ${ENTITY_TYPES.join(', ')}`,
|
||||
'Read the conversation below and extract every named entity mentioned.',
|
||||
`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,
|
||||
'Return a JSON object: { "entities": [ { "name": "...", "type": "...", "notes": "..." } ] }',
|
||||
'Only include items where type is one of the valid types.',
|
||||
'',
|
||||
'--- CONVERSATION ---', // clear delimiter helps smaller models
|
||||
`User: ${userMessage}`,
|
||||
`Assistant: ${aiResponse}`,
|
||||
'--- END CONVERSATION ---',
|
||||
'<|im_end|>',
|
||||
'<|im_start|>assistant',
|
||||
'{"entities":', // primer nudges it to start filling the array
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
@@ -58,6 +60,10 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
const db = require('../db').getDB();
|
||||
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`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
Reference in New Issue
Block a user