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