Merge branch 'main' of https://github.com/kwaroran/RisuAI
This commit is contained in:
@@ -413,10 +413,16 @@
|
||||
}
|
||||
|
||||
function isOrphan(summaryIndex: number): boolean {
|
||||
const char = DBState.db.characters[$selectedCharID];
|
||||
const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage];
|
||||
const summary = hypaV3DataState.summaries[summaryIndex];
|
||||
|
||||
for (const chatMemo of summary.chatMemos) {
|
||||
if (!getMessageFromChatMemo(chatMemo)) {
|
||||
if (chatMemo == null) {
|
||||
// Check first message exists
|
||||
if (!getFirstMessage()) return true;
|
||||
} else {
|
||||
if (chat.message.findIndex((m) => m.chatId === chatMemo) === -1)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -437,8 +443,7 @@
|
||||
const summary = hypaV3DataState.summaries[summaryIndex];
|
||||
const toSummarize: OpenAIChat[] = await Promise.all(
|
||||
summary.chatMemos.map(async (chatMemo) => {
|
||||
// Processed message
|
||||
const message = await getProcessedMessageFromChatMemo(chatMemo);
|
||||
const message = await getMessageFromChatMemo(chatMemo);
|
||||
|
||||
return {
|
||||
role: (message.role === "char"
|
||||
@@ -495,31 +500,28 @@
|
||||
summaryUIState.isRerolledTranslating = false;
|
||||
}
|
||||
|
||||
async function getProcessedMessageFromChatMemo(
|
||||
async function getMessageFromChatMemo(
|
||||
chatMemo: string | null
|
||||
): Promise<Message | null> {
|
||||
const unprocessed = getMessageFromChatMemo(chatMemo);
|
||||
|
||||
if (!unprocessed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getCurrentHypaV3Preset().settings.processRegexScript
|
||||
? await processRegexScript(unprocessed)
|
||||
: unprocessed;
|
||||
}
|
||||
|
||||
function getMessageFromChatMemo(chatMemo: string | null): Message | null {
|
||||
const char = DBState.db.characters[$selectedCharID];
|
||||
const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage];
|
||||
const shouldProcess = getCurrentHypaV3Preset().settings.processRegexScript;
|
||||
|
||||
let msg = null;
|
||||
let msgIndex = -1;
|
||||
|
||||
if (chatMemo == null) {
|
||||
const firstMessage = getFirstMessage();
|
||||
|
||||
return firstMessage ? { role: "char", data: firstMessage } : null;
|
||||
if (!firstMessage) return null;
|
||||
msg = { role: "char", data: firstMessage };
|
||||
} else {
|
||||
msgIndex = chat.message.findIndex((m) => m.chatId === chatMemo);
|
||||
if (msgIndex === -1) return null;
|
||||
msg = chat.message[msgIndex];
|
||||
}
|
||||
|
||||
return chat.message.find((m) => m.chatId === chatMemo) || null;
|
||||
return shouldProcess ? await processRegexScript(msg, msgIndex) : msg;
|
||||
}
|
||||
|
||||
function getFirstMessage(): string | null {
|
||||
@@ -533,15 +535,17 @@
|
||||
: null;
|
||||
}
|
||||
|
||||
async function processRegexScript(msg: Message): Promise<Message> {
|
||||
async function processRegexScript(
|
||||
msg: Message,
|
||||
msgIndex: number = -1
|
||||
): Promise<Message> {
|
||||
const char = DBState.db.characters[$selectedCharID];
|
||||
const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage];
|
||||
const newData: string = (
|
||||
await processScriptFull(
|
||||
char,
|
||||
risuChatParser(msg.data, { chara: char, role: msg.role }),
|
||||
"editprocess",
|
||||
-1,
|
||||
msgIndex,
|
||||
{
|
||||
chatRole: msg.role,
|
||||
}
|
||||
@@ -593,8 +597,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Processed message
|
||||
const message = await getProcessedMessageFromChatMemo(
|
||||
const message = await getMessageFromChatMemo(
|
||||
expandedMessageUIState.selectedChatMemo
|
||||
);
|
||||
|
||||
@@ -632,52 +635,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function getProcessedNextSummarizationTarget(): Promise<Message | null> {
|
||||
const unprocessed = getNextSummarizationTarget();
|
||||
|
||||
if (!unprocessed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getCurrentHypaV3Preset().settings.processRegexScript
|
||||
? await processRegexScript(unprocessed)
|
||||
: unprocessed;
|
||||
}
|
||||
|
||||
function getNextSummarizationTarget(): Message | null {
|
||||
async function getNextSummarizationTarget(): Promise<Message | null> {
|
||||
const char = DBState.db.characters[$selectedCharID];
|
||||
const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage];
|
||||
const shouldProcess = getCurrentHypaV3Preset().settings.processRegexScript;
|
||||
|
||||
// Summaries exist
|
||||
if (hypaV3DataState.summaries.length > 0) {
|
||||
const lastSummary = hypaV3DataState.summaries.at(-1);
|
||||
const lastMessageIndex = chat.message.findIndex(
|
||||
(msg) => msg.chatId === lastSummary.chatMemos.at(-1)
|
||||
(m) => m.chatId === lastSummary.chatMemos.at(-1)
|
||||
);
|
||||
|
||||
if (lastMessageIndex !== -1) {
|
||||
const nextMessage = chat.message[lastMessageIndex + 1];
|
||||
const next = chat.message[lastMessageIndex + 1] ?? null;
|
||||
|
||||
if (nextMessage) {
|
||||
return nextMessage;
|
||||
}
|
||||
return next && shouldProcess
|
||||
? await processRegexScript(next, lastMessageIndex + 1)
|
||||
: next;
|
||||
}
|
||||
}
|
||||
|
||||
// When no summaries exist OR couldn't find last connected message,
|
||||
// check if first message is available
|
||||
const firstMessage = getFirstMessage();
|
||||
|
||||
// When no summaries exist OR couldn't find last connected message
|
||||
// Check if first message is available
|
||||
if (!firstMessage || firstMessage.trim() === "") {
|
||||
if (chat.message.length > 0) {
|
||||
return chat.message[0];
|
||||
if (!firstMessage) {
|
||||
const next = chat.message[0] ?? null;
|
||||
|
||||
return next && shouldProcess ? await processRegexScript(next, 0) : next;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
// Will summarize first message
|
||||
const next: Message = { role: "char", chatId: "first", data: firstMessage };
|
||||
|
||||
// will summarize first message
|
||||
return { role: "char", chatId: "first", data: firstMessage };
|
||||
return shouldProcess ? await processRegexScript(next) : next;
|
||||
}
|
||||
|
||||
function isHypaV2ConversionPossible(): boolean {
|
||||
@@ -1278,8 +1270,7 @@
|
||||
{#if expandedMessageUIState?.summaryIndex === i}
|
||||
<!-- Expanded Message -->
|
||||
<div class="mt-2 sm:mt-4">
|
||||
<!-- Processed Message -->
|
||||
{#await getProcessedMessageFromChatMemo(expandedMessageUIState.selectedChatMemo) then expandedMessage}
|
||||
{#await getMessageFromChatMemo(expandedMessageUIState.selectedChatMemo) then expandedMessage}
|
||||
{#if expandedMessage}
|
||||
<!-- Role -->
|
||||
<div class="mb-2 sm:mb-4 text-sm text-zinc-400">
|
||||
@@ -1336,7 +1327,7 @@
|
||||
|
||||
<!-- Next Summarization Target -->
|
||||
<div class="mt-2 sm:mt-4">
|
||||
{#await getProcessedNextSummarizationTarget() then nextMessage}
|
||||
{#await getNextSummarizationTarget() then nextMessage}
|
||||
{#if nextMessage}
|
||||
{@const chatId =
|
||||
nextMessage.chatId === "first"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import SelectInput from "../UI/GUI/SelectInput.svelte";
|
||||
import Button from "../UI/GUI/Button.svelte";
|
||||
import { HypaProcesser } from "src/ts/process/memory/hypamemory";
|
||||
import { DBState } from "src/ts/stores.svelte"
|
||||
|
||||
let query = $state("");
|
||||
let model = $state("MiniLM");
|
||||
@@ -27,24 +28,43 @@
|
||||
<h2 class="text-4xl text-textcolor my-6 font-black relative">{language.embedding}</h2>
|
||||
|
||||
<span class="text-textcolor text-lg">Model</span>
|
||||
<SelectInput bind:value={model}>
|
||||
<SelectInput bind:value={model} className="mb-4">
|
||||
{#if 'gpu' in navigator}
|
||||
<OptionInput value="MiniLMGPU">MiniLM L6 v2 (GPU)</OptionInput>
|
||||
<OptionInput value="nomicGPU">Nomic Embed Text v1.5 (GPU)</OptionInput>
|
||||
<OptionInput value="bgeSmallEnGPU">BGE Small English (GPU)</OptionInput>
|
||||
<OptionInput value="bgem3GPU">BGE Medium 3 (GPU)</OptionInput>
|
||||
<OptionInput value="multiMiniLMGPU">Multilingual MiniLM L12 v2 (GPU)</OptionInput>
|
||||
<OptionInput value="bgeM3KoGPU">BGE Medium 3 Korean (GPU)</OptionInput>
|
||||
{/if}
|
||||
<OptionInput value="MiniLM">MiniLM L6 v2 (CPU)</OptionInput>
|
||||
<OptionInput value="nomic">Nomic Embed Text v1.5 (CPU)</OptionInput>
|
||||
<OptionInput value="nomicGPU">Nomic Embed Text v1.5 (GPU)</OptionInput>
|
||||
<OptionInput value="bgeSmallEn">BGE Small English (CPU)</OptionInput>
|
||||
<OptionInput value="bgeSmallEnGPU">BGE Small English (GPU)</OptionInput>
|
||||
<OptionInput value="bgem3">BGE Medium 3 (CPU)</OptionInput>
|
||||
<OptionInput value="bgem3GPU">BGE Medium 3 (GPU)</OptionInput>
|
||||
<OptionInput value="multiMiniLM">Multilingual MiniLM L12 v2 (CPU)</OptionInput>
|
||||
<OptionInput value="bgeM3Ko">BGE Medium 3 Korean (CPU)</OptionInput>
|
||||
<OptionInput value="openai3small">OpenAI text-embedding-3-small</OptionInput>
|
||||
<OptionInput value="openai3large">OpenAI text-embedding-3-large</OptionInput>
|
||||
<OptionInput value="ada">OpenAI Ada</OptionInput>
|
||||
<OptionInput value="custom">Custom (OpenAI-compatible)</OptionInput>
|
||||
</SelectInput>
|
||||
|
||||
{#if model === "custom"}
|
||||
<span class="text-textcolor text-lg">Custom Server URL</span>
|
||||
<TextInput bind:value={customEmbeddingUrl} size="lg" fullwidth />
|
||||
{#if model === 'openai3small' || model === 'openai3large' || model === 'ada'}
|
||||
<span class="text-textcolor text-lg">OpenAI API Key</span>
|
||||
<TextInput size="sm" marginBottom bind:value={DBState.db.supaMemoryKey}/>
|
||||
{/if}
|
||||
|
||||
{#if model === "custom"}
|
||||
<span class="text-textcolor text-lg">URL</span>
|
||||
<TextInput size="sm" marginBottom bind:value={DBState.db.hypaCustomSettings.url}/>
|
||||
<span class="text-textcolor text-lg">Key/Password</span>
|
||||
<TextInput size="sm" marginBottom bind:value={DBState.db.hypaCustomSettings.key}/>
|
||||
<span class="text-textcolor text-lg">Request Model</span>
|
||||
<TextInput size="sm" marginBottom bind:value={DBState.db.hypaCustomSettings.model}/>
|
||||
{/if}
|
||||
|
||||
<div class="mb-4"></div>
|
||||
|
||||
<span class="text-textcolor text-lg">Query</span>
|
||||
<TextInput bind:value={query} size="lg" fullwidth />
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
}
|
||||
// End HypaV3
|
||||
|
||||
let imageModel = '';
|
||||
let imageModel = $state('');
|
||||
|
||||
// add init NAI V4
|
||||
// if(DBState.db.NAIImgConfig.autoSmea === undefined) DBState.db.NAIImgConfig.autoSmea = false;
|
||||
@@ -277,13 +277,6 @@
|
||||
<span class="text-textcolor">CFG rescale</span>
|
||||
<NumberInput size="sm" marginBottom min={0} max={1} bind:value={DBState.db.NAIImgConfig.cfg_rescale}/>
|
||||
|
||||
<span class="text-textcolor">Noise Schedule</span>
|
||||
<SelectInput className="mt-2 mb-4" bind:value={DBState.db.NAIImgConfig.noise_schedule}>
|
||||
<OptionInput value="karras">karras</OptionInput>
|
||||
<OptionInput value="exponential">exponential</OptionInput>
|
||||
<OptionInput value="polyexponential">polyexponential</OptionInput>
|
||||
</SelectInput>
|
||||
|
||||
{#if !DBState.db.NAII2I || DBState.db.NAIImgConfig.sampler !== 'ddim_v3'}
|
||||
<Check bind:check={DBState.db.NAIImgConfig.sm} name="Use SMEA"/>
|
||||
{:else if DBState.db.NAIImgModel === 'nai-diffusion-4-full'
|
||||
@@ -294,11 +287,6 @@
|
||||
|
||||
{#if DBState.db.NAIImgModel === 'nai-diffusion-4-full'
|
||||
|| DBState.db.NAIImgModel === 'nai-diffusion-4-curated-preview'}
|
||||
|
||||
<span class="text-textcolor">Prompt Guidance Rescale</span>
|
||||
<SliderInput marginBottom min={0} max={1} step={0.02} fixed={2} bind:value={DBState.db.NAIImgConfig.cfg_rescale} />
|
||||
|
||||
|
||||
<Check bind:check={DBState.db.NAIImgConfig.autoSmea} name='Auto Smea'/>
|
||||
<Check bind:check={DBState.db.NAIImgConfig.use_coords} name='Use coords'/>
|
||||
<Check bind:check={DBState.db.NAIImgConfig.legacy_uc} name='Use legacy uc'/>
|
||||
@@ -917,19 +905,21 @@
|
||||
{/if}
|
||||
|
||||
<span class="text-textcolor">{language.embedding}</span>
|
||||
<SelectInput className="mt-2 mb-2" bind:value={DBState.db.hypaModel}>
|
||||
<SelectInput className="mb-4" bind:value={DBState.db.hypaModel}>
|
||||
{#if 'gpu' in navigator}
|
||||
<OptionInput value="MiniLMGPU">MiniLM L6 v2 (GPU)</OptionInput>
|
||||
<OptionInput value="nomicGPU">Nomic Embed Text v1.5 (GPU)</OptionInput>
|
||||
<OptionInput value="bgeSmallEnGPU">BGE Small English (GPU)</OptionInput>
|
||||
<OptionInput value="bgem3GPU">BGE Medium 3 (GPU)</OptionInput>
|
||||
<OptionInput value="multiMiniLMGPU">Multilingual MiniLM L12 v2 (GPU)</OptionInput>
|
||||
<OptionInput value="bgeM3KoGPU">BGE Medium 3 Korean (GPU)</OptionInput>
|
||||
{/if}
|
||||
<OptionInput value="MiniLM">MiniLM L6 v2 (CPU)</OptionInput>
|
||||
<OptionInput value="nomic">Nomic Embed Text v1.5 (CPU)</OptionInput>
|
||||
<OptionInput value="bgeSmallEn">BGE Small English (CPU)</OptionInput>
|
||||
<OptionInput value="bgem3">BGE Medium 3 (CPU)</OptionInput>
|
||||
<OptionInput value="multiMiniLM">Multilingual MiniLM L12 v2 (CPU)</OptionInput>
|
||||
<OptionInput value="bgeM3Ko">BGE Medium 3 Korean (CPU)</OptionInput>
|
||||
<OptionInput value="openai3small">OpenAI text-embedding-3-small</OptionInput>
|
||||
<OptionInput value="openai3large">OpenAI text-embedding-3-large</OptionInput>
|
||||
<OptionInput value="ada">OpenAI Ada</OptionInput>
|
||||
|
||||
@@ -21,6 +21,8 @@ export const localModels = {
|
||||
'bgem3GPU': 'Xenova/bge-m3',
|
||||
'multiMiniLM': 'Xenova/paraphrase-multilingual-MiniLM-L12-v2',
|
||||
'multiMiniLMGPU': 'Xenova/paraphrase-multilingual-MiniLM-L12-v2',
|
||||
'bgeM3Ko': 'HyperBlaze/BGE-m3-ko',
|
||||
'bgeM3KoGPU': 'HyperBlaze/BGE-m3-ko',
|
||||
},
|
||||
gpuModels:[
|
||||
'MiniLMGPU',
|
||||
@@ -28,6 +30,7 @@ export const localModels = {
|
||||
'bgeSmallEnGPU',
|
||||
'bgem3GPU',
|
||||
'multiMiniLMGPU',
|
||||
'bgeM3KoGPU',
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ export async function hypaMemoryV3(
|
||||
} finally {
|
||||
if (settings.summarizationModel !== "subModel") {
|
||||
try {
|
||||
unloadEngine();
|
||||
await unloadEngine();
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export const runEmbedding = async (texts: string[], model:EmbeddingModel = 'Xeno
|
||||
}
|
||||
extractor = await pipeline('feature-extraction', model, {
|
||||
// Default dtype for webgpu is fp32, so we can use q8, which is the default dtype in wasm.
|
||||
...(device === 'webgpu' ? { dtype: "q8" } : {}),
|
||||
dtype: "q8",
|
||||
device: device,
|
||||
progress_callback: (progress) => {
|
||||
console.log(progress)
|
||||
|
||||
@@ -310,9 +310,6 @@ export function setDatabase(data:Database){
|
||||
legacy_uc:false,
|
||||
};
|
||||
}
|
||||
if(checkNullish(data.NAIImgConfig.cfg_rescale)){
|
||||
data.NAIImgConfig.cfg_rescale = 0;
|
||||
}
|
||||
if(checkNullish(data.customTextTheme)){
|
||||
data.customTextTheme = {
|
||||
FontColorStandard: "#f8f8f2",
|
||||
|
||||
Reference in New Issue
Block a user