Replace cloneDeep to native structuredclone and remove unused import

This commit is contained in:
kwaroran
2024-04-25 01:17:14 +09:00
parent cc744853d2
commit 11b1d4d4f3
22 changed files with 85 additions and 115 deletions

View File

@@ -13,7 +13,6 @@ import { exampleMessage } from "./exampleMessages";
import { sayTTS } from "./tts";
import { supaMemory } from "./memory/supaMemory";
import { v4 } from "uuid";
import { cloneDeep } from "lodash";
import { groupOrder } from "./group";
import { runTrigger } from "./triggers";
import { HypaProcesser } from "./memory/hypamemory";
@@ -207,7 +206,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
'personaPrompt':([] as OpenAIChat[])
}
let promptTemplate = cloneDeep(db.promptTemplate)
let promptTemplate = structuredClone(db.promptTemplate)
const usingPromptTemplate = !!promptTemplate
if(promptTemplate){
let hasPostEverything = false
@@ -394,7 +393,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
for(const card of template){
switch(card.type){
case 'persona':{
let pmt = cloneDeep(unformated.personaPrompt)
let pmt = structuredClone(unformated.personaPrompt)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -405,7 +404,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'description':{
let pmt = cloneDeep(unformated.description)
let pmt = structuredClone(unformated.description)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -416,7 +415,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'authornote':{
let pmt = cloneDeep(unformated.authorNote)
let pmt = structuredClone(unformated.authorNote)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '')
@@ -759,7 +758,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
//make into one
let formated:OpenAIChat[] = []
const formatOrder = cloneDeep(db.formatingOrder)
const formatOrder = structuredClone(db.formatingOrder)
if(formatOrder){
formatOrder.push('postEverything')
}
@@ -803,7 +802,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
for(const card of template){
switch(card.type){
case 'persona':{
let pmt = cloneDeep(unformated.personaPrompt)
let pmt = structuredClone(unformated.personaPrompt)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -814,7 +813,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'description':{
let pmt = cloneDeep(unformated.description)
let pmt = structuredClone(unformated.description)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -825,7 +824,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'authornote':{
let pmt = cloneDeep(unformated.authorNote)
let pmt = structuredClone(unformated.authorNote)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '')
@@ -917,7 +916,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
break
}
case 'memory':{
let pmt = cloneDeep(memories)
let pmt = structuredClone(memories)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)

View File

@@ -3,7 +3,6 @@ import type { OpenAIChat } from "..";
import { DataBase, type Chat, type character, type groupChat } from "../../storage/database";
import { tokenize, type ChatTokenizer } from "../../tokenizer";
import { requestChatData } from "../request";
import { cloneDeep } from "lodash";
import { HypaProcesser } from "./hypamemory";
import { stringlizeChat } from "../stringlize";
import { globalFetch } from "src/ts/storage/globalApi";
@@ -74,7 +73,7 @@ export async function supaMemory(
for(let j=0;j<HypaData.length;j++){
let i =0;
let countTokens = currentTokens
let countChats = cloneDeep(chats)
let countChats = structuredClone(chats)
while(true){
if(countChats.length === 0){
break

View File

@@ -14,7 +14,6 @@ import { SignatureV4 } from "@smithy/signature-v4";
import { HttpRequest } from "@smithy/protocol-http";
import { Sha256 } from "@aws-crypto/sha256-js";
import { v4 } from "uuid";
import { cloneDeep } from "lodash";
import { supportsInlayImage } from "./files/image";
import { OaifixBias } from "../plugins/fixer";
import { Capacitor } from "@capacitor/core";
@@ -124,7 +123,7 @@ export interface OpenAIChatExtra {
export async function requestChatDataMain(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
const db = get(DataBase)
let formated = cloneDeep(arg.formated)
let formated = structuredClone(arg.formated)
let maxTokens = arg.maxTokens ??db.maxResponse
let temperature = arg.temperature ?? (db.temperature / 100)
let bias = arg.bias
@@ -178,7 +177,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
for(let i=0;i<formated.length;i++){
const m = formated[i]
if(m.multimodals && m.multimodals.length > 0 && m.role === 'user'){
let v:OpenAIChatExtra = cloneDeep(m)
let v:OpenAIChatExtra = structuredClone(m)
let contents:OpenAIContents[] = []
for(let j=0;j<m.multimodals.length;j++){
contents.push({

View File

@@ -1,4 +1,3 @@
import { cloneDeep } from 'lodash'
import type { Database } from 'src/ts/storage/database'
export function templateCheck(db:Database){

View File

@@ -1,4 +1,3 @@
import { cloneDeep } from "lodash";
import { risuChatParser } from "../parser";
import { DataBase, type Chat, type character } from "../storage/database";
import { tokenize } from "../tokenizer";
@@ -85,7 +84,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
manualName?: string
}){
arg.recursiveCount ??= 0
char = cloneDeep(char)
char = structuredClone(char)
let varChanged = false
let stopSending = arg.stopSending ?? false
const currentChat = get(CurrentChat)
@@ -95,7 +94,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
promptend: ''
}
const triggers = char.triggerscript.concat(getModuleTriggers())
let chat = cloneDeep(arg.chat ?? char.chats[char.chatPage])
let chat = structuredClone(arg.chat ?? char.chats[char.chatPage])
if((!triggers) || (triggers.length === 0)){
return null
}