diff --git a/src/bot.js b/src/bot.js index 07f602c..feba649 100644 --- a/src/bot.js +++ b/src/bot.js @@ -37,6 +37,7 @@ function cacheContext(userId, context) { shortTerm: cloneShortTerm(context.shortTerm || []), summary: context.summary, memories: cloneMemories(context.memories || []), + userName: context.userName || null, }; contextCache.set(userId, { context: snapshot, timestamp: Date.now() }); return snapshot; @@ -201,6 +202,7 @@ function startContinuationForUser(userId, channel) { const cachedContext = getCachedContext(userId); const { messages, debug } = await buildPrompt(userId, incomingText, { context: cachedContext, + userName: cachedContext?.userName || null, }); cacheContext(userId, debug.context); const reply = await chatCompletion(messages, { temperature: 0.7, maxTokens: 200 }); @@ -694,6 +696,7 @@ client.on('messageCreate', async (message) => { liveIntel: intelMeta.liveIntel, blockedSearchTerm: intelMeta.blockedSearchTerm, searchOutage: intelMeta.searchOutage, + userName: message.member?.displayName || message.author.username, }); cacheContext(userId, debug.context); const reply = await chatCompletion(messages, { temperature: 0.6, maxTokens: 200 }); diff --git a/src/prompt.js b/src/prompt.js index 28ae2cb..cae6574 100644 --- a/src/prompt.js +++ b/src/prompt.js @@ -94,9 +94,15 @@ export async function buildPrompt(userId, incomingText, options = {}) { searchOutage = null, context: providedContext = null, useGlobalMemories = false, + userName = null, } = options; const context = providedContext || (await prepareContext(userId, incomingText, { includeAllUsers: useGlobalMemories })); + if (userName) { + context.userName = userName; + } else if (context.userName === undefined) { + context.userName = null; + } const memoryLines = context.memories.length ? context.memories .map((m) => @@ -121,6 +127,11 @@ export async function buildPrompt(userId, incomingText, options = {}) { ' Adjust emoji usage, sarcasm, response length, and overall energy accordingly.', ); } + if (context.userName) { + systemPromptParts.push(`System: You are currently chatting with ${context.userName}. Anchor each reply to them.`); + } else { + systemPromptParts.push(`System: You are currently chatting with Discord user ${userId}. Keep that connection in mind.`); + } systemPromptParts.push(STATIC_SYSTEM_PROMPT); if (searchOutage) { systemPromptParts.push('System: Google search is currently offline; be transparent about the outage and continue without searching until it returns.');