Add plenty of features

This commit is contained in:
Kwaroran
2024-11-27 06:01:42 +09:00
parent 73b7fd9156
commit 981ec3921e
13 changed files with 285 additions and 133 deletions

View File

@@ -167,6 +167,9 @@ export const languageEnglish = {
chatHTML: "A HTML that would be inserted as each chat.\n\nYou can use CBS and special tags.\n- `<risutextbox>`: a textbox that would be used to render text\n- `<risuicon>`: an icon for user or assistant\n- `<risubuttons>`: icon buttons for chat edit, translations and etc.\n- `<risugeninfo>`: generation information button.",
systemContentReplacement: "The prompt format that replaces system prompt if the model doesn't support system prompt.",
systemRoleReplacement: "The role that replaces system role if the model doesn't support system role.",
summarizationPrompt: "The prompt that is used for summarization. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the chat data.",
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.",
},
setup: {
chooseProvider: "Choose AI Provider",
@@ -801,4 +804,9 @@ export const languageEnglish = {
predictedOutput: "Predicted Output",
systemContentReplacement: "System Content Replacement",
systemRoleReplacement: "System Role Replacement",
seperateParameters: "Seperate Parameters",
seperateParametersEnabled: "Enable Seperate Parameters",
summarizationPrompt: "Summarization Prompt",
translatorPrompt: "Translation Prompt",
translateBeforeHTMLFormatting: "Translate Before HTML Formatting",
}

View File

@@ -148,7 +148,16 @@
}
}
if(translateText){
if(!DBState.db.legacyTranslation){
if(DBState.db.translator === 'llm' && DBState.db.translateBeforeHTMLFormatting){
translating = true
data = await translateHTML(data, false, charArg, chatID)
translating = false
const marked = await ParseMarkdown(data, charArg, mode, chatID, getCbsCondition())
lastParsedQueue = marked
lastCharArg = charArg
return marked
}
else if(!DBState.db.legacyTranslation){
const marked = await ParseMarkdown(data, charArg, 'pretranslate', chatID, getCbsCondition())
translating = true
const translated = await postTranslationParse(await translateHTML(marked, false, charArg, chatID))

View File

@@ -27,7 +27,8 @@
import PromptSettings from "./PromptSettings.svelte";
import { openPresetList } from "src/ts/stores.svelte";
import { selectSingleFile } from "src/ts/util";
import { LLMFormat } from "src/ts/model/modellist";
import { getModelInfo, LLMFlags, LLMFormat, LLMProvider } from "src/ts/model/modellist";
import CheckInput from "src/lib/UI/GUI/CheckInput.svelte";
let tokens = $state({
mainPrompt: 0,
@@ -54,6 +55,8 @@
});
let submenu = $state(DBState.db.useLegacyGUI ? -1 : 0)
let modelInfo = $derived(getModelInfo(DBState.db.aiModel))
let subModelInfo = $derived(getModelInfo(DBState.db.subModel))
</script>
<h2 class="mb-2 text-2xl font-bold mt-2">{language.chatBot}</h2>
@@ -89,26 +92,21 @@
<span class="text-textcolor mt-2">{language.submodel} <Help key="submodel"/></span>
<ModelList bind:value={DBState.db.subModel}/>
{#if DBState.db.aiModel.startsWith('palm2') || DBState.db.subModel.startsWith('palm2') || DBState.db.aiModel.startsWith('gemini') || DBState.db.subModel.startsWith('gemini')}
<span class="text-textcolor">
{#if DBState.db.google.projectId === 'aigoogle'}
GoogleAI API Key
{:else}
Google Bearer Token
{/if}
</span>
{#if modelInfo.provider === LLMProvider.GoogleCloud || subModelInfo.provider === LLMProvider.GoogleCloud}
<span class="text-textcolor">GoogleAI API Key</span>
<TextInput marginBottom={true} size={"sm"} placeholder="..." hideText={DBState.db.hideApiKey} bind:value={DBState.db.google.accessToken}/>
{#if DBState.db.google.projectId !== 'aigoogle'}
<span class="text-textcolor">Google Project ID</span>
<TextInput marginBottom={true} size={"sm"} placeholder="..." hideText={DBState.db.hideApiKey} bind:value={DBState.db.google.projectId}/>
{/if}
{/if}
{#if DBState.db.aiModel.startsWith('jamba') || DBState.db.subModel.startsWith('jamba')}
{#if modelInfo.provider === LLMProvider.VertexAI || subModelInfo.provider === LLMProvider.VertexAI}
<span class="text-textcolor">Vertex Client Email</span>
<TextInput marginBottom={true} size={"sm"} placeholder="..." hideText={DBState.db.hideApiKey} bind:value={DBState.db.vertexClientEmail}/>
<span class="text-textcolor">Vertex Private Key</span>
<TextInput marginBottom={true} size={"sm"} placeholder="..." hideText={DBState.db.hideApiKey} bind:value={DBState.db.vertexPrivateKey}/>
{/if}
{#if modelInfo.provider === LLMProvider.AI21 || subModelInfo.provider === LLMProvider.AI21}
<span class="text-textcolor">AI21 {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={true} size={"sm"} placeholder="..." bind:value={DBState.db.ai21Key}/>
{/if}
{#if DBState.db.aiModel.startsWith('novellist') || DBState.db.subModel.startsWith('novellist')}
{#if modelInfo.provider === LLMProvider.NovelList || subModelInfo.provider === LLMProvider.NovelList}
<span class="text-textcolor">NovelList {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={true} size={"sm"} placeholder="..." bind:value={DBState.db.novellistAPI}/>
{/if}
@@ -116,15 +114,15 @@
<span class="text-textcolor">Mancer {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={true} size={"sm"} placeholder="..." bind:value={DBState.db.mancerHeader}/>
{/if}
{#if DBState.db.aiModel.startsWith('claude-') || DBState.db.subModel.startsWith('claude-')}
{#if modelInfo.provider === LLMProvider.Anthropic || subModelInfo.provider === LLMProvider.Anthropic}
<span class="text-textcolor">Claude {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={true} size={"sm"} placeholder="..." bind:value={DBState.db.claudeAPIKey}/>
{/if}
{#if DBState.db.aiModel.startsWith('mistral') || DBState.db.subModel.startsWith('mistral')}
{#if modelInfo.provider === LLMProvider.Mistral || subModelInfo.provider === LLMProvider.Mistral}
<span class="text-textcolor">Mistral {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={true} size={"sm"} placeholder="..." bind:value={DBState.db.mistralKey}/>
{/if}
{#if DBState.db.aiModel.startsWith('novelai') || DBState.db.subModel.startsWith('novelai')}
{#if modelInfo.provider === LLMProvider.NovelAI || subModelInfo.provider === LLMProvider.NovelAI}
<span class="text-textcolor">NovelAI Bearer Token</span>
<TextInput bind:value={DBState.db.novelai.token}/>
{/if}
@@ -156,11 +154,7 @@
</OptionInput>
</SelectInput>
{/if}
{#if DBState.db.aiModel.startsWith('risullm')}
<span class="text-textcolor mt-4">Risu {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={false} size={"sm"} bind:value={DBState.db.proxyKey} />
{/if}
{#if DBState.db.aiModel.startsWith('cohere')}
{#if modelInfo.provider === LLMProvider.Cohere || subModelInfo.provider === LLMProvider.Cohere}
<span class="text-textcolor mt-4">Cohere {language.apiKey}</span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={false} size={"sm"} bind:value={DBState.db.cohereAPIKey} />
{/if}
@@ -211,32 +205,21 @@
{/each}
</SelectInput>
{/if}
{#if DBState.db.aiModel.startsWith('gpt') || DBState.db.subModel.startsWith('gpt')
|| DBState.db.aiModel.startsWith('instructgpt') || DBState.db.subModel.startsWith('instructgpt')}
{#if modelInfo.provider === LLMProvider.OpenAI || subModelInfo.provider === LLMProvider.OpenAI}
<span class="text-textcolor">OpenAI {language.apiKey} <Help key="oaiapikey"/></span>
<TextInput hideText={DBState.db.hideApiKey} marginBottom={false} size={"sm"} bind:value={DBState.db.openAIKey} placeholder="sk-XXXXXXXXXXXXXXXXXXXX"/>
{/if}
<div class="py-2 flex flex-col gap-2 mb-4">
{#if DBState.db.aiModel.startsWith('gpt') || DBState.db.aiModel === 'reverse_proxy' || DBState.db.aiModel === 'openrouter' || DBState.db.aiModel.startsWith('claude-3')}
{#if modelInfo.flags.includes(LLMFlags.hasStreaming) || subModelInfo.flags.includes(LLMFlags.hasStreaming)}
<Check bind:check={DBState.db.useStreaming} name={`Response ${language.streaming}`}/>
{/if}
{#if DBState.db.aiModel.startsWith('palm2') || DBState.db.subModel.startsWith('palm2') || DBState.db.aiModel.startsWith('gemini') || DBState.db.subModel.startsWith('gemini')}
<Check check={DBState.db.google.projectId !== 'aigoogle'} name={'Use Vertex AI'} onChange={(v) => {
if(!v){
DBState.db.google.projectId = 'aigoogle'
}
else{
DBState.db.google.projectId = ''
}
}}/>
{/if}
{#if DBState.db.aiModel === 'reverse_proxy' || DBState.db.subModel === 'reverse_proxy'}
<Check bind:check={DBState.db.reverseProxyOobaMode} name={`${language.reverseProxyOobaMode}`}/>
{/if}
{#if DBState.db.aiModel === "novelai" || DBState.db.subModel === "novelai" || DBState.db.aiModel === 'novelai_kayra' || DBState.db.subModel === 'novelai_kayra'}
{#if modelInfo.provider === LLMProvider.NovelAI || subModelInfo.provider === LLMProvider.NovelAI}
<Check bind:check={DBState.db.NAIadventure} name={language.textAdventureNAI}/>
<Check bind:check={DBState.db.NAIappendName} name={language.appendNameNAI}/>
@@ -299,25 +282,21 @@
<NumberInput bind:value={DBState.db.generationSeed} marginBottom={true}/>
{/if}
<span class="text-textcolor">{language.temperature} <Help key="tempature"/></span>
{#if DBState.db.aiModel.startsWith("novelai")}
<SliderInput min={0} max={250} marginBottom bind:value={DBState.db.temperature} multiple={0.01} fixed={2} disableable/>
{:else}
<SliderInput min={0} max={200} marginBottom bind:value={DBState.db.temperature} multiple={0.01} fixed={2} disableable/>
{/if}
{#if DBState.db.aiModel.startsWith('openrouter') || DBState.db.aiModel.startsWith('claude-3') || DBState.db.aiModel.startsWith('cohere-')|| DBState.db.aiModel === 'kobold'}
<SliderInput min={0} max={200} marginBottom bind:value={DBState.db.temperature} multiple={0.01} fixed={2} disableable/>
{#if modelInfo.parameters.includes('top_k')}
<span class="text-textcolor">Top K</span>
<SliderInput min={0} max={100} marginBottom step={1} bind:value={DBState.db.top_k} disableable/>
{/if}
{#if DBState.db.aiModel.startsWith('openrouter')}
{#if modelInfo.parameters.includes('min_p')}
<span class="text-textcolor">Min P</span>
<SliderInput min={0} max={1} marginBottom step={0.01} fixed={2} bind:value={DBState.db.min_p} disableable/>
{/if}
{#if DBState.db.aiModel.startsWith('openrouter') || DBState.db.aiModel === 'kobold'}
{#if modelInfo.parameters.includes('top_a')}
<span class="text-textcolor">Top A</span>
<SliderInput min={0} max={1} marginBottom step={0.01} fixed={2} bind:value={DBState.db.top_a} disableable/>
{/if}
{#if modelInfo.parameters.includes('repetition_penalty')}
<span class="text-textcolor">Repetition penalty</span>
<SliderInput min={0} max={2} marginBottom step={0.01} fixed={2} bind:value={DBState.db.repetition_penalty} disableable/>
@@ -389,7 +368,7 @@
</div>
<Check bind:check={DBState.db.ooba.formating.useName} name={language.useNamePrefix}/>
{:else if DBState.db.aiModel.startsWith('novelai')}
{:else if modelInfo.format === LLMFormat.NovelAI}
<div class="flex flex-col p-3 bg-darkbg mt-4">
<span class="text-textcolor">Starter</span>
<TextInput bind:value={DBState.db.NAIsettings.starter} placeholder={'⁂'} />
@@ -423,7 +402,7 @@
<span class="text-textcolor">Cfg Scale</span>
<SliderInput min={1} max={3} step={0.01} marginBottom fixed={2} bind:value={DBState.db.NAIsettings.cfg_scale}/>
{:else if DBState.db.aiModel.startsWith('novellist')}
{:else if modelInfo.format === LLMFormat.NovelList}
<span class="text-textcolor">Top P</span>
<SliderInput min={0} max={2} step={0.01} marginBottom fixed={2} bind:value={DBState.db.ainconfig.top_p}/>
<span class="text-textcolor">Reputation Penalty</span>
@@ -438,22 +417,19 @@
<SliderInput min={0} max={1} step={0.01} marginBottom fixed={2} bind:value={DBState.db.ainconfig.top_a}/>
<span class="text-textcolor">Typical P</span>
<SliderInput min={0} max={1} step={0.01} marginBottom fixed={2} bind:value={DBState.db.ainconfig.typical_p}/>
{:else if DBState.db.aiModel.startsWith('claude')}
<span class="text-textcolor">Top P <Help key="topP"/></span>
<SliderInput min={0} max={1} step={0.01} marginBottom fixed={2} bind:value={DBState.db.top_p} disableable/>
{:else if DBState.db.aiModel.startsWith('kobold')}
<span class="text-textcolor">Top P <Help key="topP"/></span>
<SliderInput min={0} max={1} step={0.01} marginBottom fixed={2} bind:value={DBState.db.top_p} disableable/>
{:else}
<span class="text-textcolor">Top P <Help key="topP"/></span>
<SliderInput min={0} max={1} step={0.01} marginBottom fixed={2} bind:value={DBState.db.top_p} disableable/>
<span class="text-textcolor">{language.frequencyPenalty} <Help key="frequencyPenalty"/></span>
<SliderInput min={0} max={200} marginBottom fixed={2} multiple={0.01} bind:value={DBState.db.frequencyPenalty} disableable/>
<span class="text-textcolor">{language.presensePenalty} <Help key="presensePenalty"/></span>
<SliderInput min={0} max={200} marginBottom fixed={2} multiple={0.01} bind:value={DBState.db.PresensePenalty} disableable/>
{#if modelInfo.parameters.includes('top_p')}
<span class="text-textcolor">Top P</span>
<SliderInput min={0} max={1} step={0.01} marginBottom fixed={2} bind:value={DBState.db.top_p} disableable/>
{/if}
{#if modelInfo.parameters.includes('frequency_penalty')}
<span class="text-textcolor">{language.frequencyPenalty}</span>
<SliderInput min={0} max={200} marginBottom fixed={2} multiple={0.01} bind:value={DBState.db.frequencyPenalty} disableable/>
{/if}
{#if modelInfo.parameters.includes('presence_penalty')}
<span class="text-textcolor">{language.presensePenalty}</span>
<SliderInput min={0} max={200} marginBottom fixed={2} multiple={0.01} bind:value={DBState.db.PresensePenalty} disableable/>
{/if}
{/if}
{#if (DBState.db.reverseProxyOobaMode && DBState.db.aiModel === 'reverse_proxy') || (DBState.db.aiModel === 'ooba')}
@@ -464,6 +440,41 @@
<OpenrouterSettings />
{/if}
<Arcodion name={language.seperateParameters} styled>
<CheckInput bind:check={DBState.db.seperateParametersEnabled} name={language.seperateParametersEnabled} />
{#if DBState.db.seperateParametersEnabled}
{#each Object.keys(DBState.db.seperateParameters) as param, i}
<Arcodion name={
{
memory: language.longTermMemory,
emotion: language.emotionImage,
translate: language.translator,
otherAx: language.others,
}[param]
} styled>
<span class="text-textcolor">{language.temperature} <Help key="tempature"/></span>
<SliderInput min={0} max={200} marginBottom bind:value={DBState.db.seperateParameters[param].temperature} multiple={0.01} fixed={2} disableable/>
<span class="text-textcolor">Top K</span>
<SliderInput min={0} max={100} marginBottom step={1} bind:value={DBState.db.seperateParameters[param].top_k} disableable/>
<span class="text-textcolor">Repetition penalty</span>
<SliderInput min={0} max={2} marginBottom step={0.01} fixed={2} bind:value={DBState.db.seperateParameters[param].repetition_penalty} disableable/>
<span class="text-textcolor">Min P</span>
<SliderInput min={0} max={1} marginBottom step={0.01} fixed={2} bind:value={DBState.db.seperateParameters[param].min_p} disableable/>
<span class="text-textcolor">Top A</span>
<SliderInput min={0} max={1} marginBottom step={0.01} fixed={2} bind:value={DBState.db.seperateParameters[param].top_a} disableable/>
<span class="text-textcolor">Top P</span>
<SliderInput min={0} max={1} marginBottom step={0.01} fixed={2} bind:value={DBState.db.seperateParameters[param].top_p} disableable/>
<span class="text-textcolor">Frequency Penalty</span>
<SliderInput min={0} max={200} marginBottom step={0.01} fixed={2} bind:value={DBState.db.seperateParameters[param].frequency_penalty} disableable/>
<span class="text-textcolor">Presence Penalty</span>
<SliderInput min={0} max={200} marginBottom step={0.01} fixed={2} bind:value={DBState.db.seperateParameters[param].presence_penalty} disableable/>
</Arcodion>
{/each}
{/if}
</Arcodion>
{/if}
{#if submenu === 3 || submenu === -1}

View File

@@ -115,6 +115,8 @@
{#if DBState.db.translatorType === 'llm'}
<span class="text-textcolor mt-4">{language.translationResponseSize}</span>
<NumberInput min={0} max={2048} marginBottom={true} bind:value={DBState.db.translatorMaxResponse}/>
<span class="text-textcolor mt-4">{language.translatorPrompt} <Help key="translatorPrompt" /></span>
<TextAreaInput bind:value={DBState.db.translatorPrompt} placeholder={"You are a translator. translate the following html or text into {{slot}}. do not output anything other than the translation."}/>
{/if}
@@ -149,4 +151,12 @@
<Help key="legacyTranslation"/>
</Check>
</div>
{#if DBState.db.translatorType === 'llm'}
<div class="flex items-center mt-4">
<Check bind:check={DBState.db.translateBeforeHTMLFormatting} name={language.translateBeforeHTMLFormatting}>
<Help key="translateBeforeHTMLFormatting"/>
</Check>
</div>
{/if}
{/if}

View File

@@ -15,6 +15,7 @@
import { getCharImage } from "src/ts/characters";
import Arcodion from "src/lib/UI/Arcodion.svelte";
import CheckInput from "src/lib/UI/GUI/CheckInput.svelte";
import TextAreaInput from "src/lib/UI/GUI/TextAreaInput.svelte";
$effect.pre(() => {
DBState.db.NAIImgConfig ??= {
width: 512,
@@ -423,8 +424,8 @@
<span class="text-textcolor">{language.SuperMemory} OpenAI Key</span>
<TextInput size="sm" marginBottom bind:value={DBState.db.supaMemoryKey}/>
{/if}
<span class="text-textcolor">{language.SuperMemory} Prompt</span>
<TextInput size="sm" marginBottom bind:value={DBState.db.supaMemoryPrompt} placeholder="Leave it blank to use default"/>
<span class="text-textcolor">{language.summarizationPrompt} <Help key="summarizationPrompt" /></span>
<TextAreaInput size="sm" bind:value={DBState.db.supaMemoryPrompt} placeholder="Leave it blank to use default"/>
<span class="text-textcolor">{language.HypaMemory} Model</span>
<SelectInput className="mt-2 mb-2" bind:value={DBState.db.hypaModel}>
<OptionInput value="MiniLM">MiniLM-L6-v2 (Free / Local)</OptionInput>

View File

@@ -13,7 +13,7 @@
{#if disableable}
<div class="relative h-8 border-darkborderc border rounded-full cursor-pointer rounded-r-none border-r-0 flex justify-center items-center">
<CheckInput check={value !== -1000} margin={false} onChange={(c) => {
<CheckInput check={value !== -1000 && value !== undefined} margin={false} onChange={(c) => {
onchange?.()
if(c) {
value = min;
@@ -58,7 +58,7 @@
<span
class="absolute top-0 left-4 h-8 rounded-full items-center justify-center flex text-textcolor text-sm"
>
{customText === undefined ? (value === -1000 ? language.disabled : (value * multiple).toFixed(fixed)) : customText}
{customText === undefined ? ((value === -1000 || value === undefined) ? language.disabled : (value * multiple).toFixed(fixed)) : customText}
</span>
</div>
</div>

View File

@@ -9,6 +9,7 @@ export enum LLMFlags{
hasCache,
hasFullSystemPrompt,
hasFirstSystemPrompt,
hasStreaming,
requiresAlternateRole,
mustStartWithUserInput,
}
@@ -26,6 +27,7 @@ export enum LLMProvider{
WebLLM,
Horde,
AWS,
AI21
}
export enum LLMFormat{
@@ -87,7 +89,7 @@ export const LLMModels: LLMModel[] = [
name: 'GPT-3.5',
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [LLMFlags.hasFullSystemPrompt],
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
parameters: OpenAIParameters,
},
{
@@ -96,7 +98,7 @@ export const LLMModels: LLMModel[] = [
name: 'InstructGPT-3.5',
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAILegacyInstruct,
flags: [LLMFlags.hasFullSystemPrompt],
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
parameters: OpenAIParameters,
},
{
@@ -105,7 +107,7 @@ export const LLMModels: LLMModel[] = [
name: 'GPT-4 Turbo',
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [LLMFlags.hasFullSystemPrompt],
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
parameters: OpenAIParameters,
},
{
@@ -116,7 +118,8 @@ export const LLMModels: LLMModel[] = [
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
recommended: true,
parameters: OpenAIParameters,
@@ -129,7 +132,8 @@ export const LLMModels: LLMModel[] = [
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
recommended: true,
parameters: OpenAIParameters,
@@ -141,7 +145,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -152,7 +157,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -163,7 +169,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -174,7 +181,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -185,7 +193,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -196,7 +205,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -207,7 +217,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -218,7 +229,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -229,7 +241,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -240,7 +253,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -251,7 +265,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -262,7 +277,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -273,7 +289,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -283,7 +300,10 @@ export const LLMModels: LLMModel[] = [
name: 'GPT-4 Vision 1106',
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [LLMFlags.hasImageInput],
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
{
@@ -293,7 +313,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -305,7 +326,8 @@ export const LLMModels: LLMModel[] = [
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -317,7 +339,8 @@ export const LLMModels: LLMModel[] = [
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -329,7 +352,8 @@ export const LLMModels: LLMModel[] = [
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -341,7 +365,8 @@ export const LLMModels: LLMModel[] = [
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasImageInput,
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -352,7 +377,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -363,7 +389,8 @@ export const LLMModels: LLMModel[] = [
provider: LLMProvider.OpenAI,
format: LLMFormat.OpenAICompatible,
flags: [
LLMFlags.hasFullSystemPrompt
LLMFlags.hasFullSystemPrompt,
LLMFlags.hasStreaming
],
parameters: OpenAIParameters,
},
@@ -376,7 +403,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
recommended: true,
parameters: ClaudeParameters,
@@ -390,7 +418,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
recommended: true,
parameters: ClaudeParameters,
@@ -404,7 +433,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
parameters: ClaudeParameters,
},
@@ -417,7 +447,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
parameters: ClaudeParameters,
},
@@ -430,7 +461,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
parameters: ClaudeParameters,
},
@@ -443,7 +475,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
parameters: ClaudeParameters,
},
@@ -456,7 +489,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
parameters: ClaudeParameters,
},
@@ -469,7 +503,8 @@ export const LLMModels: LLMModel[] = [
flags: [
LLMFlags.hasPrefill,
LLMFlags.hasImageInput,
LLMFlags.hasFirstSystemPrompt
LLMFlags.hasFirstSystemPrompt,
LLMFlags.hasStreaming
],
parameters: ClaudeParameters,
},
@@ -593,7 +628,7 @@ export const LLMModels: LLMModel[] = [
id: 'openrouter',
provider: LLMProvider.AsIs,
format: LLMFormat.OpenAICompatible,
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasImageInput],
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasImageInput, LLMFlags.hasStreaming],
parameters: ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k'],
recommended: true
},
@@ -930,7 +965,7 @@ export const LLMModels: LLMModel[] = [
name: "Custom API",
provider: LLMProvider.AsIs,
format: LLMFormat.OpenAICompatible,
flags: [LLMFlags.hasFullSystemPrompt],
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
recommended: true,
parameters: ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k']
}

View File

@@ -1465,9 +1465,8 @@ export async function sendChat(chatProcessIndex = -1,arg:{
formated: promptbody,
bias: emobias,
currentChar: currentChar,
temperature: 0.4,
maxTokens: 30,
}, 'submodel', abortSignal)
}, 'emotion', abortSignal)
if(rq.type === 'fail' || rq.type === 'streaming' || rq.type === 'multiline'){
if(abortSignal.aborted){

View File

@@ -5,6 +5,7 @@ import { requestChatData } from "../request";
import { HypaProcesser } from "./hypamemory";
import { globalFetch } from "src/ts/globalApi.svelte";
import { runSummarizer } from "../transformers";
import { parseChatML } from "src/ts/parser.svelte";
export interface HypaV2Data {
chunks: {
@@ -83,7 +84,10 @@ async function summary(stringlizedChat: string): Promise<{ success: boolean; dat
};
}
} else {
const promptbody: OpenAIChat[] = [
let parsedPrompt = parseChatML(supaPrompt.replaceAll('{{slot}}', stringlizedChat))
const promptbody: OpenAIChat[] = parsedPrompt ?? [
{
role: "user",
content: stringlizedChat
@@ -99,7 +103,7 @@ async function summary(stringlizedChat: string): Promise<{ success: boolean; dat
bias: {},
useStreaming: false,
noMultiGen: true
}, 'submodel');
}, 'memory');
if (da.type === 'fail' || da.type === 'streaming' || da.type === 'multiline') {
return {
success: false,

View File

@@ -7,6 +7,7 @@ import { stringlizeChat } from "../stringlize";
import { globalFetch } from "src/ts/globalApi.svelte";
import { runSummarizer } from "../transformers";
import { getUserName } from "src/ts/util";
import { parseChatML } from "src/ts/parser.svelte";
export async function supaMemory(
chats:OpenAIChat[],
@@ -252,7 +253,8 @@ export async function supaMemory(
}
}
else {
const promptbody:OpenAIChat[] = [
let parsedPrompt = parseChatML(supaPrompt.replaceAll('{{slot}}', stringlizedChat))
const promptbody:OpenAIChat[] = parsedPrompt ?? [
{
role: "user",
content: stringlizedChat
@@ -267,7 +269,7 @@ export async function supaMemory(
bias: {},
useStreaming: false,
noMultiGen: true
}, 'submodel')
}, 'memory')
if(da.type === 'fail' || da.type === 'streaming' || da.type === 'multiline'){
return {
currentTokens: currentTokens,

View File

@@ -1,5 +1,5 @@
import type { MultiModal, OpenAIChat, OpenAIChatFull } from "./index.svelte";
import { getCurrentCharacter, getDatabase, type character } from "../storage/database.svelte";
import { getCurrentCharacter, getDatabase, setDatabase, type character } from "../storage/database.svelte";
import { pluginProcess } from "../plugins/plugins";
import { language } from "../../lang";
import { stringlizeAINChat, getStopStrings, unstringlizeAIN, unstringlizeChat } from "./stringlize";
@@ -47,6 +47,7 @@ interface RequestDataArgumentExtended extends requestDataArgument{
abortSignal?:AbortSignal
modelInfo?:LLMModel
customURL?:string
mode?:ModelModeExtended
}
type requestDataResponse = {
@@ -89,12 +90,31 @@ interface OaiFunctions {
export type Parameter = 'temperature'|'top_k'|'repetition_penalty'|'min_p'|'top_a'|'top_p'|'frequency_penalty'|'presence_penalty'
export type ModelModeExtended = 'model'|'submodel'|'memory'|'emotion'|'otherAx'|'translate'
type ParameterMap = {
[key in Parameter]?: string;
};
function applyParameters(data: { [key: string]: any }, parameters: Parameter[], rename: ParameterMap = {}) {
function applyParameters(data: { [key: string]: any }, parameters: Parameter[], rename: ParameterMap, ModelMode:ModelModeExtended): { [key: string]: any } {
const db = getDatabase()
if(db.seperateParametersEnabled && ModelMode !== 'model'){
if(ModelMode === 'submodel'){
ModelMode = 'otherAx'
}
for(const parameter of parameters){
let value = db.seperateParameters[ModelMode][parameter]
if(value === -1000 || value === undefined){
continue
}
data[rename[parameter] ?? parameter] = value
}
return data
}
for(const parameter of parameters){
let value = 0
switch(parameter){
@@ -141,7 +161,7 @@ function applyParameters(data: { [key: string]: any }, parameters: Parameter[],
return data
}
export async function requestChatData(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
export async function requestChatData(arg:requestDataArgument, model:ModelModeExtended, abortSignal:AbortSignal=null):Promise<requestDataResponse> {
const db = getDatabase()
let trys = 0
while(true){
@@ -240,7 +260,7 @@ function reformater(formated:OpenAIChat[],modelInfo:LLMModel){
}
export async function requestChatDataMain(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
export async function requestChatDataMain(arg:requestDataArgument, model:ModelModeExtended, abortSignal:AbortSignal=null):Promise<requestDataResponse> {
const db = getDatabase()
const targ:RequestDataArgumentExtended = arg
targ.formated = safeStructuredClone(arg.formated)
@@ -255,6 +275,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
targ.multiGen = ((db.genTime > 1 && targ.aiModel.startsWith('gpt') && (!arg.continue)) && (!arg.noMultiGen))
targ.abortSignal = abortSignal
targ.modelInfo = getModelInfo(targ.aiModel)
targ.mode = model
if(targ.aiModel === 'reverse_proxy'){
targ.modelInfo.internalID = db.customProxyRequestModel
targ.modelInfo.format = db.customAPIFormat
@@ -502,7 +523,7 @@ async function requestOpenAI(arg:RequestDataArgumentExtended):Promise<requestDat
top_p: db.top_p,
safe_prompt: false,
max_tokens: arg.maxTokens,
}, ['temperature', 'presence_penalty', 'frequency_penalty'] ),
}, ['temperature', 'presence_penalty', 'frequency_penalty'], {}, arg.mode ),
headers: {
"Authorization": "Bearer " + db.mistralKey,
},
@@ -625,8 +646,11 @@ async function requestOpenAI(arg:RequestDataArgumentExtended):Promise<requestDat
}
}
body = applyParameters(body,
aiModel === 'openrouter' ? ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k'] : ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty']
body = applyParameters(
body,
aiModel === 'openrouter' ? ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k'] : ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty'],
{},
arg.mode
)
if(aiModel === 'reverse_proxy' && db.reverseProxyOobaMode){
@@ -1465,7 +1489,7 @@ async function requestGoogleCloudVertex(arg:RequestDataArgumentExtended):Promise
"maxOutputTokens": maxTokens,
}, ['temperature', 'top_p'], {
'top_p': "topP"
}),
}, arg.mode),
safetySettings: uncensoredCatagory
}
@@ -1523,11 +1547,22 @@ async function requestGoogleCloudVertex(arg:RequestDataArgumentExtended):Promise
const data = await response.json();
return data.access_token;
const token = data.access_token;
const db2 = getDatabase()
db2.vertexAccessToken = token
db2.vertexAccessTokenExpires = Date.now() + 3500 * 1000
setDatabase(db2)
return token;
}
if(arg.modelInfo.format === LLMFormat.VertexAIGemini){
headers['Authorization'] = "Bearer " + generateToken(db.google.clientEmail, db.google.privateKey)
if(db.vertexAccessTokenExpires < Date.now()){
headers['Authorization'] = "Bearer " + generateToken(db.vertexClientEmail, db.vertexPrivateKey)
}
else{
headers['Authorization'] = "Bearer " + db.vertexAccessToken
}
}
const url = arg.customURL ?? (arg.modelInfo.format === LLMFormat.VertexAIGemini ?
@@ -1606,7 +1641,7 @@ async function requestKobold(arg:RequestDataArgumentExtended):Promise<requestDat
'top_a'
], {
'repetition_penalty': 'rep_pen'
}) as KoboldGenerationInputSchema
}, arg.mode) as KoboldGenerationInputSchema
const da = await globalFetch(url.toString(), {
method: "POST",
@@ -1802,7 +1837,7 @@ async function requestCohere(arg:RequestDataArgumentExtended):Promise<requestDat
], {
'top_k': 'k',
'top_p': 'p',
})
}, arg.mode)
if(aiModel !== 'cohere-command-r-03-2024' && aiModel !== 'cohere-command-r-plus-04-2024'){
body.safety_mode = "NONE"
@@ -2091,7 +2126,7 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
system: systemPrompt.trim(),
max_tokens: maxTokens,
stream: useStreaming ?? false
}, ['temperature', 'top_k', 'top_p'])
}, ['temperature', 'top_k', 'top_p'], {}, arg.mode)
if(systemPrompt === ''){
delete body.system

View File

@@ -448,6 +448,17 @@ export function setDatabase(data:Database){
data.customAPIFormat ??= LLMFormat.OpenAICompatible
data.systemContentReplacement ??= `system: {{slot}}`
data.systemRoleReplacement ??= 'user'
data.vertexAccessToken ??= ''
data.vertexAccessTokenExpires ??= 0
data.vertexClientEmail ??= ''
data.vertexPrivateKey ??= ''
data.seperateParametersEnabled ??= false
data.seperateParameters = {
memory: {},
emotion: {},
translate: {},
otherAx: {}
}
changeLanguage(data.language)
setDatabaseLite(data)
}
@@ -724,8 +735,6 @@ export interface Database{
google: {
accessToken: string
projectId: string
privateKey: string
clientEmail: string
}
mistralKey?:string
chainOfThought?:boolean
@@ -825,6 +834,29 @@ export interface Database{
customAPIFormat:LLMFormat
systemContentReplacement:string
systemRoleReplacement:'user'|'assistant'
vertexPrivateKey: string
vertexClientEmail: string
vertexAccessToken: string
vertexAccessTokenExpires: number
seperateParametersEnabled:boolean
seperateParameters:{
memory: SeparateParameters,
emotion: SeparateParameters,
translate: SeparateParameters,
otherAx: SeparateParameters
}
translateBeforeHTMLFormatting:boolean
}
interface SeparateParameters{
temperature?:number
top_k?:number
repetition_penalty?:number
min_p?:number
top_a?:number
top_p?:number
frequency_penalty?:number
presence_penalty?:number
}
export interface customscript{
@@ -1519,6 +1551,7 @@ import type { HypaV2Data } from '../process/memory/hypav2';
import { decodeRPack, encodeRPack } from '../rpack/rpack_bg';
import { DBState, selectedCharID } from '../stores.svelte';
import { LLMFormat } from '../model/modellist';
import type { Parameter } from '../process/request';
export async function downloadPreset(id:number, type:'json'|'risupreset'|'return' = 'json'){
saveCurrentPreset()

View File

@@ -10,12 +10,17 @@ import { selectedCharID } from "../stores.svelte"
import { getModuleRegexScripts } from "../process/modules"
import { getNodetextToSentence, sleep } from "../util"
import { processScriptFull } from "../process/scripts"
import localforage from "localforage"
let cache={
origin: [''],
trans: ['']
}
const LLMCacheStorage = localforage.createInstance({
name: "LLMTranslateCache"
})
let waitTrans = 0
export async function translate(text:string, reverse:boolean) {
@@ -442,10 +447,10 @@ function needSuperChunkedTranslate(){
return getDatabase().translatorType === 'deeplX'
}
let llmCache = new Map<string, string>()
async function translateLLM(text:string, arg:{to:string}){
if(llmCache.has(text)){
return llmCache.get(text)
async function translateLLM(text:string, arg:{to:string}):Promise<string>{
const cacheMatch = await LLMCacheStorage.getItem(text)
if(cacheMatch){
return cacheMatch as string
}
const styleDecodeRegex = /\<risu-style\>(.+?)\<\/risu-style\>/gms
let styleDecodes:string[] = []
@@ -489,7 +494,7 @@ async function translateLLM(text:string, arg:{to:string}){
useStreaming: false,
noMultiGen: true,
maxTokens: db.translatorMaxResponse,
}, 'submodel')
}, 'translate')
if(rq.type === 'fail' || rq.type === 'streaming' || rq.type === 'multiline'){
alertError(`${rq.result}`)
@@ -498,6 +503,6 @@ async function translateLLM(text:string, arg:{to:string}){
const result = rq.result.replace(/<style-data style-index="(\d+)" ?\/?>/g, (match, p1) => {
return styleDecodes[parseInt(p1)] ?? ''
}).replace(/<\/style-data>/g, '')
llmCache.set(text, result)
await LLMCacheStorage.setItem(text, result)
return result
}