Add moduleIntergration

This commit is contained in:
kwaroran
2024-09-05 20:44:57 +09:00
parent d58806c978
commit 7d14cf614c
5 changed files with 48 additions and 33 deletions

View File

@@ -135,6 +135,7 @@ export const languageEnglish = {
luaHelp: "You can use Lua scripts as a trigger script. you can define onInput, onOutput, onStart functions. onInput is called when user sends a message, onOutput is called when character sends a message, onStart is called when the chat starts. for more information, see the documentation.", luaHelp: "You can use Lua scripts as a trigger script. you can define onInput, onOutput, onStart functions. onInput is called when user sends a message, onOutput is called when character sends a message, onStart is called when the chat starts. for more information, see the documentation.",
claudeCachingExperimental: "Caching in Claude is experimental feature that can reduce the cost of the model, but it can also increase the cost if you use it without reroll. since this is a experimental feature, it can be unstable and behavior can be changed in the future.", claudeCachingExperimental: "Caching in Claude is experimental feature that can reduce the cost of the model, but it can also increase the cost if you use it without reroll. since this is a experimental feature, it can be unstable and behavior can be changed in the future.",
urllora: "You can use direct download link of the model file. you can make direct url from google drive like website like https://sites.google.com/site/gdocs2direct/ , or use civitai URL, copy the the AIR (looks like `urn:air:flux1:lora:civitai:180891@776656` or just `civitai:180891@776656`) and paste it.", urllora: "You can use direct download link of the model file. you can make direct url from google drive like website like https://sites.google.com/site/gdocs2direct/ , or use civitai URL, copy the the AIR (looks like `urn:air:flux1:lora:civitai:180891@776656` or just `civitai:180891@776656`) and paste it.",
namespace: "Namespace is a unique identifier for the module. it is used to prevent conflicts between modules, and for interaction of presets, other modules and etc. if you are not sure what to put, leave it blank.",
}, },
setup: { setup: {
chooseProvider: "Choose AI Provider", chooseProvider: "Choose AI Provider",
@@ -688,5 +689,7 @@ export const languageEnglish = {
hideApiKeys: "Hide API Keys", hideApiKeys: "Hide API Keys",
unformatQuotes: "Disable Quote Formatting", unformatQuotes: "Disable Quote Formatting",
enableDevTools: "Enable Dev Tools", enableDevTools: "Enable Dev Tools",
selectFile: "Select File" selectFile: "Select File",
namespace: "Namespace",
moduleIntergration: "Module Integration",
} }

View File

@@ -563,6 +563,9 @@
}}/> }}/>
{/if} {/if}
</Arcodion> </Arcodion>
<Arcodion name={language.moduleIntergration}>
<TextAreaInput bind:value={$DataBase.moduleIntergration} fullwidth height={"32"} autocomplete="off"/>
</Arcodion>
{#if submenu !== -1} {#if submenu !== -1}
<Button on:click={() => {$openPresetList = true}} className="mt-4">{language.presets}</Button> <Button on:click={() => {$openPresetList = true}} className="mt-4">{language.presets}</Button>
{/if} {/if}

View File

@@ -121,8 +121,12 @@
</div> </div>
{#if submenu === 0} {#if submenu === 0}
<TextInput bind:value={currentModule.name} className="mt-1" placeholder={language.name}/> <span>{language.name}</span>
<TextInput bind:value={currentModule.description} className="mt-1" placeholder={language.description} size="sm"/> <TextInput bind:value={currentModule.name} className="mt-1"/>
<span class="mt-4">{language.description}</span>
<TextInput bind:value={currentModule.description} className="mt-1" size="sm"/>
<span class="mt-4">{language.namespace} <Help key="namespace" /></span>
<TextInput bind:value={currentModule.namespace} className="mt-1" size="sm"/>
<div class="flex items-center mt-4"> <div class="flex items-center mt-4">
<Check bind:check={currentModule.hideIcon} name={language.hideChatIcon}/> <Check bind:check={currentModule.hideIcon} name={language.hideChatIcon}/>
</div> </div>

View File

@@ -24,6 +24,7 @@ export interface RisuModule{
hideIcon?: boolean hideIcon?: boolean
backgroundEmbedding?:string backgroundEmbedding?:string
assets?:[string,string,string][] assets?:[string,string,string][]
namespace?:string
} }
export async function exportModule(module:RisuModule){ export async function exportModule(module:RisuModule){
@@ -242,19 +243,39 @@ function getModuleById(id:string){
return null return null
} }
function getModuleByIds(ids:string[]){
let modules:RisuModule[] = []
const db = get(DataBase)
for(let i=0;i<db.modules.length;i++){
if(ids.includes(db.modules[i].id)){
modules.push(db.modules[i])
}
if(db.modules[i].namespace && ids.includes(db.modules[i].namespace)){
modules.push(db.modules[i])
}
}
return modules
}
let lastModules = '' let lastModules = ''
let lastModuleData:RisuModule[] = [] let lastModuleData:RisuModule[] = []
export function getModules(ids:string[]){ export function getModules(){
const currentChat = get(CurrentChat)
const db = get(DataBase)
let ids = db.enabledModules ?? []
if (currentChat){
ids = ids.concat(currentChat.modules ?? [])
}
if(db.moduleIntergration){
const intList = db.moduleIntergration.split(',').map((s) => s.trim())
ids = ids.concat(intList)
}
const idsJoined = ids.join('-') const idsJoined = ids.join('-')
if(lastModules === idsJoined){ if(lastModules === idsJoined){
return lastModuleData return lastModuleData
} }
let modules:RisuModule[] = [] let modules:RisuModule[] = getModuleByIds(ids)
for(const id of ids){
const module = getModuleById(id)
modules.push(module)
}
lastModules = idsJoined lastModules = idsJoined
lastModuleData = modules lastModuleData = modules
return modules return modules
@@ -263,12 +284,7 @@ export function getModules(ids:string[]){
export function getModuleLorebooks() { export function getModuleLorebooks() {
const currentChat = get(CurrentChat) const modules = getModules()
const db = get(DataBase)
if (!currentChat) return []
let moduleIds = currentChat.modules ?? []
moduleIds = moduleIds.concat(db.enabledModules)
const modules = getModules(moduleIds)
let lorebooks: loreBook[] = [] let lorebooks: loreBook[] = []
for (const module of modules) { for (const module of modules) {
if(!module){ if(!module){
@@ -282,12 +298,7 @@ export function getModuleLorebooks() {
} }
export function getModuleAssets() { export function getModuleAssets() {
const currentChat = get(CurrentChat) const modules = getModules()
const db = get(DataBase)
if (!currentChat) return []
let moduleIds = currentChat.modules ?? []
moduleIds = moduleIds.concat(db.enabledModules)
const modules = getModules(moduleIds)
let assets: [string,string,string][] = [] let assets: [string,string,string][] = []
for (const module of modules) { for (const module of modules) {
if(!module){ if(!module){
@@ -302,12 +313,7 @@ export function getModuleAssets() {
export function getModuleTriggers() { export function getModuleTriggers() {
const currentChat = get(CurrentChat) const modules = getModules()
const db = get(DataBase)
if (!currentChat) return []
let moduleIds = currentChat.modules ?? []
moduleIds = moduleIds.concat(db.enabledModules)
const modules = getModules(moduleIds)
let triggers: triggerscript[] = [] let triggers: triggerscript[] = []
for (const module of modules) { for (const module of modules) {
if(!module){ if(!module){
@@ -324,12 +330,7 @@ export function getModuleTriggers() {
} }
export function getModuleRegexScripts() { export function getModuleRegexScripts() {
const currentChat = get(CurrentChat) const modules = getModules()
const db = get(DataBase)
if (!currentChat) return []
let moduleIds = currentChat.modules ?? []
moduleIds = moduleIds.concat(db.enabledModules)
const modules = getModules(moduleIds)
let customscripts: customscript[] = [] let customscripts: customscript[] = []
for (const module of modules) { for (const module of modules) {
if(!module){ if(!module){

View File

@@ -725,6 +725,7 @@ export interface Database{
falLora: string falLora: string
falLoraName: string falLoraName: string
falLoraScale: number falLoraScale: number
moduleIntergration: string
} }
export interface customscript{ export interface customscript{
@@ -975,6 +976,7 @@ export interface botPreset{
useInstructPrompt?:boolean useInstructPrompt?:boolean
customPromptTemplateToggle?:string customPromptTemplateToggle?:string
templateDefaultVariables?:string templateDefaultVariables?:string
moduleIntergration?:string
} }
@@ -1254,6 +1256,7 @@ export function saveCurrentPreset(){
useInstructPrompt: db.useInstructPrompt, useInstructPrompt: db.useInstructPrompt,
customPromptTemplateToggle: db.customPromptTemplateToggle ?? "", customPromptTemplateToggle: db.customPromptTemplateToggle ?? "",
templateDefaultVariables: db.templateDefaultVariables ?? "", templateDefaultVariables: db.templateDefaultVariables ?? "",
moduleIntergration: db.moduleIntergration ?? "",
} }
db.botPresets = pres db.botPresets = pres
setDatabase(db) setDatabase(db)
@@ -1338,6 +1341,7 @@ export function setPreset(db:Database, newPres: botPreset){
db.useInstructPrompt = newPres.useInstructPrompt ?? false db.useInstructPrompt = newPres.useInstructPrompt ?? false
db.customPromptTemplateToggle = newPres.customPromptTemplateToggle ?? '' db.customPromptTemplateToggle = newPres.customPromptTemplateToggle ?? ''
db.templateDefaultVariables = newPres.templateDefaultVariables ?? '' db.templateDefaultVariables = newPres.templateDefaultVariables ?? ''
db.moduleIntergration = newPres.moduleIntergration ?? ''
return db return db
} }