Add new asset finder and preset chain

This commit is contained in:
kwaroran
2024-12-08 21:25:57 +09:00
parent c454f8df2d
commit 40ad42ffe9
6 changed files with 84 additions and 8 deletions

View File

@@ -171,7 +171,8 @@ export const languageEnglish = {
translatorPrompt: "The prompt that is used for translation. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the dest language, {{solt::content}} for the content, and {{slot::tnote}} for the translator note.", translatorPrompt: "The prompt that is used for translation. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the dest language, {{solt::content}} for the content, and {{slot::tnote}} for the translator note.",
translateBeforeHTMLFormatting: "If enabled, it will translate the text before Regex scripts and HTML formatting. this could make the token lesser but could break the formatting.", translateBeforeHTMLFormatting: "If enabled, it will translate the text before Regex scripts and HTML formatting. this could make the token lesser but could break the formatting.",
autoTranslateCachedOnly: "If enabled, it will automatically translate only the text that the user has translated previously.", autoTranslateCachedOnly: "If enabled, it will automatically translate only the text that the user has translated previously.",
APIPool: "If enabled, it will connect to RisuAI API Pool. Every user which API pool is enabled, the API key will be shared if it used for free, rate-limited models, making it user to make more request of rate-limited models by using other's API key that didn't used much." presetChain: "If it is not blank, the preset will be changed and applied randomly every time when user sends a message in the preset list in this input. preset list should be seperated by comma, for example, `preset1,preset2`.",
legacyMediaFindings: "If enabled, it will use the old method to find media assets, without using the additional search algorithm.",
}, },
setup: { setup: {
chooseProvider: "Choose AI Provider", chooseProvider: "Choose AI Provider",
@@ -819,5 +820,6 @@ export const languageEnglish = {
customFlags: "Custom Flags", customFlags: "Custom Flags",
enableCustomFlags: "Enable Custom Flags", enableCustomFlags: "Enable Custom Flags",
googleCloudTokenization: "Google Cloud Tokenization", googleCloudTokenization: "Google Cloud Tokenization",
APIPool: "API Pool" presetChain: "Preset Chain",
legacyMediaFindings: "Legacy Media Findings",
} }

View File

@@ -41,6 +41,9 @@
<span class="text-textcolor">Kei Server URL</span> <span class="text-textcolor">Kei Server URL</span>
<TextInput marginBottom={true} size={"sm"} bind:value={DBState.db.keiServerURL} placeholder="Leave it blank to use default"/> <TextInput marginBottom={true} size={"sm"} bind:value={DBState.db.keiServerURL} placeholder="Leave it blank to use default"/>
<span class="text-textcolor">{language.presetChain}</span>
<TextInput marginBottom={true} size={"sm"} bind:value={DBState.db.presetChain} placeholder="Leave it blank to not use"/>
<span class="text-textcolor">{language.requestretrys} <Help key="requestretrys"/></span> <span class="text-textcolor">{language.requestretrys} <Help key="requestretrys"/></span>
<NumberInput marginBottom={true} size={"sm"} min={0} max={20} bind:value={DBState.db.requestRetrys}/> <NumberInput marginBottom={true} size={"sm"} min={0} max={20} bind:value={DBState.db.requestRetrys}/>
@@ -78,6 +81,9 @@
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check bind:check={DBState.db.forceProxyAsOpenAI} name={language.forceProxyAsOpenAI}> <Help key="forceProxyAsOpenAI"/></Check> <Check bind:check={DBState.db.forceProxyAsOpenAI} name={language.forceProxyAsOpenAI}> <Help key="forceProxyAsOpenAI"/></Check>
</div> </div>
<div class="flex items-center mt-4">
<Check bind:check={DBState.db.legacyMediaFindings} name={language.legacyMediaFindings}> <Help key="legacyMediaFindings"/></Check>
</div>
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check bind:check={DBState.db.autofillRequestUrl} name={language.autoFillRequestURL}> <Help key="autoFillRequestURL"/></Check> <Check bind:check={DBState.db.autofillRequestUrl} name={language.autoFillRequestURL}> <Help key="autoFillRequestURL"/></Check>
</div> </div>

View File

@@ -906,7 +906,6 @@ async function fetchWithProxy(url: string, arg: GlobalFetchArgs): Promise<Global
"risu-url": encodeURIComponent(url), "risu-url": encodeURIComponent(url),
"Content-Type": arg.body instanceof URLSearchParams ? "application/x-www-form-urlencoded" : "application/json", "Content-Type": arg.body instanceof URLSearchParams ? "application/x-www-form-urlencoded" : "application/json",
...(arg.useRisuToken && { "x-risu-tk": "use" }), ...(arg.useRisuToken && { "x-risu-tk": "use" }),
"risu-pool": DBState.db.risuPool ? 'true' : 'false'
}; };
const body = arg.body instanceof URLSearchParams ? arg.body.toString() : JSON.stringify(arg.body); const body = arg.body instanceof URLSearchParams ? arg.body.toString() : JSON.stringify(arg.body);

