Fix escape and add escape option
This commit is contained in:
@@ -104,19 +104,31 @@ const replacements = [
|
||||
';', //0xE9BF
|
||||
]
|
||||
|
||||
export function unescape(text:string){
|
||||
export function risuUnescape(text:string){
|
||||
return text.replace(/[\uE9b8-\uE9bf]/g, (f) => {
|
||||
const index = f.charCodeAt(0) - 0xE9B8
|
||||
return replacements[index]
|
||||
})
|
||||
}
|
||||
|
||||
export function risuEscape(text:string){
|
||||
return text.replace(/[{}()]/g, (f) => {
|
||||
switch(f){
|
||||
case '{': return '\uE9B8'
|
||||
case '}': return '\uE9B9'
|
||||
case '(': return '\uE9BA'
|
||||
case ')': return '\uE9BB'
|
||||
default: return f
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function renderMarkdown(md:markdownit, data:string){
|
||||
let quotes = ['“', '”', '‘', '’']
|
||||
if(DBState.db?.customQuotes){
|
||||
quotes = DBState.db.customQuotesData ?? quotes
|
||||
}
|
||||
let text = unescape(md.render(data.replace(/“|”/g, '"').replace(/‘|’/g, "'")))
|
||||
let text = risuUnescape(md.render(data.replace(/“|”/g, '"').replace(/‘|’/g, "'")))
|
||||
|
||||
if(DBState.db?.unformatQuotes){
|
||||
text = text.replace(/\uE9b0/gu, quotes[0]).replace(/\uE9b1/gu, quotes[1])
|
||||
@@ -2210,28 +2222,7 @@ function blockEndMatcher(p1:string,type:{type:blockMatch,type2?:string},matcherA
|
||||
})
|
||||
}
|
||||
case 'escape':{
|
||||
return p1Trimed.replace(/[\{\}\<\>\(\)\:\;]/g,(m) => {
|
||||
switch(m){
|
||||
case '{':
|
||||
return '\uE9B8'
|
||||
case '}':
|
||||
return '\uE9B9'
|
||||
case '<':
|
||||
return '\uE9BC'
|
||||
case '>':
|
||||
return '\uE9BD'
|
||||
case '(':
|
||||
return '\uE9BA'
|
||||
case ')':
|
||||
return '\uE9BB'
|
||||
case ':':
|
||||
return '\uE9BE'
|
||||
case ';':
|
||||
return '\uE9BF'
|
||||
default:
|
||||
return m
|
||||
}
|
||||
})
|
||||
return risuEscape(p1Trimed)
|
||||
}
|
||||
default:{
|
||||
return ''
|
||||
|
||||
@@ -1374,7 +1374,8 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
continue: arg.continue,
|
||||
chatId: generationId,
|
||||
imageResponse: DBState.db.outputImageModal,
|
||||
previewBody: arg.previewPrompt
|
||||
previewBody: arg.previewPrompt,
|
||||
escape: nowChatroom.type === 'character' && nowChatroom.escapeOutput
|
||||
}, 'model', abortSignal)
|
||||
|
||||
console.log(req)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { addFetchLog, fetchNative, globalFetch, isNodeServer, isTauri, textifyRe
|
||||
import { sleep } from "../util";
|
||||
import { NovelAIBadWordIds, stringlizeNAIChat } from "./models/nai";
|
||||
import { strongBan, tokenize, tokenizeNum } from "../tokenizer";
|
||||
import { risuChatParser } from "../parser.svelte";
|
||||
import { risuChatParser, risuEscape } from "../parser.svelte";
|
||||
import { SignatureV4 } from "@smithy/signature-v4";
|
||||
import { HttpRequest } from "@smithy/protocol-http";
|
||||
import { Sha256 } from "@aws-crypto/sha256-js";
|
||||
@@ -23,8 +23,7 @@ import { getModelInfo, LLMFlags, LLMFormat, type LLMModel } from "../model/model
|
||||
import { runTrigger } from "./triggers";
|
||||
import { registerClaudeObserver } from "../observer.svelte";
|
||||
import { v4 } from "uuid";
|
||||
import { DBState } from "../stores.svelte";
|
||||
import { unescape } from "lodash";
|
||||
import { risuUnescape } from "../parser.svelte";
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +47,7 @@ interface requestDataArgument{
|
||||
imageResponse?:boolean
|
||||
previewBody?:boolean
|
||||
staticModel?: string
|
||||
escape?:boolean
|
||||
}
|
||||
|
||||
interface RequestDataArgumentExtended extends requestDataArgument{
|
||||
@@ -275,8 +275,13 @@ export async function requestChatData(arg:requestDataArgument, model:ModelModeEx
|
||||
fallBackModels.push('')
|
||||
let da:requestDataResponse
|
||||
|
||||
if(arg.escape){
|
||||
arg.useStreaming = false
|
||||
console.warn('Escape is enabled, disabling streaming')
|
||||
}
|
||||
|
||||
const originalFormated = safeStructuredClone(arg.formated).map(m => {
|
||||
m.content = unescape(m.content)
|
||||
m.content = risuUnescape(m.content)
|
||||
return m
|
||||
})
|
||||
|
||||
@@ -337,6 +342,10 @@ export async function requestChatData(arg:requestDataArgument, model:ModelModeEx
|
||||
result: 'Aborted'
|
||||
}
|
||||
}
|
||||
|
||||
if(da.type === 'success' && arg.escape){
|
||||
da.result = risuEscape(da.result)
|
||||
}
|
||||
|
||||
if(da.type === 'success' && pluginV2.replacerafterRequest.size > 0){
|
||||
for(const replacer of pluginV2.replacerafterRequest){
|
||||
|
||||
@@ -1210,6 +1210,7 @@ export interface character{
|
||||
lastInteraction?:number
|
||||
translatorNote?:string
|
||||
doNotChangeSeperateModels?:boolean
|
||||
escapeOutput?:boolean
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user