Add inlayErrorResponse

This commit is contained in:
Kwaroran
2025-01-31 17:38:14 +09:00
parent 8174c6dcde
commit 757a944686
6 changed files with 52 additions and 12 deletions

View File

@@ -842,4 +842,5 @@ export const languageEnglish = {
checkCorruption: "Check Corruption", checkCorruption: "Check Corruption",
showPromptComparison: "Show Prompt Comparison", showPromptComparison: "Show Prompt Comparison",
hypaV3Desc: "HypaMemory V3 is a long-term memory system that use both summarized data and vector search.", hypaV3Desc: "HypaMemory V3 is a long-term memory system that use both summarized data and vector search.",
inlayErrorResponse: "Inlay Error Response",
} }

View File

@@ -50,4 +50,8 @@
<div class="flex items-center mt-2"> <div class="flex items-center mt-2">
<Check bind:check={DBState.db.requestInfoInsideChat} name={language.requestInfoInsideChat}/> <Check bind:check={DBState.db.requestInfoInsideChat} name={language.requestInfoInsideChat}/>
</div>
<div class="flex items-center mt-2">
<Check bind:check={DBState.db.inlayErrorResponse} name={language.inlayErrorResponse}/>
</div> </div>

View File

@@ -260,6 +260,14 @@ html, body{
@apply rounded-lg focus:outline-none max-w-80 w-full @apply rounded-lg focus:outline-none max-w-80 w-full
} }
.x-risu-risu-error {
@apply border-2 border-red-700 bg-red-500 text-white rounded-md shadow-sm focus:outline-none transition-colors duration-200 px-4 py-2 min-w-0 break-words
}
.x-risu-risu-error h1 {
@apply text-xl mb-2
}
.z-100{ .z-100{
z-index: 100; z-index: 100;
} }

View File

