Responses updates.
This commit is contained in:
parent
fa13ae77af
commit
7df051795a
@ -274,9 +274,11 @@ async function onMessage(client, cfg, message) {
|
|||||||
}
|
}
|
||||||
// Build request body, including replied-to message context and mention of who spoke
|
// Build request body, including replied-to message context and mention of who spoke
|
||||||
let referencePrefix = '';
|
let referencePrefix = '';
|
||||||
|
let referenceMessage = null;
|
||||||
if (message.reference?.messageId) {
|
if (message.reference?.messageId) {
|
||||||
try {
|
try {
|
||||||
const ref = await message.channel.messages.fetch(message.reference.messageId);
|
const ref = await message.channel.messages.fetch(message.reference.messageId);
|
||||||
|
referenceMessage = ref;
|
||||||
const refContent = ref.content || '';
|
const refContent = ref.content || '';
|
||||||
if (ref.author.id === botId) {
|
if (ref.author.id === botId) {
|
||||||
referencePrefix = `You said: ${refContent}`;
|
referencePrefix = `You said: ${refContent}`;
|
||||||
@ -365,6 +367,23 @@ async function onMessage(client, cfg, message) {
|
|||||||
body.tools = tools;
|
body.tools = tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there are image attachments in the referenced or current message, wrap text and images into a multimodal message
|
||||||
|
const refImages = referenceMessage
|
||||||
|
? referenceMessage.attachments.filter(att => /\.(png|jpe?g|gif|webp)$/i.test(att.name || att.url))
|
||||||
|
: new Map();
|
||||||
|
const currImages = message.attachments.filter(att => /\.(png|jpe?g|gif|webp)$/i.test(att.name || att.url));
|
||||||
|
if (refImages.size > 0 || currImages.size > 0) {
|
||||||
|
// build ordered content items: text first, then referenced images, then current images
|
||||||
|
const contentItems = [{ type: 'input_text', text: userInput }];
|
||||||
|
for (const att of refImages.values()) {
|
||||||
|
contentItems.push({ type: 'input_image', detail: 'auto', image_url: att.url });
|
||||||
|
}
|
||||||
|
for (const att of currImages.values()) {
|
||||||
|
contentItems.push({ type: 'input_image', detail: 'auto', image_url: att.url });
|
||||||
|
}
|
||||||
|
body.input = [{ type: 'message', role: 'user', content: contentItems }];
|
||||||
|
}
|
||||||
|
|
||||||
// Call OpenAI Responses
|
// Call OpenAI Responses
|
||||||
logger.debug(`Calling AI with body: ${JSON.stringify(body)}`);
|
logger.debug(`Calling AI with body: ${JSON.stringify(body)}`);
|
||||||
const resp = await client.openai.responses.create(body);
|
const resp = await client.openai.responses.create(body);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user