now uses name of discord user
This commit is contained in:
@@ -37,6 +37,7 @@ function cacheContext(userId, context) {
|
|||||||
shortTerm: cloneShortTerm(context.shortTerm || []),
|
shortTerm: cloneShortTerm(context.shortTerm || []),
|
||||||
summary: context.summary,
|
summary: context.summary,
|
||||||
memories: cloneMemories(context.memories || []),
|
memories: cloneMemories(context.memories || []),
|
||||||
|
userName: context.userName || null,
|
||||||
};
|
};
|
||||||
contextCache.set(userId, { context: snapshot, timestamp: Date.now() });
|
contextCache.set(userId, { context: snapshot, timestamp: Date.now() });
|
||||||
return snapshot;
|
return snapshot;
|
||||||
@@ -201,6 +202,7 @@ function startContinuationForUser(userId, channel) {
|
|||||||
const cachedContext = getCachedContext(userId);
|
const cachedContext = getCachedContext(userId);
|
||||||
const { messages, debug } = await buildPrompt(userId, incomingText, {
|
const { messages, debug } = await buildPrompt(userId, incomingText, {
|
||||||
context: cachedContext,
|
context: cachedContext,
|
||||||
|
userName: cachedContext?.userName || null,
|
||||||
});
|
});
|
||||||
cacheContext(userId, debug.context);
|
cacheContext(userId, debug.context);
|
||||||
const reply = await chatCompletion(messages, { temperature: 0.7, maxTokens: 200 });
|
const reply = await chatCompletion(messages, { temperature: 0.7, maxTokens: 200 });
|
||||||
@@ -694,6 +696,7 @@ client.on('messageCreate', async (message) => {
|
|||||||
liveIntel: intelMeta.liveIntel,
|
liveIntel: intelMeta.liveIntel,
|
||||||
blockedSearchTerm: intelMeta.blockedSearchTerm,
|
blockedSearchTerm: intelMeta.blockedSearchTerm,
|
||||||
searchOutage: intelMeta.searchOutage,
|
searchOutage: intelMeta.searchOutage,
|
||||||
|
userName: message.member?.displayName || message.author.username,
|
||||||
});
|
});
|
||||||
cacheContext(userId, debug.context);
|
cacheContext(userId, debug.context);
|
||||||
const reply = await chatCompletion(messages, { temperature: 0.6, maxTokens: 200 });
|
const reply = await chatCompletion(messages, { temperature: 0.6, maxTokens: 200 });
|
||||||
|
|||||||
@@ -94,9 +94,15 @@ export async function buildPrompt(userId, incomingText, options = {}) {
|
|||||||
searchOutage = null,
|
searchOutage = null,
|
||||||
context: providedContext = null,
|
context: providedContext = null,
|
||||||
useGlobalMemories = false,
|
useGlobalMemories = false,
|
||||||
|
userName = null,
|
||||||
} = options;
|
} = options;
|
||||||
const context =
|
const context =
|
||||||
providedContext || (await prepareContext(userId, incomingText, { includeAllUsers: useGlobalMemories }));
|
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
|
const memoryLines = context.memories.length
|
||||||
? context.memories
|
? context.memories
|
||||||
.map((m) =>
|
.map((m) =>
|
||||||
@@ -121,6 +127,11 @@ export async function buildPrompt(userId, incomingText, options = {}) {
|
|||||||
' Adjust emoji usage, sarcasm, response length, and overall energy accordingly.',
|
' 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);
|
systemPromptParts.push(STATIC_SYSTEM_PROMPT);
|
||||||
if (searchOutage) {
|
if (searchOutage) {
|
||||||
systemPromptParts.push('System: Google search is currently offline; be transparent about the outage and continue without searching until it returns.');
|
systemPromptParts.push('System: Google search is currently offline; be transparent about the outage and continue without searching until it returns.');
|
||||||
|
|||||||
Reference in New Issue
Block a user