Add low level access

This commit is contained in:
kwaroran
2024-05-28 20:39:35 +09:00
parent 48afa966b6
commit 2401b25bee
8 changed files with 267 additions and 6 deletions

View File

@@ -479,6 +479,12 @@ async function importCharacterCardSpec(card:CharacterCardV2Risu|CharacterCardV3,
sdData = risuext.sdData ?? sdData
}
if(risuext.lowLevelAccess){
const conf = alertConfirm(language.lowLevelAccessConfirm)
if(!conf){
return false
}
}
const charbook = data.character_book
let lorebook:loreBook[] = []
let loresettings:undefined|loreSettings = undefined
@@ -586,6 +592,7 @@ async function importCharacterCardSpec(card:CharacterCardV2Risu|CharacterCardV3,
imported: true,
source: card?.data?.extensions?.risuai?.source ?? [],
ccAssets: ccAssets,
lowLevelAccess: risuext.lowLevelAccess ?? false
}
if(card.spec === 'chara_card_v3'){
@@ -939,7 +946,8 @@ export function createBaseV3(char:character){
lorePlus: char.lorePlus,
inlayViewScreen: char.inlayViewScreen,
newGenData: char.newGenData,
vits: {}
vits: {},
lowLevelAccess: char.lowLevelAccess ?? false
},
depth_prompt: char.depth_prompt
},

View File

@@ -13,6 +13,7 @@ import { findCharacterbyId, parseKeyValue, sfc32, uuidtoNumber } from './util';
import { getInlayImage } from './process/files/image';
import { autoMarkNew } from './plugins/automark';
import { getModuleLorebooks } from './process/modules';
import { HypaProcesser } from './process/memory/hypamemory';
const mconverted = new Marked({
gfm: true,

View File

@@ -1087,6 +1087,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
let result = ''
let emoChanged = false
let resendChat = false
if(abortSignal.aborted === true){
return false
@@ -1151,6 +1152,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
if(triggerResult && triggerResult.chat){
currentChat = triggerResult.chat
}
if(triggerResult && triggerResult.sendAIprompt){
resendChat = true
}
const inlayr = runInlayScreen(currentChar, currentChat.message[msgIndex].data)
currentChat.message[msgIndex].data = inlayr.text
db.characters[selectedChar].chats[selectedChat] = currentChat
@@ -1236,6 +1240,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
db.characters[selectedChar].chats[selectedChat] = triggerResult.chat
setDatabase(db)
}
if(triggerResult && triggerResult.sendAIprompt){
resendChat = true
}
}
let needsAutoContinue = false
@@ -1259,6 +1266,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
})
}
if(resendChat){
doingChat.set(false)
return await sendChat(chatProcessIndex, {
signal: abortSignal
})
}
chatProcessStage.set(4)
sendPeerChar()

View File

