adding in entity extraction layer
This commit is contained in:
@@ -8,16 +8,33 @@ const ENTITY_TYPES = ['person', 'place', 'project', 'technology', 'concept', 'or
|
||||
|
||||
function buildExtractionPrompt(userMessage, aiResponse) {
|
||||
return [
|
||||
'Extract named entities from the conversation below.',
|
||||
`Valid entity types: ${ENTITY_TYPES.join(', ')}.`,
|
||||
'Return ONLY a JSON array. No explanation, no markdown, no code fences.',
|
||||
'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).',
|
||||
'If no entities are found, return: []',
|
||||
'<|im_start|>system',
|
||||
'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|>',
|
||||
'<|im_start|>user',
|
||||
'Extract all named entities from this conversation.',
|
||||
'',
|
||||
`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}`,
|
||||
`Assistant: ${aiResponse}`,
|
||||
'',
|
||||
'JSON array:',
|
||||
'### Extracted entities as JSON array:',
|
||||
'<|im_end|>',
|
||||
'<|im_start|>assistant',
|
||||
'[',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
@@ -26,7 +43,7 @@ async function extractAndStoreEntities(userMessage, aiResponse) {
|
||||
userMessage: userMessage?.slice(0, 100),
|
||||
aiResponse: aiResponse?.slice(0, 100)
|
||||
});
|
||||
|
||||
|
||||
console.log('[entities] Extraction triggered')
|
||||
try {
|
||||
const res = await fetch(`${EXTRACTION_URL}/api/generate`, {
|
||||
|
||||
Reference in New Issue
Block a user