Responses context update.

This commit is contained in:
jrmyr 2025-05-05 11:30:34 +00:00
parent 0dba97890e
commit fa13ae77af

View File

@ -272,12 +272,29 @@ async function onMessage(client, cfg, message) {
client.logger.error(`Error checking score: ${err.message}`);
}
}
// Build request body, prefixing with a mention of who spoke
// Build request body, including replied-to message context and mention of who spoke
let referencePrefix = '';
if (message.reference?.messageId) {
try {
const ref = await message.channel.messages.fetch(message.reference.messageId);
const refContent = ref.content || '';
if (ref.author.id === botId) {
referencePrefix = `You said: ${refContent}`;
} else {
referencePrefix = `<@${ref.author.id}> said: ${refContent}`;
}
} catch {
// ignore fetch errors
}
}
const speakerMention = `<@${message.author.id}>`;
const userInput = referencePrefix
? `${referencePrefix}\n${speakerMention} said to you: ${message.content}`
: `${speakerMention} said to you: ${message.content}`;
const body = {
model: cfg.defaultModel,
instructions: client.responsesPrompt,
input: `${speakerMention} said to you: ${message.content}`,
input: userInput,
previous_response_id: prev,
max_output_tokens: cfg.defaultMaxTokens,
temperature: cfg.defaultTemperature,