View File

@@ -318,10 +318,18 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
} }
} }
} }
const path = assetPaths[name] let path = assetPaths[name]
if(!path){
if(DBState.db.legacyMediaFindings){
return ''
}
path = getClosestMatch(name, assetPaths)
if(!path){ if(!path){
return '' return ''
} }
}
switch(type){ switch(type){
case 'raw': case 'raw':
case 'path': case 'path':
@@ -366,6 +374,50 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
return data return data
} }
function getClosestMatch(name:string, assetPaths:{[key:string]:{path:string, ext?:string}}){
if(Object.keys(assetPaths).length === 0){
return null
}
const dest = (a:string, b:string) => {
let d:Int16Array[] = []
for(let i=0;i<a.length+1;i++){
d.push(new Int16Array(b.length+1))
}
for(let i=0;i<=a.length;i++){
d[i][0] = i
}
for(let i=0;i<=b.length;i++){
d[0][i] = i
}
for(let i=1; i<=a.length; i++){
for(let j=1;j<=b.length;j++){
d[i][j] = Math.min(
d[i-1][j-1] + (a.charAt(i-1)===b.charAt(j-1) ? 0 : 1),
d[i-1][j]+1, d[i][j-1]+1
)
}
}
return d[a.length][b.length];
}
let closest = ''
let closestDist = 999999
for(const key in assetPaths){
const dist = dest(name.trim().replace(/[_ ]/g, ''), key.trim().replace(/[_ ]/g, ''))
if(dist < closestDist){
closest = key
closestDist = dist
}
}
return assetPaths[closest]
}
async function parseInlayImages(data:string){ async function parseInlayImages(data:string){
const inlayMatch = data.match(/{{inlay::(.+?)}}/g) const inlayMatch = data.match(/{{inlay::(.+?)}}/g)
if(inlayMatch){ if(inlayMatch){

View File

@@ -1,10 +1,10 @@
import { get, writable } from "svelte/store"; import { get, writable } from "svelte/store";
import { type character, type MessageGenerationInfo, type Chat } from "../storage/database.svelte"; import { type character, type MessageGenerationInfo, type Chat, changeToPreset } from "../storage/database.svelte";
import { DBState } from '../stores.svelte'; import { DBState } from '../stores.svelte';
import { CharEmotion, selectedCharID } from "../stores.svelte"; import { CharEmotion, selectedCharID } from "../stores.svelte";
import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer"; import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
import { language } from "../../lang"; import { language } from "../../lang";
import { alertError } from "../alert"; import { alertError, alertToast } from "../alert";
import { loadLoreBookV3Prompt } from "./lorebook.svelte"; import { loadLoreBookV3Prompt } from "./lorebook.svelte";
import { findCharacterbyId, getAuthorNoteDefaultText, getPersonaPrompt, getUserName, isLastCharPunctuation, trimUntilPunctuation } from "../util"; import { findCharacterbyId, getAuthorNoteDefaultText, getPersonaPrompt, getUserName, isLastCharPunctuation, trimUntilPunctuation } from "../util";
import { requestChatData } from "./request"; import { requestChatData } from "./request";
@@ -109,6 +109,22 @@ export async function sendChat(chatProcessIndex = -1,arg:{
} }
doingChat.set(true) doingChat.set(true)
if(chatProcessIndex === -1 && DBState.db.presetChain){
const names = DBState.db.presetChain.split(' ')
const ele = names[Math.random() * names.length]
const findId = DBState.db.botPresets.findIndex((v) => {
return v.name === ele
})
if(findId === -1){
alertToast(`Cannot find preset: ${ele}`)
}
else{
changeToPreset(findId, true)
}
}
if(connectionOpen){ if(connectionOpen){
chatProcessStage.set(4) chatProcessStage.set(4)
const peerSafe = await peerSafeCheck() const peerSafe = await peerSafeCheck()

View File

@@ -854,7 +854,8 @@ export interface Database{
customFlags: LLMFlags[] customFlags: LLMFlags[]
enableCustomFlags: boolean enableCustomFlags: boolean
googleClaudeTokenizing: boolean googleClaudeTokenizing: boolean
risuPool: boolean presetChain: string
legacyMediaFindings?:boolean
} }
interface SeparateParameters{ interface SeparateParameters{