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