@@ -6,6 +6,10 @@ import { get } from "svelte/store";
import { CurrentCharacter, CurrentChat, selectedCharID } from "../stores";
import { processMultiCommand } from "./command";
import { parseKeyValue } from "../util";
import { alertError, alertInput, alertNormal, alertSelect } from "../alert";
import type { OpenAIChat } from ".";
import { HypaProcesser } from "./memory/hypamemory";
import { requestChatData } from "./request";
export interface triggerscript{
comment: string;
@@ -16,7 +20,7 @@ export interface triggerscript{
export type triggerCondition = triggerConditionsVar|triggerConditionsExists|triggerConditionsChatIndex
export type triggerEffect = triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger
export type triggerEffect = triggerEffectRunLLM|triggerEffectCheckSimilarity|triggerEffectSendAIprompt|triggerEffectShowAlert|triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger
export type triggerConditionsVar = {
type:'var'|'value'
@@ -62,6 +66,13 @@ export interface triggerEffectCommand{
value: string
}
export interface triggerEffectShowAlert{
type: 'showAlert',
alertType: string
value: string
inputVar: string
}
export interface triggerEffectRunTrigger{
type: 'runtrigger',
value: string
@@ -71,6 +82,23 @@ export interface triggerEffectStop{
type: 'stop'
}
export interface triggerEffectSendAIprompt{
type: 'sendAIprompt'
}
export interface triggerEffectCheckSimilarity{
type: 'checkSimilarity',
source: string,
value: string,
inputVar: string
}
export interface triggerEffectRunLLM{
type: 'runLLM',
value: string,
inputVar: string
}
export type additonalSysPrompt = {
start:string,
historyend: string,
@@ -88,6 +116,8 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
char = structuredClone(char)
let varChanged = false
let stopSending = arg.stopSending ?? false
let lowLevelAccess = char.lowLevelAccess ?? false
let sendAIprompt = false
const currentChat = get(CurrentChat)
let additonalSysPrompt:additonalSysPrompt = arg.additonalSysPrompt ?? {
start:'',
@@ -269,7 +299,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
break
}
case 'runtrigger':{
if(arg.recursiveCount < 10){
if(arg.recursiveCount < 10 || lowLevelAccess){
arg.recursiveCount++
const r = await runTrigger(char,'manual',{
chat,
@@ -286,6 +316,116 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
}
break
}
// low level access only
case 'showAlert':{
if(!lowLevelAccess){
break
}
const effectValue = risuChatParser(effect.value,{chara:char})
const inputVar = risuChatParser(effect.inputVar,{chara:char})
switch(effect.alertType){
case 'normal':{
alertNormal(effectValue)
break
}
case 'error':{
alertError(effectValue)
break
}
case 'input':{
const val = await alertInput(effectValue)
setVar(inputVar, val)
}
case 'select':{
const val = await alertSelect(effectValue.split('§'))
setVar(inputVar, val)
}
}
break
}
case 'sendAIprompt':{
if(!lowLevelAccess){
break
}
sendAIprompt = true
break
}
case 'runLLM':{
if(!lowLevelAccess){
break
}
const effectValue = risuChatParser(effect.value,{chara:char})
const varName = effect.inputVar
let promptbody:OpenAIChat[] = []
let currentRole:'user'|'assistant'|'system'
const splited = effectValue.split('\n')
for(let i = 0; i < splited.length; i++){
const line = splited[i]
if(line.startsWith('@@role ')){
const role = line.split(' ')[1]
switch(role){
case 'user':
case 'assistant':
case 'system':
currentRole = role
break
default:
currentRole = 'system'
break
}
promptbody.push({role: currentRole, content: ''})
continue
}
else if(promptbody.length === 0){
promptbody.push({role: 'system', content: line})
}
else{
promptbody[promptbody.length - 1].content += line
}
}
promptbody = promptbody.map((e) => {
e.content = e.content.trim()
return e
}).filter((e) => e.content.length > 0)
const result = await requestChatData({
formated: promptbody,
bias: {},
useStreaming: false,
noMultiGen: true,
}, 'model')
if(result.type === 'fail' || result.type === 'streaming' || result.type === 'multiline'){
setVar(varName, 'Error: ' + result.result)
}
else{
setVar(varName, result.result)
}
break
}
case 'checkSimilarity':{
if(!lowLevelAccess){
break
}
const processer = new HypaProcesser('MiniLM')
const effectValue = risuChatParser(effect.value,{chara:char})
const source = risuChatParser(effect.source,{chara:char})
await processer.addText(effectValue.split('§'))
const val = await processer.similaritySearch(source)
setVar(effect.inputVar, val.join('§'))
break
}
}
}
}
@@ -305,6 +445,6 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
currentChat.scriptstate = chat.scriptstate
}
return {additonalSysPrompt, chat, tokens:caculatedTokens, stopSending}
return {additonalSysPrompt, chat, tokens:caculatedTokens, stopSending, sendAIprompt}
}

View File

@@ -797,6 +797,7 @@ export interface character{
ext: string
}>
defaultVariables?:string
lowLevelAccess?:boolean
}
@@ -843,6 +844,7 @@ export interface groupChat{
trashTime?:number
nickname?:string
defaultVariables?:string
lowLevelAccess?:boolean
}
export interface botPreset{