updated lite

This commit is contained in:
Concedo 2026-04-10 22:21:05 +08:00
parent 0f278d93b3
commit 9b95ade6cc

View file

@ -20797,10 +20797,47 @@ Current version indicated by LITEVER below.
oaiimgs = oai_append_media(oaiimgs);
if(mhistory.length>0 && oaiimgs.length>0)
{
mhistory[0].msg = [{type: 'text', text: mhistory[0].msg}];
for(let i=0;i<oaiimgs.length;++i)
//do we have the same number of images as placeholders? if so, assign each image to the right turns
let placeholder_count = 0;
const regex = /\n\(Attached (Image|Audio) \d+\)\n/g;
for(let i=0;i<mhistory.length;++i)
{
mhistory[0].msg.push(oaiimgs[i]);
const matches = mhistory[i].msg.match(regex);
const count = matches ? matches.length : 0;
placeholder_count += count;
}
if(placeholder_count==oaiimgs.length)
{
//exactly same number, so we can put images into matching turns
let mediaidx = 0;//for each occurance of the regex in this turn, insert mediaidx from oaiimgs and increment it
for (let i = 0; i < mhistory.length; ++i)
{
let msg = mhistory[i].msg;
const matches = msg.match(regex);
const count = matches ? matches.length : 0;
if(count>0)
{
msg = msg.replace(regex, '');
let newMsg = [{ type: 'text', text: msg }];
for (let j = 0; j < count; ++j)
{
if (mediaidx < oaiimgs.length)
{
newMsg.push(oaiimgs[mediaidx]);
mediaidx++;
}
}
mhistory[i].msg = newMsg;
}
}
}
else
{
mhistory[0].msg = [{type: 'text', text: mhistory[0].msg}];
for(let i=0;i<oaiimgs.length;++i)
{
mhistory[0].msg.push(oaiimgs[i]);
}
}
}
for(let i=0;i<mhistory.length;++i)