Fix escape and add escape option
This commit is contained in:
@@ -1128,5 +1128,6 @@ export const languageEnglish = {
|
|||||||
promptInfoEmptyMessage: "No prompt information is available for this message.",
|
promptInfoEmptyMessage: "No prompt information is available for this message.",
|
||||||
promptInfoEmptyToggle: "No custom toggles are currently active.",
|
promptInfoEmptyToggle: "No custom toggles are currently active.",
|
||||||
promptInfoEmptyText: "No prompt text has been saved.",
|
promptInfoEmptyText: "No prompt text has been saved.",
|
||||||
|
escapeOutput: "Escape Output",
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -995,4 +995,5 @@ export const languageKorean = {
|
|||||||
"promptInfoEmptyMessage": "이 메시지에 대한 프롬프트 정보가 없습니다.",
|
"promptInfoEmptyMessage": "이 메시지에 대한 프롬프트 정보가 없습니다.",
|
||||||
"promptInfoEmptyToggle": "활성화된 커스텀 토글이 없습니다.",
|
"promptInfoEmptyToggle": "활성화된 커스텀 토글이 없습니다.",
|
||||||
"promptInfoEmptyText": "저장된 프롬프트 텍스트가 없습니다.",
|
"promptInfoEmptyText": "저장된 프롬프트 텍스트가 없습니다.",
|
||||||
|
"escapeOutput": "출력 이스케이프",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1089,6 +1089,10 @@
|
|||||||
<span> <Help key="utilityBot" name={language.utilityBot}/></span>
|
<span> <Help key="utilityBot" name={language.utilityBot}/></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center mt-4">
|
||||||
|
<Check bind:check={DBState.db.characters[$selectedCharID].escapeOutput} name={language.escapeOutput}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if DBState.db.supaModelType !== 'none' && DBState.db.hypav2}
|
{#if DBState.db.supaModelType !== 'none' && DBState.db.hypav2}
|
||||||
<Button
|
<Button
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
|
|||||||
@@ -104,19 +104,31 @@ const replacements = [
|
|||||||
';', //0xE9BF
|
';', //0xE9BF
|
||||||
]
|
]
|
||||||
|
|
||||||
export function unescape(text:string){
|
export function risuUnescape(text:string){
|
||||||
return text.replace(/[\uE9b8-\uE9bf]/g, (f) => {
|
return text.replace(/[\uE9b8-\uE9bf]/g, (f) => {
|
||||||
const index = f.charCodeAt(0) - 0xE9B8
|
const index = f.charCodeAt(0) - 0xE9B8
|
||||||
return replacements[index]
|
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){
|
function renderMarkdown(md:markdownit, data:string){
|
||||||
let quotes = ['“', '”', '‘', '’']
|
let quotes = ['“', '”', '‘', '’']
|
||||||
if(DBState.db?.customQuotes){
|
if(DBState.db?.customQuotes){
|
||||||
quotes = DBState.db.customQuotesData ?? quotes
|
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){
|
if(DBState.db?.unformatQuotes){
|
||||||
text = text.replace(/\uE9b0/gu, quotes[0]).replace(/\uE9b1/gu, quotes[1])
|
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':{
|
case 'escape':{
|
||||||
return p1Trimed.replace(/[\{\}\<\>\(\)\:\;]/g,(m) => {
|
return risuEscape(p1Trimed)
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
default:{
|
default:{
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
@@ -1374,7 +1374,8 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
|||||||
continue: arg.continue,
|
continue: arg.continue,
|
||||||
chatId: generationId,
|
chatId: generationId,
|
||||||
imageResponse: DBState.db.outputImageModal,
|
imageResponse: DBState.db.outputImageModal,
|
||||||
previewBody: arg.previewPrompt
|
previewBody: arg.previewPrompt,
|
||||||
|
escape: nowChatroom.type === 'character' && nowChatroom.escapeOutput
|
||||||
}, 'model', abortSignal)
|
}, 'model', abortSignal)
|
||||||
|
|
||||||
console.log(req)
|
console.log(req)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { addFetchLog, fetchNative, globalFetch, isNodeServer, isTauri, textifyRe
|
|||||||
import { sleep } from "../util";
|
import { sleep } from "../util";
|
||||||
import { NovelAIBadWordIds, stringlizeNAIChat } from "./models/nai";
|
import { NovelAIBadWordIds, stringlizeNAIChat } from "./models/nai";
|
||||||
import { strongBan, tokenize, tokenizeNum } from "../tokenizer";
|
import { strongBan, tokenize, tokenizeNum } from "../tokenizer";
|
||||||
import { risuChatParser } from "../parser.svelte";
|
import { risuChatParser, risuEscape } from "../parser.svelte";
|
||||||
import { SignatureV4 } from "@smithy/signature-v4";
|
import { SignatureV4 } from "@smithy/signature-v4";
|
||||||
import { HttpRequest } from "@smithy/protocol-http";
|
import { HttpRequest } from "@smithy/protocol-http";
|
||||||
import { Sha256 } from "@aws-crypto/sha256-js";
|
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 { runTrigger } from "./triggers";
|
||||||
import { registerClaudeObserver } from "../observer.svelte";
|
import { registerClaudeObserver } from "../observer.svelte";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
import { DBState } from "../stores.svelte";
|
import { risuUnescape } from "../parser.svelte";
|
||||||
import { unescape } from "lodash";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +47,7 @@ interface requestDataArgument{
|
|||||||
imageResponse?:boolean
|
imageResponse?:boolean
|
||||||
previewBody?:boolean
|
previewBody?:boolean
|
||||||
staticModel?: string
|
staticModel?: string
|
||||||
|
escape?:boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestDataArgumentExtended extends requestDataArgument{
|
interface RequestDataArgumentExtended extends requestDataArgument{
|
||||||
@@ -275,8 +275,13 @@ export async function requestChatData(arg:requestDataArgument, model:ModelModeEx
|
|||||||
fallBackModels.push('')
|
fallBackModels.push('')
|
||||||
let da:requestDataResponse
|
let da:requestDataResponse
|
||||||
|
|
||||||
|
if(arg.escape){
|
||||||
|
arg.useStreaming = false
|
||||||
|
console.warn('Escape is enabled, disabling streaming')
|
||||||
|
}
|
||||||
|
|
||||||
const originalFormated = safeStructuredClone(arg.formated).map(m => {
|
const originalFormated = safeStructuredClone(arg.formated).map(m => {
|
||||||
m.content = unescape(m.content)
|
m.content = risuUnescape(m.content)
|
||||||
return m
|
return m
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -337,6 +342,10 @@ export async function requestChatData(arg:requestDataArgument, model:ModelModeEx
|
|||||||
result: 'Aborted'
|
result: 'Aborted'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(da.type === 'success' && arg.escape){
|
||||||
|
da.result = risuEscape(da.result)
|
||||||
|
}
|
||||||
|
|
||||||
if(da.type === 'success' && pluginV2.replacerafterRequest.size > 0){
|
if(da.type === 'success' && pluginV2.replacerafterRequest.size > 0){
|
||||||
for(const replacer of pluginV2.replacerafterRequest){
|
for(const replacer of pluginV2.replacerafterRequest){
|
||||||
|
|||||||
@@ -1210,6 +1210,7 @@ export interface character{
|
|||||||
lastInteraction?:number
|
lastInteraction?:number
|
||||||
translatorNote?:string
|
translatorNote?:string
|
||||||
doNotChangeSeperateModels?:boolean
|
doNotChangeSeperateModels?:boolean
|
||||||
|
escapeOutput?:boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user