From 85e7becaf69f8fd8b4158fec3894e14efdfba5e2 Mon Sep 17 00:00:00 2001 From: bangonicdd <133192207+bangonicdd@users.noreply.github.com> Date: Sat, 3 Feb 2024 04:30:34 +0900 Subject: [PATCH 1/4] Add gpt-3.5-turbo-0125, fix gpt-4-0314 --- src/lib/UI/ModelList.svelte | 3 ++- src/ts/process/request.ts | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/UI/ModelList.svelte b/src/lib/UI/ModelList.svelte index 38a214db..074e06a1 100644 --- a/src/lib/UI/ModelList.svelte +++ b/src/lib/UI/ModelList.svelte @@ -126,10 +126,11 @@ {#if showUnrec} - + + diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index 3927836e..e138bd00 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -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, From 8bcae0864b7533d5817cc74a52e5aa40fc84c0d7 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Tue, 6 Feb 2024 21:34:02 +0900 Subject: [PATCH 2/4] Fix formatting for Claude --- src/etc/patchNote.ts | 2 +- src/ts/process/request.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/etc/patchNote.ts b/src/etc/patchNote.ts index 79299735..1bba23c7 100644 --- a/src/etc/patchNote.ts +++ b/src/etc/patchNote.ts @@ -15,7 +15,7 @@ export function getPatchNote(version: string){ if(patchNote.version.split(".")[1] === version.split(".")[1] && patchNote.version.split(".")[0] === version.split(".")[0]){ return patchNote } - return { +return { version: version.split(".")[0] + "." + version.split(".")[1], content: "" } diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index 3927836e..598c48b9 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -1423,7 +1423,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 +1437,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 From 68382cb38e6b21fbf8f58cc0b99e6b1a28c13247 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 7 Feb 2024 02:21:16 +0900 Subject: [PATCH 3/4] Add Modules --- src/lang/en.ts | 13 ++ src/lib/ChatScreens/ChatScreen.svelte | 10 +- src/lib/ChatScreens/DefaultChatScreen.svelte | 17 +- .../Pages/Module/ModuleChatMenu.svelte | 77 +++++++++ .../Setting/Pages/Module/ModuleMenu.svelte | 153 ++++++++++++++++++ .../Pages/Module/ModuleSettings.svelte | 109 +++++++++++++ src/lib/Setting/Settings.svelte | 21 ++- src/lib/SideBars/Scripts/RegexList.svelte | 2 +- src/lib/SideBars/Scripts/TriggerList.svelte | 2 +- src/ts/process/lorebook.ts | 5 +- src/ts/process/modules.ts | 120 ++++++++++++++ src/ts/process/scripts.ts | 3 +- src/ts/process/triggers.ts | 3 +- src/ts/storage/database.ts | 6 + src/ts/storage/globalApi.ts | 6 +- 15 files changed, 527 insertions(+), 20 deletions(-) create mode 100644 src/lib/Setting/Pages/Module/ModuleChatMenu.svelte create mode 100644 src/lib/Setting/Pages/Module/ModuleMenu.svelte create mode 100644 src/lib/Setting/Pages/Module/ModuleSettings.svelte create mode 100644 src/ts/process/modules.ts diff --git a/src/lang/en.ts b/src/lang/en.ts index 5975574f..c823c24e 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -515,4 +515,17 @@ export const languageEnglish = { license: "License", licenseDesc: "You can choose license for the downloaders to limit the usages of your card's prompt.", passwordDesc: "You can set a password to protect your card from unauthorized access.", + module: "Module", + modules: "Modules", + noModules: "No modules has been installed.", + createModule: "Create Module", + basicInfo: "Basic Info", + moduleContent: "Module Content", + confirmRemoveModuleFeature: "Do you really want to remove this feature? This action cannot be undone.", + editModule: "Edit Module", + importModule: "Import Module", + download: "Download", + edit: "Edit", + enableGlobal: "Enable Globally", + chatModulesInfo: "You can enable or disable modules for this chat.", } \ No newline at end of file diff --git a/src/lib/ChatScreens/ChatScreen.svelte b/src/lib/ChatScreens/ChatScreen.svelte index 01fe227f..c5500d79 100644 --- a/src/lib/ChatScreens/ChatScreen.svelte +++ b/src/lib/ChatScreens/ChatScreen.svelte @@ -10,7 +10,9 @@ import BackgroundDom from "./BackgroundDom.svelte"; import SideBarArrow from "../UI/GUI/SideBarArrow.svelte"; import VisualNovelMain from "../VisualNovel/VisualNovelMain.svelte"; + import ModuleChatMenu from "../Setting/Pages/Module/ModuleChatMenu.svelte"; let openChatList = false + let openModuleList = false const wallPaper = `background: url(${defaultWallpaper})` const externalStyles = @@ -40,7 +42,7 @@ {/if} {/if} - 2 ? `${externalStyles}`: ''} bind:openChatList/> + 2 ? `${externalStyles}`: ''} bind:openChatList bind:openModuleList/> {:else if $DataBase.theme === 'waifu'} @@ -55,7 +57,7 @@ {/if} {/if}
= 0 && $CurrentCharacter.viewScreen !== 'none'}> - +
{:else if $DataBase.theme === 'waifuMobile'} @@ -66,7 +68,7 @@ class:per33={$selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none'} class:h-full={!($selectedCharID >= 0 && $CurrentCharacter.viewScreen !== 'none')} > - + {#if $selectedCharID >= 0} {#if $CurrentCharacter.viewScreen !== 'none'} @@ -79,6 +81,8 @@ {/if} {#if openChatList} {openChatList = false}}/> +{:else if openModuleList} + {openModuleList = false}}/> {/if} \ No newline at end of file diff --git a/src/lib/Setting/Pages/Module/ModuleMenu.svelte b/src/lib/Setting/Pages/Module/ModuleMenu.svelte new file mode 100644 index 00000000..f3d5e04e --- /dev/null +++ b/src/lib/Setting/Pages/Module/ModuleMenu.svelte @@ -0,0 +1,153 @@ + + +{language.basicInfo} + + +{language.moduleContent} +
+ + + + +
+ +{#if (Array.isArray(currentModule.lorebook))} + {language.loreBook} +
+ {#each currentModule.lorebook as lore, i} + { + currentModule.lorebook.splice(i, 1) + currentModule.lorebook = currentModule.lorebook + }}/> + {/each} +
+ +{/if} + +{#if (Array.isArray(currentModule.regex))} + {language.regexScript} + + +{/if} + +{#if (Array.isArray(currentModule.trigger))} + {language.triggerScript} + + +{/if} \ No newline at end of file diff --git a/src/lib/Setting/Pages/Module/ModuleSettings.svelte b/src/lib/Setting/Pages/Module/ModuleSettings.svelte new file mode 100644 index 00000000..e3275f94 --- /dev/null +++ b/src/lib/Setting/Pages/Module/ModuleSettings.svelte @@ -0,0 +1,109 @@ + +{#if mode === 0} +

{language.modules}

+ +
+ {#if $DataBase.modules.length === 0} +
{language.noModules}
+ {:else} + {#each $DataBase.modules as rmodule, i} + {#if i !== 0} +
+ {/if} + +
+ {rmodule.name} +
+ + + + +
+
+
+ {rmodule.description || 'No description provided'} +
+ {/each} + {/if} +
+ + +{:else if mode === 1} +

{language.createModule}

+ + {#if tempModule.name !== ''} + + {/if} +{:else if mode === 2} +

{language.editModule}

+ + {#if tempModule.name !== ''} + + {/if} +{/if} \ No newline at end of file diff --git a/src/lib/Setting/Settings.svelte b/src/lib/Setting/Settings.svelte index 619aef96..3c4713d9 100644 --- a/src/lib/Setting/Settings.svelte +++ b/src/lib/Setting/Settings.svelte @@ -1,5 +1,5 @@ -
+
{#if value.length === 0}
No Scripts
{/if} diff --git a/src/lib/SideBars/Scripts/TriggerList.svelte b/src/lib/SideBars/Scripts/TriggerList.svelte index 4a82ec09..80382b4b 100644 --- a/src/lib/SideBars/Scripts/TriggerList.svelte +++ b/src/lib/SideBars/Scripts/TriggerList.svelte @@ -7,7 +7,7 @@ -
+
{#if value.length === 0}
No Scripts
{/if} diff --git a/src/ts/process/lorebook.ts b/src/ts/process/lorebook.ts index c1dd272e..08f4c262 100644 --- a/src/ts/process/lorebook.ts +++ b/src/ts/process/lorebook.ts @@ -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() } diff --git a/src/ts/process/modules.ts b/src/ts/process/modules.ts new file mode 100644 index 00000000..23c2d028 --- /dev/null +++ b/src/ts/process/modules.ts @@ -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 { const a = document.createElement('a') a.href = data From ad90121850aba630b349198a8270e1c3970be4a6 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 7 Feb 2024 02:24:30 +0900 Subject: [PATCH 4/4] Remember Settings menu --- .../Pages/Module/ModuleChatMenu.svelte | 5 +- src/lib/Setting/Settings.svelte | 130 +++++++++--------- src/ts/stores.ts | 1 + 3 files changed, 70 insertions(+), 66 deletions(-) diff --git a/src/lib/Setting/Pages/Module/ModuleChatMenu.svelte b/src/lib/Setting/Pages/Module/ModuleChatMenu.svelte index 063eb96b..8b671dda 100644 --- a/src/lib/Setting/Pages/Module/ModuleChatMenu.svelte +++ b/src/lib/Setting/Pages/Module/ModuleChatMenu.svelte @@ -1,9 +1,10 @@ @@ -63,6 +64,8 @@
diff --git a/src/lib/Setting/Settings.svelte b/src/lib/Setting/Settings.svelte index 3c4713d9..1d2578ec 100644 --- a/src/lib/Setting/Settings.svelte +++ b/src/lib/Setting/Settings.svelte @@ -8,7 +8,7 @@ import PluginSettings from "./Pages/PluginSettings.svelte"; import FilesSettings from "./Pages/FilesSettings.svelte"; import AdvancedSettings from "./Pages/AdvancedSettings.svelte"; - import { settingsOpen } from "src/ts/stores"; + import { SettingsMenuIndex, settingsOpen } from "src/ts/stores"; import Botpreset from "./botpreset.svelte"; import Communities from "./Pages/Communities.svelte"; import GlobalLoreBookSettings from "./Pages/GlobalLoreBookSettings.svelte"; @@ -20,133 +20,133 @@ import PromptSettings from "./Pages/PromptSettings.svelte"; import ThanksPage from "./Pages/ThanksPage.svelte"; import ModuleSettings from "./Pages/Module/ModuleSettings.svelte"; - let selected = -1 + let openPresetList = false let openLoreList = false - if(window.innerWidth >= 700 && selected === -1){ - selected = 1 + if(window.innerWidth >= 900 && $SettingsMenuIndex === -1){ + $SettingsMenuIndex = 1 }
- {#if window.innerWidth >= 700 || selected === -1} + {#if window.innerWidth >= 700 || $SettingsMenuIndex === -1}
{/if} - {#if window.innerWidth >= 700 || selected !== -1} - {#key selected} + {#if window.innerWidth >= 700 || $SettingsMenuIndex !== -1} + {#key $SettingsMenuIndex}
- {#if selected === 0} + {#if $SettingsMenuIndex === 0} - {:else if selected === 1} + {:else if $SettingsMenuIndex === 1} { - selected = 13 + $SettingsMenuIndex = 13 }} /> - {:else if selected === 2} + {:else if $SettingsMenuIndex === 2} - {:else if selected === 3} + {:else if $SettingsMenuIndex === 3} - {:else if selected === 4} + {:else if $SettingsMenuIndex === 4} - {:else if selected === 5} + {:else if $SettingsMenuIndex === 5} - {:else if selected === 6} + {:else if $SettingsMenuIndex === 6} - {:else if selected === 7} + {:else if $SettingsMenuIndex === 7} - {:else if selected === 8} + {:else if $SettingsMenuIndex === 8} - {:else if selected === 9} + {:else if $SettingsMenuIndex === 9} - {:else if selected === 10} + {:else if $SettingsMenuIndex === 10} - {:else if selected === 11} + {:else if $SettingsMenuIndex === 11} - {:else if selected === 12} + {:else if $SettingsMenuIndex === 12} - {:else if selected === 14} + {:else if $SettingsMenuIndex === 14} - {:else if selected === 13} + {:else if $SettingsMenuIndex === 13} { - selected = 1 + $SettingsMenuIndex = 1 }}/> - {:else if selected === 77} + {:else if $SettingsMenuIndex === 77} {/if}
@@ -205,7 +205,7 @@ settingsOpen.set(false) } else{ - selected = -1 + $SettingsMenuIndex = -1 } }}> diff --git a/src/ts/stores.ts b/src/ts/stores.ts index d6c5f4f2..126adb2f 100644 --- a/src/ts/stores.ts +++ b/src/ts/stores.ts @@ -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'){