adding in entity extraction layer

This commit is contained in:
Storme-bit
2026-04-17 05:50:54 -07:00
parent 940b636175
commit ba1e6b32e7

View File

@@ -43,11 +43,13 @@ async function extractAndStoreEntities(userMessage, aiResponse) {
if (!res.ok) throw new Error(`Ollama responded ${res.status}`); if (!res.ok) throw new Error(`Ollama responded ${res.status}`);
const data = await res.json(); const data = await res.json();
console.log('[entities] Raw response:', data.response?.slice(0, 200));
const raw = data.response?.trim() ?? ''; const raw = data.response?.trim() ?? '';
// Strip markdown fences defensively — small models sometimes add them anyway // Strip markdown fences defensively — small models sometimes add them anyway
const clean = raw.replace(/^```(?:json)?\n?/, '').replace(/\n?```$/, '').trim(); const clean = raw.replace(/^```(?:json)?\n?/, '').replace(/\n?```$/, '').trim();
const entities = JSON.parse(clean); const entities = JSON.parse(clean);
console.log('[entities] Parsed entities:', entities);
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');