now uses name of discord user

This commit is contained in:
Luna
2026-03-03 20:59:23 +01:00
parent 931f222979
commit 55b5e88acb
2 changed files with 14 additions and 0 deletions

View File

@@ -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 });

View File

@@ -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.');