Update inlay syntax to support 'inlayed' type and adjust parsing logic
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
|
||||
if(fileInput.length > 0){
|
||||
for(const file of fileInput){
|
||||
messageInput += `{{inlay::${file}}}`
|
||||
messageInput += `{{inlayed::${file}}}`
|
||||
}
|
||||
fileInput = []
|
||||
}
|
||||
|
||||
@@ -429,19 +429,24 @@ function getClosestMatch(name:string, assetPaths:{[key:string]:{path:string, ext
|
||||
}
|
||||
|
||||
async function parseInlayAssets(data:string){
|
||||
const inlayMatch = data.match(/{{inlay::(.+?)}}/g)
|
||||
const inlayMatch = data.match(/{{(inlay|inlayed)::(.+?)}}/g)
|
||||
if(inlayMatch){
|
||||
for(const inlay of inlayMatch){
|
||||
const id = inlay.substring(9, inlay.length - 2)
|
||||
const inlayType = inlay.startsWith('{{inlayed') ? 'inlayed' : 'inlay'
|
||||
const id = inlay.substring(inlay.indexOf('::') + 2, inlay.length - 2)
|
||||
const asset = await getInlayAsset(id)
|
||||
if(asset?.type === 'image'){
|
||||
data = data.replace(inlay, `<div class="risu-inlay-image"><img src="${asset.data}"/></div>\n\n`)
|
||||
}
|
||||
if(asset?.type === 'video'){
|
||||
data = data.replace(inlay, `<div class="risu-inlay-image"><video controls><source src="${asset.data}" type="video/mp4"></video></div>\n\n`)
|
||||
}
|
||||
if(asset?.type === 'audio'){
|
||||
data = data.replace(inlay, `<div class="risu-inlay-image"><audio controls><source src="${asset.data}" type="audio/mpeg"></audio></div>\n\n`)
|
||||
let prefix = inlayType === 'inlayed' ? `<div class="risu-inlay-image">` : ''
|
||||
let postfix = inlayType === 'inlayed' ? `</div>\n\n` : ''
|
||||
switch(asset?.type){
|
||||
case 'image':
|
||||
data = data.replace(inlay, `${prefix}<img src="${asset.data}"/>${postfix}`)
|
||||
break
|
||||
case 'video':
|
||||
data = data.replace(inlay, `${prefix}<video controls><source src="${asset.data}" type="video/mp4"></video>${postfix}`)
|
||||
break
|
||||
case 'audio':
|
||||
data = data.replace(inlay, `${prefix}<audio controls><source src="${asset.data}" type="audio/mpeg"></audio>${postfix}`)
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -688,10 +688,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
}
|
||||
let inlays:string[] = []
|
||||
if(msg.role === 'char'){
|
||||
formatedChat = formatedChat.replace(/{{inlay::(.+?)}}/g, '')
|
||||
formatedChat = formatedChat.replace(/{{(inlay|inlayed)::(.+?)}}/g, '')
|
||||
}
|
||||
else{
|
||||
const inlayMatch = formatedChat.match(/{{inlay::(.+?)}}/g)
|
||||
const inlayMatch = formatedChat.match(/{{(inlay|inlayed)::(.+?)}}/g)
|
||||
if(inlayMatch){
|
||||
for(const inlay of inlayMatch){
|
||||
inlays.push(inlay)
|
||||
@@ -703,7 +703,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
const modelinfo = getModelInfo(DBState.db.aiModel)
|
||||
if(inlays.length > 0){
|
||||
for(const inlay of inlays){
|
||||
const inlayName = inlay.replace('{{inlay::', '').replace('}}', '')
|
||||
const inlayName = inlay.replace('{{inlayed::', '').replace('{{inlay::', '').replace('}}', '')
|
||||
const inlayData = await getInlayAsset(inlayName)
|
||||
if(inlayData?.type === 'image'){
|
||||
if(modelinfo.flags.includes(LLMFlags.hasImageInput)){
|
||||
|
||||
Reference in New Issue
Block a user