Rework variable assignment and processing
This commit is contained in:
@@ -2,7 +2,7 @@ import DOMPurify from 'isomorphic-dompurify';
|
||||
import showdown from 'showdown';
|
||||
import { Marked } from 'marked';
|
||||
|
||||
import { DataBase, type Database, type Message, type character, type customscript, type groupChat } from './storage/database';
|
||||
import { DataBase, setDatabase, type Database, type Message, type character, type customscript, type groupChat } from './storage/database';
|
||||
import { getFileSrc } from './storage/globalApi';
|
||||
import { processScriptFull } from './process/scripts';
|
||||
import { get } from 'svelte/store';
|
||||
@@ -393,6 +393,7 @@ type matcherArg = {
|
||||
consistantChar?:boolean
|
||||
displaying?:boolean
|
||||
role?:string
|
||||
runVar?:boolean
|
||||
}
|
||||
const matcher = (p1:string,matcherArg:matcherArg) => {
|
||||
if(p1.length > 100000){
|
||||
@@ -647,8 +648,11 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
||||
const v = arra[1]
|
||||
switch(arra[0]){
|
||||
case 'getvar':{
|
||||
const d = matcherArg.var ?? getVarChat(chatID)
|
||||
return d[v] ?? "[Null]"
|
||||
const db = get(DataBase)
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
return (chat.scriptstate ?? {})[v] ?? 'null'
|
||||
}
|
||||
case 'calc':{
|
||||
return calcString(v).toString()
|
||||
@@ -658,7 +662,25 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
||||
if(matcherArg.rmVar){
|
||||
return ''
|
||||
}
|
||||
break
|
||||
if(matcherArg.runVar){
|
||||
const db = get(DataBase)
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
chat.scriptstate = chat.scriptstate ?? {}
|
||||
if(arra[0] === 'addvar'){
|
||||
chat.scriptstate[v] = Number(chat.scriptstate[v]) + Number(arra[2])
|
||||
}
|
||||
else{
|
||||
chat.scriptstate[v] = arra[2]
|
||||
}
|
||||
|
||||
char.chats[char.chatPage] = chat
|
||||
db.characters[selectedChar] = char
|
||||
setDatabase(db)
|
||||
return ''
|
||||
}
|
||||
return null
|
||||
}
|
||||
case 'button':{
|
||||
return `<button style="padding" x-risu-prompt="${arra[2]}">${arra[1]}</button>`
|
||||
@@ -892,6 +914,7 @@ export function risuChatParser(da:string, arg:{
|
||||
consistantChar?:boolean
|
||||
visualize?:boolean,
|
||||
role?:string
|
||||
runVar?:boolean
|
||||
} = {}):string{
|
||||
const chatID = arg.chatID ?? -1
|
||||
const db = arg.db ?? get(DataBase)
|
||||
@@ -937,7 +960,8 @@ export function risuChatParser(da:string, arg:{
|
||||
var: arg.var ?? null,
|
||||
tokenizeAccurate: arg.tokenizeAccurate ?? false,
|
||||
displaying: arg.visualize ?? false,
|
||||
role: arg.role
|
||||
role: arg.role,
|
||||
runVar: arg.runVar ?? false,
|
||||
}
|
||||
let pef = performance.now()
|
||||
while(pointer < da.length){
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, setDatabase, type character, type MessageGenerationInfo } from "../storage/database";
|
||||
import { DataBase, setDatabase, type character, type MessageGenerationInfo, type Chat } from "../storage/database";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
||||
import { language } from "../../lang";
|
||||
@@ -73,6 +73,15 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function runCurrentChatFunction(chat:Chat){
|
||||
chat.message = chat.message.map((v) => {
|
||||
v.data = risuChatParser(v.data, {chara: currentChar, runVar: true})
|
||||
return v
|
||||
})
|
||||
return chat
|
||||
}
|
||||
|
||||
function reformatContent(data:string){
|
||||
if(chatProcessIndex === -1){
|
||||
return data.trim()
|
||||
@@ -150,7 +159,8 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
let chatAdditonalTokens = arg.chatAdditonalTokens ?? caculatedChatTokens
|
||||
const tokenizer = new ChatTokenizer(chatAdditonalTokens, db.aiModel.startsWith('gpt') ? 'noName' : 'name')
|
||||
let selectedChat = nowChatroom.chatPage
|
||||
let currentChat = nowChatroom.chats[selectedChat]
|
||||
let currentChat = runCurrentChatFunction(nowChatroom.chats[selectedChat])
|
||||
nowChatroom.chats[selectedChat] = currentChat
|
||||
let maxContextTokens = db.maxContext
|
||||
|
||||
if(db.aiModel === 'gpt35'){
|
||||
@@ -523,7 +533,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
const chat:OpenAIChat = {
|
||||
role: 'assistant',
|
||||
content: await (processScript(nowChatroom,
|
||||
risuChatParser(firstMsg, {chara: currentChar, rmVar: true}),
|
||||
risuChatParser(firstMsg, {chara: currentChar}),
|
||||
'editprocess'))
|
||||
}
|
||||
|
||||
@@ -546,7 +556,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
|
||||
let index = 0
|
||||
for(const msg of ms){
|
||||
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, rmVar: true, role: msg.role}), 'editprocess')
|
||||
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, role: msg.role}), 'editprocess')
|
||||
let name = ''
|
||||
if(msg.role === 'char'){
|
||||
if(msg.saying){
|
||||
@@ -1104,6 +1114,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
}
|
||||
|
||||
db.characters[selectedChar].chats[selectedChat] = runCurrentChatFunction(db.characters[selectedChar].chats[selectedChat])
|
||||
sendPeerChar()
|
||||
|
||||
if(req.special){
|
||||
|
||||
Reference in New Issue
Block a user