adding in entity extraction layer

This commit is contained in:
Storme-bit
2026-04-17 05:54:33 -07:00
parent 4070eb5559
commit 0cad85d4a7

View File

@@ -8,16 +8,33 @@ const ENTITY_TYPES = ['person', 'place', 'project', 'technology', 'concept', 'or
function buildExtractionPrompt(userMessage, aiResponse) { function buildExtractionPrompt(userMessage, aiResponse) {
return [ return [
'Extract named entities from the conversation below.', '<|im_start|>system',
`Valid entity types: ${ENTITY_TYPES.join(', ')}.`, 'You are an entity extraction assistant. You extract named entities from conversations and return them as a JSON array. You never return empty arrays when entities are present. You only output valid JSON.<|im_end|>',
'Return ONLY a JSON array. No explanation, no markdown, no code fences.', '<|im_start|>user',
'Each item must have exactly these fields: "name" (string), "type" (one of the valid types), "notes" (one sentence fact about this entity from the conversation).', 'Extract all named entities from this conversation.',
'If no entities are found, return: []',
'', '',
`Valid types: ${ENTITY_TYPES.join(', ')}`,
'',
'Examples of entities to extract:',
'- People: names of individuals',
'- Projects: software projects, systems, tools being built',
'- Technologies: databases, frameworks, languages, hardware',
'- Organizations: companies, teams',
'- Places: locations, servers, infrastructure',
'',
'Return a JSON array where each item has:',
' "name": the entity name',
' "type": one of the valid types above',
' "notes": one sentence describing this entity based on the conversation',
'',
'### Conversation:',
`User: ${userMessage}`, `User: ${userMessage}`,
`Assistant: ${aiResponse}`, `Assistant: ${aiResponse}`,
'', '',
'JSON array:', '### Extracted entities as JSON array:',
'<|im_end|>',
'<|im_start|>assistant',
'[',
].join('\n'); ].join('\n');
} }
@@ -26,7 +43,7 @@ async function extractAndStoreEntities(userMessage, aiResponse) {
userMessage: userMessage?.slice(0, 100), userMessage: userMessage?.slice(0, 100),
aiResponse: aiResponse?.slice(0, 100) aiResponse: aiResponse?.slice(0, 100)
}); });
console.log('[entities] Extraction triggered') console.log('[entities] Extraction triggered')
try { try {
const res = await fetch(`${EXTRACTION_URL}/api/generate`, { const res = await fetch(`${EXTRACTION_URL}/api/generate`, {