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.",
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.",
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: {
chooseProvider: "Choose AI Provider",
@@ -688,5 +689,7 @@ export const languageEnglish = {
hideApiKeys: "Hide API Keys",
unformatQuotes: "Disable Quote Formatting",
enableDevTools: "Enable Dev Tools",
selectFile: "Select File"
selectFile: "Select File",
namespace: "Namespace",
moduleIntergration: "Module Integration",
}

View File

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

View File

@@ -121,8 +121,12 @@
</div>
{#if submenu === 0}
<TextInput bind:value={currentModule.name} className="mt-1" placeholder={language.name}/>
<TextInput bind:value={currentModule.description} className="mt-1" placeholder={language.description} size="sm"/>
<span>{language.name}</span>
<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">
<Check bind:check={currentModule.hideIcon} name={language.hideChatIcon}/>
</div>

View File

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

View File

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