feat: add chatbot memory and conversational replies

This commit is contained in:
renato97
2025-12-01 03:18:47 +00:00
parent 7fb03b4aac
commit c21734220c
3 changed files with 13 additions and 6 deletions

View File

@@ -351,7 +351,7 @@ async function generateFromPrompt(prompt, options = {}) {
};
}
async function conversationalReply(prompt, library, sources) {
async function conversationalReply(prompt, library, sources, history = []) {
const context = {
prompt,
projects: library.slice(-5).map((entry) => ({
@@ -361,22 +361,29 @@ async function conversationalReply(prompt, library, sources) {
})),
sources: sources.slice(0, 20)
};
const historySummary = (history || [])
.slice(-10)
.map((msg) => `${msg.role === 'user' ? 'Usuario' : 'Bot'}: ${msg.text}`)
.join('\\n');
const text = await callAnthropic(
'Actúa como un productor musical amigable que ayuda a planear nuevos proyectos de Ableton Live. Responde en español latino, máximo 3 frases, incluye sugerencias creativas y cuándo usar \"generame un als ...\".',
`Usuario: ${prompt}\nContexto: ${JSON.stringify(context, null, 2)}`
`Historial reciente:\n${historySummary || 'Sin historial'}\nUsuario: ${prompt}\nContexto: ${JSON.stringify(context, null, 2)}`
);
if (text) {
return text.trim();
}
if (!library.length) {
return '¡Hola! Aún no tengo proyectos para tomar como referencia. Sube un .als y cuéntame qué estilo buscas; luego pide "generame un als ..." y prepararé una sesión.';
const vibe = prompt ? `Me encanta esa idea de ${prompt}. ` : '';
return `${vibe}Aún no tengo proyectos para tomar como referencia. Sube un .als y luego dime "generame un als ..." y prepararé una sesión nueva.`;
}
const recent = library.slice(-1)[0];
const srcText =
sources && sources.length
? `También veo ${sources.length} archivos en data/sources/ (ej: ${sources.slice(0, 3).join(', ')}). `
: '';
return `Hola, tengo ${library.length} proyectos guardados y el más reciente es "${recent.projectName}" (${recent.liveSet?.tempo || 'N/D'} BPM). ${srcText}Cuéntame la vibra y cuando digas "generame un als ..." lo construyo.`;
const vibe = prompt ? `Esa vibra de "${prompt}" suena genial. ` : '';
return `${vibe}Tengo ${library.length} proyectos guardados y el más reciente es "${recent.projectName}" (${recent.liveSet?.tempo || 'N/D'} BPM). ${srcText}Cuéntame más y cuando digas "generame un als ..." lo construyo.`;
}
module.exports = {