@@ -255,6 +255,11 @@ async function renderHighlightableMarkdown(data:string) {
} }
break break
} }
case 'risuerror':{
lang = 'error'
shotLang = 'error'
break
}
default:{ default:{
lang = 'none' lang = 'none'
shotLang = 'none' shotLang = 'none'
@@ -266,6 +271,9 @@ async function renderHighlightableMarkdown(data:string) {
if(lang === 'none'){ if(lang === 'none'){
rendered = rendered.replace(placeholder, `<pre><code>${md.utils.escapeHtml(code)}</code></pre>`) rendered = rendered.replace(placeholder, `<pre><code>${md.utils.escapeHtml(code)}</code></pre>`)
} }
else if(lang === 'error'){
rendered = rendered.replace(placeholder, `<div class="risu-error"><h1>${language.error}</h1>${md.utils.escapeHtml(code)}</div>`)
}
else{ else{
const highlighted = hljs.highlight(code, { const highlighted = hljs.highlight(code, {
language: lang, language: lang,
@@ -285,7 +293,7 @@ async function renderHighlightableMarkdown(data:string) {
} }
export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/g export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/gms
async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){
const assetWidthString = (DBState.db.assetWidth && DBState.db.assetWidth !== -1 || DBState.db.assetWidth === 0) ? `max-width:${DBState.db.assetWidth}rem;` : '' const assetWidthString = (DBState.db.assetWidth && DBState.db.assetWidth !== -1 || DBState.db.assetWidth === 0) ? `max-width:${DBState.db.assetWidth}rem;` : ''

View File

@@ -102,6 +102,24 @@ export async function sendChat(chatProcessIndex = -1,arg:{
return data.trim() return data.trim()
} }
function throwError(error:string){
if(DBState.db.inlayErrorResponse){
DBState.db.characters[selectedChar].chats[selectedChat].message.push({
role: 'char',
data: `\`\`\`risuerror\n${error}\n\`\`\``,
saying: currentChar.chaId,
time: Date.now(),
generationInfo,
})
return
}
alertError(error)
return
}
let isDoing = get(doingChat) let isDoing = get(doingChat)
if(isDoing){ if(isDoing){
@@ -134,7 +152,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
if(!peerSafe){ if(!peerSafe){
peerRevertChat() peerRevertChat()
doingChat.set(false) doingChat.set(false)
alertError(language.otherUserRequesting) throwError(language.otherUserRequesting)
return false return false
} }
await peerSync() await peerSync()
@@ -198,7 +216,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
else{ else{
currentChar = findCharacterbyIdwithCache(nowChatroom.characters[chatProcessIndex]) currentChar = findCharacterbyIdwithCache(nowChatroom.characters[chatProcessIndex])
if(!currentChar){ if(!currentChar){
alertError(`cannot find character: ${nowChatroom.characters[chatProcessIndex]}`) throwError(`cannot find character: ${nowChatroom.characters[chatProcessIndex]}`)
return false return false
} }
} }
@@ -815,7 +833,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
const sp = await hypaMemoryV2(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer) const sp = await hypaMemoryV2(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer)
if(sp.error){ if(sp.error){
console.log(sp) console.log(sp)
alertError(sp.error) throwError(sp.error)
return false return false
} }
chats = sp.chats chats = sp.chats
@@ -836,7 +854,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
DBState.db.characters[selectedChar].chats[selectedChat].hypaV3Data = currentChat.hypaV3Data DBState.db.characters[selectedChar].chats[selectedChat].hypaV3Data = currentChat.hypaV3Data
} }
console.log(sp) console.log(sp)
alertError(sp.error) throwError(sp.error)
return false return false
} }
chats = sp.chats chats = sp.chats
@@ -852,7 +870,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
asHyper: DBState.db.hypaMemory asHyper: DBState.db.hypaMemory
}) })
if(sp.error){ if(sp.error){
alertError(sp.error) throwError(sp.error)
return false return false
} }
chats = sp.chats chats = sp.chats
@@ -867,7 +885,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
else{ else{
while(currentTokens > maxContextTokens){ while(currentTokens > maxContextTokens){
if(chats.length <= 1){ if(chats.length <= 1){
alertError(language.errors.toomuchtoken + "\n\nRequired Tokens: " + currentTokens) throwError(language.errors.toomuchtoken + "\n\nRequired Tokens: " + currentTokens)
return false return false
} }
@@ -1158,7 +1176,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
let pointer = 0 let pointer = 0
while(inputTokens > maxContextTokens){ while(inputTokens > maxContextTokens){
if(pointer >= formated.length){ if(pointer >= formated.length){
alertError(language.errors.toomuchtoken + "\n\nAt token rechecking. Required Tokens: " + inputTokens) throwError(language.errors.toomuchtoken + "\n\nAt token rechecking. Required Tokens: " + inputTokens)
return false return false
} }
if(formated[pointer].removable){ if(formated[pointer].removable){
@@ -1212,7 +1230,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
return false return false
} }
if(req.type === 'fail'){ if(req.type === 'fail'){
alertError(req.result) throwError(req.result)
return false return false
} }
else if(req.type === 'streaming'){ else if(req.type === 'streaming'){
@@ -1553,7 +1571,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
if(abortSignal.aborted){ if(abortSignal.aborted){
return true return true
} }
alertError(`${rq.result}`) throwError(`${rq.result}`)
return true return true
} }
else{ else{
@@ -1594,7 +1612,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
emotionSelected = true emotionSelected = true
} }
} catch (error) { } catch (error) {
alertError(language.errors.httpError + `${error}`) throwError(language.errors.httpError + `${error}`)
return true return true
} }
} }
@@ -1605,7 +1623,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
} }
else if(currentChar.viewScreen === 'imggen'){ else if(currentChar.viewScreen === 'imggen'){
if(chatProcessIndex !== -1){ if(chatProcessIndex !== -1){
alertError("Stable diffusion in group chat is not supported") throwError("Stable diffusion in group chat is not supported")
} }
const msgs = DBState.db.characters[selectedChar].chats[selectedChat].message const msgs = DBState.db.characters[selectedChar].chats[selectedChat].message

View File

@@ -895,6 +895,7 @@ export interface Database{
processRegexScript: boolean processRegexScript: boolean
}, },
OaiCompAPIKeys: {[key:string]:string} OaiCompAPIKeys: {[key:string]:string}
inlayErrorResponse:boolean
} }
interface SeparateParameters{ interface SeparateParameters{