sync: description generation fix - simplified prompt

This commit is contained in:
“BeeRad”
2026-01-13 11:38:25 +11:00
parent 4f030c7d29
commit f7b8b2058c
3 changed files with 34 additions and 48 deletions
+14 -33
View File
@@ -4,6 +4,7 @@ import { generateText } from 'ai';
export interface DescriptionInput {
title: string;
content?: string;
link?: string;
metadata?: {
source?: string;
channel_name?: string;
@@ -11,11 +12,12 @@ export interface DescriptionInput {
site_name?: string;
};
type?: string;
dimensions?: string[];
}
/**
* Generate a 280-character description for a knowledge node.
* The description starts with "This is a..." and identifies the content type.
* Contextually grounded - adapts to node type (person, concept, article, etc.)
*/
export async function generateDescription(input: DescriptionInput): Promise<string> {
try {
@@ -32,7 +34,7 @@ export async function generateDescription(input: DescriptionInput): Promise<stri
const description = response.text.trim();
// Ensure it starts with "This is a" and is within limit
// Ensure within character limit
const finalDescription = description.slice(0, 280);
console.log(`[DescriptionService] Generated: "${finalDescription}"`);
@@ -46,41 +48,20 @@ export async function generateDescription(input: DescriptionInput): Promise<stri
}
function buildDescriptionPrompt(input: DescriptionInput): string {
const metadataLines: string[] = [];
const lines: string[] = [`Title: ${input.title}`];
if (input.metadata?.source) {
metadataLines.push(`Source: ${input.metadata.source}`);
}
if (input.metadata?.channel_name) {
metadataLines.push(`Channel: ${input.metadata.channel_name}`);
}
if (input.metadata?.author) {
metadataLines.push(`Author: ${input.metadata.author}`);
}
if (input.metadata?.site_name) {
metadataLines.push(`Site: ${input.metadata.site_name}`);
}
if (input.type) {
metadataLines.push(`Type: ${input.type}`);
}
if (input.link) lines.push(`URL: ${input.link}`);
if (input.dimensions?.length) lines.push(`Dimensions: ${input.dimensions.join(', ')}`);
if (input.metadata?.channel_name) lines.push(`Channel: ${input.metadata.channel_name}`);
if (input.metadata?.author) lines.push(`Author: ${input.metadata.author}`);
if (input.metadata?.site_name) lines.push(`Site: ${input.metadata.site_name}`);
const contentPreview = input.content?.slice(0, 500) || '';
const contentPreview = input.content?.slice(0, 800) || '';
if (contentPreview) lines.push(`Content: ${contentPreview}${input.content && input.content.length > 800 ? '...' : ''}`);
return `Generate a concise description (max 280 characters) for this knowledge item.
return `Your job is to do your best to answer 'what is this' - the most simple, high level contextual information of what this thing is. Users will be adding a variety of different nodes (ideas, books, podcasts, people, papers etc). Do your best to take the available information and infer what it is - high level. If unsure, that's fine just give your best guess and say you're unsure. Max 280 characters.
CRITICAL REQUIREMENTS:
- Start with "This is a..."
- Identify the content type (article, video, paper, podcast episode, tweet, book, tutorial, etc.)
- Be specific about what the content covers
- Maximum 280 characters total
=== KNOWLEDGE ITEM ===
Title: ${input.title}
${metadataLines.length > 0 ? metadataLines.join('\n') : ''}
${contentPreview ? `\nContent preview: ${contentPreview}${input.content && input.content.length > 500 ? '...' : ''}` : ''}
=== YOUR RESPONSE ===
Write ONLY the description, nothing else. Start with "This is a..."`;
${lines.join('\n')}`;
}
export const descriptionService = {