Add removeIncompleteResponse
This commit is contained in:
@@ -575,4 +575,5 @@ export const languageEnglish = {
|
|||||||
metaData: "Meta Data",
|
metaData: "Meta Data",
|
||||||
autoContinueMinTokens: "Target Tokens (Auto Continue)",
|
autoContinueMinTokens: "Target Tokens (Auto Continue)",
|
||||||
autoContinueChat: "Anti-Incomplete Response (Auto Continue)",
|
autoContinueChat: "Anti-Incomplete Response (Auto Continue)",
|
||||||
|
removeIncompleteResponse: "Remove Incomplete Sentences",
|
||||||
}
|
}
|
||||||
@@ -76,6 +76,9 @@
|
|||||||
<div class="flex items-center mt-4">
|
<div class="flex items-center mt-4">
|
||||||
<Check bind:check={$DataBase.autoContinueChat} name={language.autoContinueChat}> <Help key="autoContinueChat"/></Check>
|
<Check bind:check={$DataBase.autoContinueChat} name={language.autoContinueChat}> <Help key="autoContinueChat"/></Check>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center mt-4">
|
||||||
|
<Check bind:check={$DataBase.removeIncompleteResponse} name={language.removeIncompleteResponse}></Check>
|
||||||
|
</div>
|
||||||
<div class="flex items-center mt-4">
|
<div class="flex items-center mt-4">
|
||||||
<Check bind:check={$DataBase.newOAIHandle} name={language.newOAIHandle}/>
|
<Check bind:check={$DataBase.newOAIHandle} name={language.newOAIHandle}/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
|||||||
import { language } from "../../lang";
|
import { language } from "../../lang";
|
||||||
import { alertError } from "../alert";
|
import { alertError } from "../alert";
|
||||||
import { loadLoreBookPrompt } from "./lorebook";
|
import { loadLoreBookPrompt } from "./lorebook";
|
||||||
import { findCharacterbyId, getAuthorNoteDefaultText } from "../util";
|
import { findCharacterbyId, getAuthorNoteDefaultText, isLastCharPunctuation, trimUntilPunctuation } from "../util";
|
||||||
import { requestChatData } from "./request";
|
import { requestChatData } from "./request";
|
||||||
import { stableDiff } from "./stableDiff";
|
import { stableDiff } from "./stableDiff";
|
||||||
import { processScript, processScriptFull, risuChatParser } from "./scripts";
|
import { processScript, processScriptFull, risuChatParser } from "./scripts";
|
||||||
@@ -1026,7 +1026,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
if(db.cipherChat){
|
if(db.cipherChat){
|
||||||
result = decipherChat(result)
|
result = decipherChat(result)
|
||||||
}
|
}
|
||||||
const result2 = await processScriptFull(nowChatroom, reformatContent(prefix + result), 'editoutput', msgIndex)
|
if(db.removeIncompleteResponse){
|
||||||
|
result = trimUntilPunctuation(result)
|
||||||
|
}
|
||||||
|
let result2 = await processScriptFull(nowChatroom, reformatContent(prefix + result), 'editoutput', msgIndex)
|
||||||
db.characters[selectedChar].chats[selectedChat].message[msgIndex].data = result2.data
|
db.characters[selectedChar].chats[selectedChat].message[msgIndex].data = result2.data
|
||||||
emoChanged = result2.emoChanged
|
emoChanged = result2.emoChanged
|
||||||
db.characters[selectedChar].reloadKeys += 1
|
db.characters[selectedChar].reloadKeys += 1
|
||||||
@@ -1078,6 +1081,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
let beforeChat = db.characters[selectedChar].chats[selectedChat].message[msgIndex]
|
let beforeChat = db.characters[selectedChar].chats[selectedChat].message[msgIndex]
|
||||||
result2 = await processScriptFull(nowChatroom, reformatContent(beforeChat.data + mess), 'editoutput', msgIndex)
|
result2 = await processScriptFull(nowChatroom, reformatContent(beforeChat.data + mess), 'editoutput', msgIndex)
|
||||||
}
|
}
|
||||||
|
if(db.removeIncompleteResponse){
|
||||||
|
result2.data = trimUntilPunctuation(result2.data)
|
||||||
|
}
|
||||||
result = result2.data
|
result = result2.data
|
||||||
const inlayResult = runInlayScreen(currentChar, result)
|
const inlayResult = runInlayScreen(currentChar, result)
|
||||||
result = inlayResult.text
|
result = inlayResult.text
|
||||||
@@ -1138,25 +1144,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
needsAutoContinue = true
|
needsAutoContinue = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if(db.autoContinueChat){
|
if(db.autoContinueChat && (!isLastCharPunctuation(result))){
|
||||||
//if result doesn't end with punctuation or special characters, auto continue
|
//if result doesn't end with punctuation or special characters, auto continue
|
||||||
const lastChar = result.trim().at(-1)
|
needsAutoContinue = true
|
||||||
const punctuation = [
|
|
||||||
'.', '!', '?', '。', '!', '?', '…', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '|', '\\', ':', ';', '"', "'", '<', '>', ',', '.', '/', '~', '`', ' ',
|
|
||||||
'¡', '¿', '‽', '⁉'
|
|
||||||
]
|
|
||||||
if(lastChar && !(punctuation.indexOf(lastChar) !== -1
|
|
||||||
//spacing modifier letters
|
|
||||||
|| (lastChar.charCodeAt(0) >= 0x02B0 && lastChar.charCodeAt(0) <= 0x02FF)
|
|
||||||
//combining diacritical marks
|
|
||||||
|| (lastChar.charCodeAt(0) >= 0x0300 && lastChar.charCodeAt(0) <= 0x036F)
|
|
||||||
//hebrew punctuation
|
|
||||||
|| (lastChar.charCodeAt(0) >= 0x0590 && lastChar.charCodeAt(0) <= 0x05CF)
|
|
||||||
//CJK symbols and punctuation
|
|
||||||
|| (lastChar.charCodeAt(0) >= 0x3000 && lastChar.charCodeAt(0) <= 0x303F)
|
|
||||||
)){
|
|
||||||
needsAutoContinue = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(needsAutoContinue){
|
if(needsAutoContinue){
|
||||||
|
|||||||
@@ -626,6 +626,7 @@ export interface Database{
|
|||||||
ollamaModel:string
|
ollamaModel:string
|
||||||
autoContinueChat:boolean
|
autoContinueChat:boolean
|
||||||
autoContinueMinTokens:number
|
autoContinueMinTokens:number
|
||||||
|
removeIncompleteResponse:boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface customscript{
|
export interface customscript{
|
||||||
|
|||||||
@@ -463,4 +463,33 @@ export function uuidtoNumber(uuid:string){
|
|||||||
result += uuid.charCodeAt(i)
|
result += uuid.charCodeAt(i)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isLastCharPunctuation(s:string){
|
||||||
|
const lastChar = s.trim().at(-1)
|
||||||
|
const punctuation = [
|
||||||
|
'.', '!', '?', '。', '!', '?', '…', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '|', '\\', ':', ';', '<', '>', ',', '.', '/', '~', '`', ' ',
|
||||||
|
'¡', '¿', '‽', '⁉'
|
||||||
|
]
|
||||||
|
if(lastChar && !(punctuation.indexOf(lastChar) !== -1
|
||||||
|
//spacing modifier letters
|
||||||
|
|| (lastChar.charCodeAt(0) >= 0x02B0 && lastChar.charCodeAt(0) <= 0x02FF)
|
||||||
|
//combining diacritical marks
|
||||||
|
|| (lastChar.charCodeAt(0) >= 0x0300 && lastChar.charCodeAt(0) <= 0x036F)
|
||||||
|
//hebrew punctuation
|
||||||
|
|| (lastChar.charCodeAt(0) >= 0x0590 && lastChar.charCodeAt(0) <= 0x05CF)
|
||||||
|
//CJK symbols and punctuation
|
||||||
|
|| (lastChar.charCodeAt(0) >= 0x3000 && lastChar.charCodeAt(0) <= 0x303F)
|
||||||
|
)){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trimUntilPunctuation(s:string){
|
||||||
|
let result = s
|
||||||
|
while(result.length > 0 && !isLastCharPunctuation(result)){
|
||||||
|
result = result.slice(0, -1)
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user