[fix] trigger tokens
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
else{
|
||||
const char = $DataBase.characters[selectedChar]
|
||||
if(char.type === 'character'){
|
||||
let triggerResult = runTrigger(char,'input', {chat: char.chats[char.chatPage]})
|
||||
let triggerResult = await runTrigger(char,'input', {chat: char.chats[char.chatPage]})
|
||||
if(triggerResult){
|
||||
cha = triggerResult.chat.message
|
||||
}
|
||||
|
||||
@@ -293,10 +293,11 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
|
||||
let ms = currentChat.message
|
||||
|
||||
const triggerResult = runTrigger(currentChar, 'start', {chat: currentChat})
|
||||
const triggerResult = await runTrigger(currentChar, 'start', {chat: currentChat})
|
||||
if(triggerResult){
|
||||
currentChat = triggerResult.chat
|
||||
ms = currentChat.message
|
||||
currentTokens += triggerResult.tokens
|
||||
}
|
||||
|
||||
for(const msg of ms){
|
||||
@@ -495,7 +496,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
}
|
||||
|
||||
const triggerResult = runTrigger(currentChar, 'output', {chat:currentChat})
|
||||
const triggerResult = await runTrigger(currentChar, 'output', {chat:currentChat})
|
||||
if(triggerResult){
|
||||
db.characters[selectedChar].chats[selectedChat] = triggerResult.chat
|
||||
setDatabase(db)
|
||||
@@ -517,7 +518,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
saying: currentChar.chaId
|
||||
})
|
||||
db.characters[selectedChar].reloadKeys += 1
|
||||
const triggerResult = runTrigger(currentChar, 'output', {chat:currentChat})
|
||||
const triggerResult = await runTrigger(currentChar, 'output', {chat:currentChat})
|
||||
if(triggerResult){
|
||||
db.characters[selectedChar].chats[selectedChat] = triggerResult.chat
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cloneDeep } from "lodash";
|
||||
import { getVarChat, risuChatParser } from "../parser";
|
||||
import type { Chat, character } from "../storage/database";
|
||||
import { tokenize } from "../tokenizer";
|
||||
|
||||
export interface triggerscript{
|
||||
comment: string;
|
||||
@@ -58,7 +59,7 @@ export type additonalSysPrompt = {
|
||||
promptend: string
|
||||
}
|
||||
|
||||
export function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
chat?: Chat
|
||||
} = {}){
|
||||
char = cloneDeep(char)
|
||||
@@ -189,6 +190,17 @@ export function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
if(arg.chat !== undefined && arg.chat !== null){
|
||||
char.chats[char.chatPage] = chat
|
||||
}
|
||||
return {additonalSysPrompt, chat}
|
||||
let caculatedTokens = 0
|
||||
if(additonalSysPrompt.start){
|
||||
caculatedTokens += await tokenize(additonalSysPrompt.start)
|
||||
}
|
||||
if(additonalSysPrompt.historyend){
|
||||
caculatedTokens += await tokenize(additonalSysPrompt.historyend)
|
||||
}
|
||||
if(additonalSysPrompt.promptend){
|
||||
caculatedTokens += await tokenize(additonalSysPrompt.promptend)
|
||||
}
|
||||
|
||||
return {additonalSysPrompt, chat, tokens:caculatedTokens}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user