From fa13ae77afeef3b22e05ef8ef97275e7fa9f12eb Mon Sep 17 00:00:00 2001 From: jrmyr Date: Mon, 5 May 2025 11:30:34 +0000 Subject: [PATCH] Responses context update. --- _opt/responses.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/_opt/responses.js b/_opt/responses.js index 59edca7..6b60bec 100644 --- a/_opt/responses.js +++ b/_opt/responses.js @@ -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,