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