Add custom chain of thought feature and max thought tag depth setting

This commit is contained in:
kwaroran
2024-01-08 09:03:12 +09:00
parent ecbbc8e85c
commit aaa5843c51
7 changed files with 45 additions and 14 deletions

View File

@@ -3,7 +3,6 @@ import { unzip } from 'fflate';
import { loadAsset, saveAsset } from 'src/ts/storage/globalApi';
import { selectSingleFile } from 'src/ts/util';
import { v4 } from 'uuid';
let tfCache:Cache = null
let tfLoaded = false
let tfMap:{[key:string]:string} = {}

View File

@@ -262,7 +262,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
})
}
if(db.chainOfThought){
if(db.chainOfThought && (!(usingPromptTemplate && db.proomptSettings.customChainOfThought))){
unformated.postEverything.push({
role: 'system',
content: `<instruction> - before respond everything, Think step by step as a ai assistant how would you respond inside <Thoughts> xml tag. this must be less than 5 paragraphs.</instruction>`
@@ -403,10 +403,14 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'plain':
case 'jailbreak':{
case 'jailbreak':
case 'cot':{
if((!db.jailbreakToggle) && (card.type === 'jailbreak')){
continue
}
if((!db.chainOfThought) && (card.type === 'cot')){
continue
}
const convertRole = {
"system": "system",
@@ -521,8 +525,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
currentTokens += triggerResult.tokens
}
let index = 0
for(const msg of ms){
let formedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, rmVar: true}), 'editprocess')
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, rmVar: true}), 'editprocess')
let name = ''
if(msg.role === 'char'){
if(msg.saying){
@@ -541,10 +546,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
let inlays:string[] = []
if(db.inlayImage){
if(msg.role === 'char'){
formedChat = formedChat.replace(/{{inlay::(.+?)}}/g, '')
formatedChat = formatedChat.replace(/{{inlay::(.+?)}}/g, '')
}
else{
const inlayMatch = formedChat.match(/{{inlay::(.+?)}}/g)
const inlayMatch = formatedChat.match(/{{inlay::(.+?)}}/g)
if(inlayMatch){
for(const inlay of inlayMatch){
inlays.push(inlay)
@@ -568,25 +573,32 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
currentTokens += await tokenizer.tokenizeChat(imgchat)
}
}
formedChat = formedChat.replace(inlay, '')
formatedChat = formatedChat.replace(inlay, '')
}
}
let attr:string[] = []
if(nowChatroom.type === 'group' || (usingPromptTemplate && db.proomptSettings.sendName)){
formedChat = name + ': ' + formedChat
formatedChat = name + ': ' + formatedChat
attr.push('nameAdded')
}
if(usingPromptTemplate && db.proomptSettings.customChainOfThought && db.proomptSettings.maxThoughtTagDepth !== -1){
const depth = ms.length - index
if(depth >= db.proomptSettings.maxThoughtTagDepth){
formatedChat = formatedChat.replace(/<Thoughts>(.+?)<\/Thoughts>/gm, '')
}
}
const chat:OpenAIChat = {
role: msg.role === 'user' ? 'user' : 'assistant',
content: formedChat,
content: formatedChat,
memo: msg.chatId,
attr: attr
}
chats.push(chat)
currentTokens += await tokenizer.tokenizeChat(chat)
index++
}
if(nowChatroom.supaMemory && db.supaMemoryType !== 'none'){
@@ -762,10 +774,14 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'plain':
case 'jailbreak':{
case 'jailbreak':
case 'cot':{
if((!db.jailbreakToggle) && (card.type === 'jailbreak')){
continue
}
if((!db.chainOfThought) && (card.type === 'cot')){
continue
}
const convertRole = {
"system": "system",

View File

@@ -8,10 +8,12 @@ export type ProomptSettings = {
sendChatAsSystem: boolean
sendName: boolean
utilOverride: boolean
customChainOfThought?: boolean
maxThoughtTagDepth?: number
}
export interface ProomptPlain {
type: 'plain'|'jailbreak';
type: 'plain'|'jailbreak'|'cot';
type2: 'normal'|'globalNote'|'main'
text: string;
role: 'user'|'bot'|'system';

View File

@@ -367,10 +367,13 @@ export function setDatabase(data:Database){
postEndInnerFormat: '',
sendChatAsSystem: false,
sendName: false,
utilOverride: false
utilOverride: false,
customChainOfThought: false,
maxThoughtTagDepth: -1
}
data.keiServerURL ??= ''
data.top_k ??= 0
data.proomptSettings.maxThoughtTagDepth ??= -1
changeLanguage(data.language)
DataBase.set(data)