extraction error logging
This commit is contained in:
@@ -77,9 +77,12 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
|||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const raw = data.response?.trim() ?? '';
|
const raw = data.response?.trim() ?? '';
|
||||||
|
console.log('[entities] raw response:', raw.slice(0, 300));
|
||||||
|
|
||||||
// Strip markdown fences defensively — small models sometimes add them anyway
|
// Extract just the JSON array — everything from [ to the last ]
|
||||||
const clean = raw.replace(/^```(?:json)?\n?/, '').replace(/\n?```$/, '').trim();
|
const match = raw.match(/\[[\s\S]*\]/);
|
||||||
|
if (!match) throw new Error('No JSON array found in response');
|
||||||
|
const clean = match[0];
|
||||||
const entities = JSON.parse(clean);
|
const entities = JSON.parse(clean);
|
||||||
|
|
||||||
if (!Array.isArray(entities)) throw new Error('Response was not a JSON array');
|
if (!Array.isArray(entities)) throw new Error('Response was not a JSON array');
|
||||||
|
|||||||
Reference in New Issue
Block a user