Merge branch 'main' into main
This commit is contained in:
@@ -7,6 +7,7 @@ import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "../../lang";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
import { getModuleLorebooks } from "./modules";
|
||||
|
||||
export function addLorebook(type:number) {
|
||||
let selectedID = get(selectedCharID)
|
||||
@@ -71,12 +72,12 @@ export async function loadLoreBookPrompt(){
|
||||
const characterLore = char.globalLore ?? []
|
||||
const chatLore = char.chats[page].localLore ?? []
|
||||
const globalLore = db.loreBook[db.loreBookPage]?.data ?? []
|
||||
const fullLore = characterLore.concat(chatLore.concat(globalLore))
|
||||
const moduleLorebook = getModuleLorebooks()
|
||||
const fullLore = characterLore.concat(chatLore).concat(moduleLorebook).concat(globalLore)
|
||||
const currentChat = char.chats[page].message
|
||||
const loreDepth = char.loreSettings?.scanDepth ?? db.loreBookDepth
|
||||
const loreToken = char.loreSettings?.tokenBudget ?? db.loreBookToken
|
||||
const fullWordMatching = char.loreSettings?.fullWordMatching ?? false
|
||||
|
||||
if(char.lorePlus){
|
||||
return await loadLoreBookPlusPrompt()
|
||||
}
|
||||
|
||||
120
src/ts/process/modules.ts
Normal file
120
src/ts/process/modules.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
import { language } from "src/lang"
|
||||
import { alertError, alertNormal } from "../alert"
|
||||
import { DataBase, type customscript, type loreBook, type triggerscript } from "../storage/database"
|
||||
import { downloadFile } from "../storage/globalApi"
|
||||
import { get } from "svelte/store"
|
||||
import { CurrentChat } from "../stores"
|
||||
import { selectSingleFile } from "../util"
|
||||
import { v4 } from "uuid"
|
||||
|
||||
export interface RisuModule{
|
||||
name: string
|
||||
description: string
|
||||
lorebook?: loreBook[]
|
||||
regex?: customscript[]
|
||||
cjs?: string
|
||||
trigger?: triggerscript[]
|
||||
id: string
|
||||
}
|
||||
|
||||
export async function exportModule(module:RisuModule){
|
||||
await downloadFile(module.name + '.json', JSON.stringify({
|
||||
...module,
|
||||
type: 'risuModule'
|
||||
}, null, 2))
|
||||
alertNormal(language.successExport)
|
||||
}
|
||||
|
||||
export async function importModule(){
|
||||
const f = await selectSingleFile(['json'])
|
||||
if(!f){
|
||||
return
|
||||
}
|
||||
const file = f.data
|
||||
try {
|
||||
const importedModule = JSON.parse(Buffer.from(file).toString())
|
||||
if(importedModule.type === 'risuModule'){
|
||||
const db = get(DataBase)
|
||||
if(
|
||||
(!importedModule.name)
|
||||
|| (!importedModule.description)
|
||||
|| (!importedModule.id)
|
||||
){
|
||||
alertError(language.errors.noData)
|
||||
}
|
||||
importedModule.id = v4()
|
||||
db.modules.push(importedModule)
|
||||
}
|
||||
} catch (error) {
|
||||
alertNormal(language.errors.noData)
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleById(id:string){
|
||||
const db = get(DataBase)
|
||||
for(let i=0;i<db.modules.length;i++){
|
||||
if(db.modules[i].id === id){
|
||||
return db.modules[i]
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
export function getModuleLorebooks() {
|
||||
const currentChat = get(CurrentChat)
|
||||
const db = get(DataBase)
|
||||
if (!currentChat) return []
|
||||
const moduleIds = currentChat.modules ?? []
|
||||
moduleIds.concat(db.enabledModules)
|
||||
let lorebooks: loreBook[] = []
|
||||
for (const moduleId of moduleIds) {
|
||||
const module = getModuleById(moduleId)
|
||||
if(!module){
|
||||
continue
|
||||
}
|
||||
if (module.lorebook) {
|
||||
lorebooks = lorebooks.concat(module.lorebook)
|
||||
}
|
||||
}
|
||||
return lorebooks
|
||||
}
|
||||
|
||||
|
||||
export function getModuleTriggers() {
|
||||
const currentChat = get(CurrentChat)
|
||||
const db = get(DataBase)
|
||||
if (!currentChat) return []
|
||||
const moduleIds = currentChat.modules ?? []
|
||||
moduleIds.concat(db.enabledModules)
|
||||
let triggers: triggerscript[] = []
|
||||
for (const moduleId of moduleIds) {
|
||||
const module = getModuleById(moduleId)
|
||||
if(!module){
|
||||
continue
|
||||
}
|
||||
if (module.trigger) {
|
||||
triggers = triggers.concat(module.trigger)
|
||||
}
|
||||
}
|
||||
return triggers
|
||||
}
|
||||
|
||||
export function getModuleRegexScripts() {
|
||||
const currentChat = get(CurrentChat)
|
||||
const db = get(DataBase)
|
||||
if (!currentChat) return []
|
||||
const moduleIds = currentChat.modules ?? []
|
||||
moduleIds.concat(db.enabledModules)
|
||||
let customscripts: customscript[] = []
|
||||
for (const moduleId of moduleIds) {
|
||||
const module = getModuleById(moduleId)
|
||||
if(!module){
|
||||
continue
|
||||
}
|
||||
if (module.regex) {
|
||||
customscripts = customscripts.concat(module.regex)
|
||||
}
|
||||
}
|
||||
return customscripts
|
||||
}
|
||||
@@ -152,9 +152,10 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
case 'gpt4_32k_0613':
|
||||
case 'gpt4_1106':
|
||||
case 'gpt4_0125':
|
||||
case 'gpt35_0125':
|
||||
case 'gpt35_1106':
|
||||
case 'gpt35_0301':
|
||||
case 'gpt4_0301':
|
||||
case 'gpt4_0314':
|
||||
case 'gptvi4_1106':
|
||||
case 'openrouter':
|
||||
case 'mistral-tiny':
|
||||
@@ -405,9 +406,10 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
: requestModel === "gpt4_1106" ? 'gpt-4-1106-preview'
|
||||
: requestModel === 'gpt4_0125' ? 'gpt-4-0125-preview'
|
||||
: requestModel === "gptvi4_1106" ? 'gpt-4-vision-preview'
|
||||
: requestModel === "gpt35_0125" ? 'gpt-3.5-turbo-0125'
|
||||
: requestModel === "gpt35_1106" ? 'gpt-3.5-turbo-1106'
|
||||
: requestModel === 'gpt35_0301' ? 'gpt-3.5-turbo-0301'
|
||||
: requestModel === 'gpt4_0301' ? 'gpt-4-0301'
|
||||
: requestModel === 'gpt4_0314' ? 'gpt-4-0314'
|
||||
: (!requestModel) ? 'gpt-3.5-turbo'
|
||||
: requestModel,
|
||||
messages: formatedChat,
|
||||
@@ -1423,7 +1425,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
}
|
||||
|
||||
|
||||
|
||||
let latestRole = 'user'
|
||||
let requestPrompt = formated.map((v, i) => {
|
||||
let prefix = ''
|
||||
switch (v.role){
|
||||
@@ -1437,13 +1439,18 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
prefix = "\n\nSystem: "
|
||||
break
|
||||
}
|
||||
latestRole = v.role
|
||||
if(raiModel.startsWith('claude-2') && (!raiModel.startsWith('claude-2.0'))){
|
||||
if(v.role === 'system' && i === 0){
|
||||
prefix = ''
|
||||
}
|
||||
}
|
||||
return prefix + v.content
|
||||
}).join('') + '\n\nAssistant: '
|
||||
}).join('')
|
||||
|
||||
if(latestRole !== 'assistant'){
|
||||
requestPrompt += '\n\nAssistant: '
|
||||
}
|
||||
|
||||
|
||||
const bedrock = db.claudeAws
|
||||
|
||||
@@ -10,6 +10,7 @@ import { autoMarkPlugin } from "../plugins/automark";
|
||||
import { runCharacterJS } from "../plugins/embedscript";
|
||||
import { metricaPlugin } from "../plugins/metrica";
|
||||
import { OaiFixKorean } from "../plugins/fixer";
|
||||
import { getModuleRegexScripts } from "./modules";
|
||||
|
||||
const dreg = /{{data}}/g
|
||||
const randomness = /\|\|\|/g
|
||||
@@ -60,7 +61,7 @@ export async function importRegex(){
|
||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1){
|
||||
let db = get(DataBase)
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript)
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
||||
if(db.officialplugins.automark && mode === 'editdisplay'){
|
||||
data = autoMarkPlugin(data)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { cloneDeep } from "lodash";
|
||||
import { getVarChat, risuChatParser } from "../parser";
|
||||
import type { Chat, character } from "../storage/database";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { getModuleTriggers } from "./modules";
|
||||
|
||||
export interface triggerscript{
|
||||
comment: string;
|
||||
@@ -68,7 +69,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
historyend: '',
|
||||
promptend: ''
|
||||
}
|
||||
const triggers = char.triggerscript
|
||||
const triggers = char.triggerscript.concat(getModuleTriggers())
|
||||
const chat = cloneDeep(arg.chat ?? char.chats[char.chatPage])
|
||||
if((!triggers) || (triggers.length === 0)){
|
||||
return null
|
||||
|
||||
@@ -366,6 +366,8 @@ export function setDatabase(data:Database){
|
||||
data.openrouterMiddleOut ??= false
|
||||
data.removePunctuationHypa ??= true
|
||||
data.memoryLimitThickness ??= 1
|
||||
data.modules ??= []
|
||||
data.enabledModules ??= []
|
||||
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
@@ -586,6 +588,8 @@ export interface Database{
|
||||
lastPatchNoteCheckVersion?:string,
|
||||
removePunctuationHypa?:boolean
|
||||
memoryLimitThickness?:number
|
||||
modules: RisuModule[]
|
||||
enabledModules: string[]
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
@@ -838,6 +842,7 @@ export interface Chat{
|
||||
suggestMessages?:string[]
|
||||
isStreaming?:boolean
|
||||
scriptstate?:{[key:string]:string|number|boolean}
|
||||
modules?:string[]
|
||||
}
|
||||
|
||||
export interface Message{
|
||||
@@ -1119,6 +1124,7 @@ export function setPreset(db:Database, newPres: botPreset){
|
||||
import { encode as encodeMsgpack, decode as decodeMsgpack } from "msgpackr";
|
||||
import * as fflate from "fflate";
|
||||
import type { OnnxModelFiles } from '../process/embedding/transformers';
|
||||
import type { RisuModule } from '../process/modules';
|
||||
|
||||
export async function downloadPreset(id:number){
|
||||
saveCurrentPreset()
|
||||
|
||||
@@ -44,7 +44,11 @@ interface fetchLog{
|
||||
|
||||
let fetchLog:fetchLog[] = []
|
||||
|
||||
export async function downloadFile(name:string, data:Uint8Array|ArrayBuffer) {
|
||||
export async function downloadFile(name:string, dat:Uint8Array|ArrayBuffer|string) {
|
||||
if(typeof(dat) === 'string'){
|
||||
dat = Buffer.from(dat, 'utf-8')
|
||||
}
|
||||
const data = new Uint8Array(dat)
|
||||
const downloadURL = (data:string, fileName:string) => {
|
||||
const a = document.createElement('a')
|
||||
a.href = data
|
||||
|
||||
@@ -37,6 +37,7 @@ export const CurrentUsername = writable(db.username)
|
||||
export const CurrentUserIcon = writable(db.userIcon)
|
||||
export const CurrentShowMemoryLimit = writable(db.showMemoryLimit)
|
||||
export const ShowVN = writable(false)
|
||||
export const SettingsMenuIndex = writable(0)
|
||||
|
||||
function createSimpleCharacter(char:character|groupChat){
|
||||
if((!char) || char.type === 'group'){
|
||||
|
||||
Reference in New Issue
Block a user