diff --git a/javascript/__globals.js b/javascript/__globals.js index 347ca23..166744b 100644 --- a/javascript/__globals.js +++ b/javascript/__globals.js @@ -14,6 +14,7 @@ var embeddings = []; var hypernetworks = []; var loras = []; var lycos = []; +var chants = []; // Selected model info for black/whitelisting var currentModelHash = ""; diff --git a/javascript/ext_chants.js b/javascript/ext_chants.js new file mode 100644 index 0000000..d864db3 --- /dev/null +++ b/javascript/ext_chants.js @@ -0,0 +1,50 @@ +const CHANT_REGEX = /%(?!c:)[^,> ]*>?/gg; +const CHANT_TRIGGER = () => TAC_CFG.useChants && tagword.match(CHANT_REGEX); + +class ChantParser extends BaseTagParser { + parse() { + // Show Chant + let tempResults = []; + if (tagword !== "%" && tagword !== "%c:") { + let searchTerm = tagword.replace("%c:", "").replace("%", ""); + let filterCondition = x => x.term.toLowerCase().includes(searchTerm); + tempResults = loras.filter(x => filterCondition(x)); // Filter by tagword + } else { + tempResults = chants; + } + + // Add final results + let finalResults = []; + tempResults.forEach(t => { + let result = new AutocompleteResult(t.content.trim(), ResultType.json) + result.meta = t.name; + finalResults.push(result); + }); + + return finalResults; + } +} + +async function load() { + if (chants.length === 0) { + try { + chants = await readFile(`${tagBasePath}/chants.json`, true); + } catch (e) { + console.error("Error loading chants.txt: " + e); + } + } +} + +function sanitize(tagType, text) { + if (tagType === ResultType.chant) { + let selected = chants.find(x => x.content === text); + return `%c:${selected.term}:${TAC_CFG.extraNetworksDefaultMultiplier}>`; + } + return null; +} + +PARSERS.push(new ChantParser(CHANT_TRIGGER)); + +// Add our utility functions to their respective queues +QUEUE_FILE_LOAD.push(load); +QUEUE_SANITIZE.push(sanitize); \ No newline at end of file diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index c3bae3b..fef2d64 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -145,6 +145,7 @@ async function syncOptions() { useEmbeddings: opts["tac_useEmbeddings"], useHypernetworks: opts["tac_useHypernetworks"], useLoras: opts["tac_useLoras"], + useChants: opts["tac_useChants"], useLycos: opts["tac_useLycos"], showWikiLinks: opts["tac_showWikiLinks"], // Insertion related settings diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index a9d274f..8abd630 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -287,6 +287,7 @@ def on_ui_settings(): shared.opts.add_option("tac_showAllResults", shared.OptionInfo(False, "Show all results", section=TAC_SECTION)) shared.opts.add_option("tac_resultStepLength", shared.OptionInfo(100, "How many results to load at once", section=TAC_SECTION)) shared.opts.add_option("tac_delayTime", shared.OptionInfo(100, "Time in ms to wait before triggering completion again (Requires restart)", section=TAC_SECTION)) + shared.opts.add_option("tac_useChants", shared.OptionInfo(True, "Search for Chants", section=TAC_SECTION)) shared.opts.add_option("tac_useWildcards", shared.OptionInfo(True, "Search for wildcards", section=TAC_SECTION)) shared.opts.add_option("tac_useEmbeddings", shared.OptionInfo(True, "Search for embeddings", section=TAC_SECTION)) shared.opts.add_option("tac_useHypernetworks", shared.OptionInfo(True, "Search for hypernetworks", section=TAC_SECTION)) diff --git a/tags/chants.json b/tags/chants.json new file mode 100644 index 0000000..d9e2f9e --- /dev/null +++ b/tags/chants.json @@ -0,0 +1,8 @@ +[ + { + "name": "大绚丽术", + "terms": "大绚丽术", + "content": "bloom, shine", + "color": 1 + } +] \ No newline at end of file