extraction error logging
This commit is contained in:
@@ -29,6 +29,9 @@ function buildExtractionPrompt(userMessage, aiResponse, knownEntities = []) {
|
|||||||
' "type": one of the valid types above',
|
' "type": one of the valid types above',
|
||||||
' "notes": one sentence describing this entity based on the conversation',
|
' "notes": one sentence describing this entity based on the conversation',
|
||||||
'',
|
'',
|
||||||
|
'Extract all named entities from this conversation.',
|
||||||
|
'Respond with ONLY a JSON array. Start your response with [ and end with ].',
|
||||||
|
'Do not include any text before or after the array.',
|
||||||
`User: ${userMessage}`,
|
`User: ${userMessage}`,
|
||||||
`Assistant: ${aiResponse}`,
|
`Assistant: ${aiResponse}`,
|
||||||
'<|end|>',
|
'<|end|>',
|
||||||
@@ -68,7 +71,7 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
|||||||
stream: false,
|
stream: false,
|
||||||
options: {
|
options: {
|
||||||
temperature: 0.1,
|
temperature: 0.1,
|
||||||
num_predict: 768,
|
num_predict: 1024,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -80,8 +83,15 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
|||||||
console.log('[entities] raw response:', JSON.stringify(raw.slice(0, 300)));
|
console.log('[entities] raw response:', JSON.stringify(raw.slice(0, 300)));
|
||||||
|
|
||||||
// Extract just the JSON array — everything from [ to the last ]
|
// Extract just the JSON array — everything from [ to the last ]
|
||||||
const stripped = raw.replace(/```(?:json)?/g, '').trim();
|
let normalized = raw.replace(/```(?:json)?/g, '').trim();
|
||||||
const match = stripped.match(/\[[\s\S]*\]/);
|
if (!normalized.startsWith('[')) {
|
||||||
|
normalized = '[' + normalized;
|
||||||
|
}
|
||||||
|
if (!normalized.endsWith(']')) {
|
||||||
|
// Trim any trailing comma or incomplete object before closing
|
||||||
|
normalized = normalized.replace(/,?\s*\{[^}]*$/, '') + ']';
|
||||||
|
}
|
||||||
|
const match = normalized.match(/\[[\s\S]*\]/);
|
||||||
|
|
||||||
if (!match) throw new Error('No JSON array found in response');
|
if (!match) throw new Error('No JSON array found in response');
|
||||||
const clean = match[0];
|
const clean = match[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user