diff --git a/public/index.html b/public/index.html index c94bcdbc9..a4554639d 100644 --- a/public/index.html +++ b/public/index.html @@ -2269,6 +2269,9 @@ +
diff --git a/public/script.js b/public/script.js index a160d723b..541887274 100644 --- a/public/script.js +++ b/public/script.js @@ -136,7 +136,7 @@ import { getCharaFilename, } from "./scripts/utils.js"; -import { extension_settings, loadExtensionSettings, runGenerationInterceptors, saveMetadataDebounced } from "./scripts/extensions.js"; +import { extension_settings, getContext, loadExtensionSettings, runGenerationInterceptors, saveMetadataDebounced } from "./scripts/extensions.js"; import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js"; import { tag_map, @@ -147,6 +147,7 @@ import { appendTagToList, createTagMapFromList, renameTagKey, + importTags, } from "./scripts/tags.js"; import { SECRET_KEYS, @@ -6311,9 +6312,18 @@ function importCharacter(file) { if (this_chid != undefined && this_chid != "invalid-safety-id") { oldSelectedChar = characters[this_chid].avatar; } + console.log("importing tags"); + console.log(data); await getCharacters(); select_rm_info(`char_import`, data.file_name, oldSelectedChar); + let cur_context = getContext(); + console.log(cur_context); + //Find index of imported character base + let cur_index = cur_context.characters.findIndex(item => item.avatar === data.file_name + ".png"); + console.log(cur_index); + let imported_char = cur_context.characters[cur_index]; + importTags(imported_char); $("#rm_info_block").transition({ opacity: 1, duration: 1000 }); } }, diff --git a/public/scripts/extensions/auto-tagger/index.js b/public/scripts/extensions/auto-tagger/index.js deleted file mode 100644 index 2717116f4..000000000 --- a/public/scripts/extensions/auto-tagger/index.js +++ /dev/null @@ -1,111 +0,0 @@ -import { getContext } from "../../extensions.js"; -import { applyTagsOnCharacterSelect } from "../../tags.js"; - -// Endpoint for API call -const API_ENDPOINT_SEARCH = "https://api.chub.ai/api/characters/search"; -const API_ENDPOINT_DOWNLOAD = "https://api.chub.ai/api/characters/download"; - -// Function to fetch character data -async function fetchCharacterData(name) { - const response = await fetch(`${API_ENDPOINT_SEARCH}?search=${encodeURIComponent(name)}`); - const data = await response.json(); - return data.nodes.find(node => node.name === name); -} - -async function downloadCharacter(fullPath) { - const response = await fetch(API_ENDPOINT_DOWNLOAD, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - format: "cai", - fullPath: fullPath, - version: "main" - }) - }); - const data = await response.json(); - return data; -} - - -// Function to filter out topics like "ROOT" and "Tavern" -function filterTopics(topics) { - return topics.filter(topic => topic !== "ROOT" && topic !== "Tavern"); -} - -// Function to execute on button click -async function onButtonClick() { - console.log("Comparing characters...") - const characters = getContext().characters; - try { - for (let character of characters) { - const searchedCharacter = await fetchCharacterData(character.name); - if (searchedCharacter) { - const downloadedCharacter = await downloadCharacter(searchedCharacter.fullPath); - - //Check if character.data.description and character.scenerio are in downloadedCharacter.description - const downloadDesc = downloadedCharacter.description.replace("\"", ""); - const isPersonalityMatch = character.personality.includes(downloadedCharacter.title); - console.log(downloadedCharacter.title); - console.log(character.personality); - //const isTaglineMatch = character.tagline === downloadedCharacter.tagline; - ///const isTopicsMatch = JSON.stringify(character.topics.sort()) === JSON.stringify(downloadedCharacter.topics.sort()); - - if (isPersonalityMatch) { - console.log(`Character ${character.name} matches.`); - let tags = filterTopics(searchedCharacter.topics); - applyTagsOnCharacterSelect(character, tags); - - } else { - console.log(`Character ${character.name} does not match.`); - if (!isPersonalityMatch) { - console.log(`- Personality does not match. Generated: ${character.data.description}, API: ${downloadedCharacter.description}`); - console.log(character); - console.log(downloadedCharacter); - console.log(searchedCharacter); - } - // if (!isTaglineMatch) { - // console.log(`- Tagline does not match. Generated: ${character.tagline}, API: ${downloadedCharacter.tagline}`); - // } - // if (!isTopicsMatch) { - // console.log(`- Topics do not match. Generated: ${character.topics.join(", ")}, API: ${downloadedCharacter.topics.join(", ")}`); - // } - } - } else { - console.log(`Character ${character.name} not found.`); - } - } - } catch (error) { - console.error(error); - } -} - -jQuery(() => { - const settingsHtml = ` -
-
-
- auto-tagger -
-
-
- - -
- -
- - - - -
- -
-
-
`; - - // Append settingsHtml to extensions_settings - $('#extensions_settings').append(settingsHtml); - $('#compare-characters').on('click', onButtonClick); -}); diff --git a/public/scripts/extensions/auto-tagger/manifest.json b/public/scripts/extensions/auto-tagger/manifest.json deleted file mode 100644 index f8f5980de..000000000 --- a/public/scripts/extensions/auto-tagger/manifest.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "display_name": "Auto-Tagger", - "loading_order": 9, - "requires": [ - ], - "optional": [], - "js": "index.js", - "css": "style.css", - "author": "BlipRanger", - "version": "1.0.0", - "homePage": "https://github.com/BlipRanger" -} diff --git a/public/scripts/extensions/auto-tagger/style.css b/public/scripts/extensions/auto-tagger/style.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 60a608f01..8d8f6d4f2 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -571,6 +571,7 @@ function loadPowerUserSettings(settings, data) { $(`#tokenizer option[value="${power_user.tokenizer}"]`).attr('selected', true); $(`#pygmalion_formatting option[value=${power_user.pygmalion_formatting}]`).attr("selected", true); $(`#send_on_enter option[value=${power_user.send_on_enter}]`).attr("selected", true); + $("#show_card_tags").prop("checked", power_user.show_card_tags); $("#collapse-newlines-checkbox").prop("checked", power_user.collapse_newlines); $("#pin-examples-checkbox").prop("checked", power_user.pin_examples); $("#disable-description-formatting-checkbox").prop("checked", power_user.disable_description_formatting); @@ -1313,6 +1314,11 @@ $(document).ready(() => { saveSettingsDebounced(); }); + $("#show_card_tags").on('input', function () { + power_user.show_card_tags = !!$(this).prop('checked'); + saveSettingsDebounced(); + }); + $("#render_formulas").on("input", function () { power_user.render_formulas = !!$(this).prop('checked'); reloadMarkdownProcessor(power_user.render_formulas); diff --git a/public/scripts/tags.js b/public/scripts/tags.js index a453c0f1d..25f73896d 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -19,6 +19,7 @@ export { appendTagToList, createTagMapFromList, renameTagKey, + importTags, }; const random_id = () => Math.round(Date.now() * Math.random()).toString(); @@ -201,6 +202,28 @@ function selectTag(event, ui, listSelector) { return false; } +function importTags(imported_char) { + + for (let tagName of imported_char.data.tags) { + let tag = tags.find(t => t.name === tagName); + + // create new tag if it doesn't exist + if (!tag) { + tag = createNewTag(tagName); + } + + // add tag to the UI and internal map + //appendTagToList(listSelector, tag, { removable: true }); + addTagToMap(tag.id); + }; + saveSettingsDebounced(); + printTags(); + + // need to return false to keep the input clear + return false; +} + + function createNewTag(tagName) { const tag = { id: random_id(), @@ -365,6 +388,32 @@ export function applyTagsOnCharacterSelect() { } } +export function applyTagsOnImport() { + //clearTagsFilter(); + const chid = Number($(this).attr('chid')); + const key = characters[chid].avatar; + const tags = getTagsList(key); + + $("#tagList").empty(); + + for (const tag of tags) { + appendTagToList("#tagList", tag, { removable: true }); + } +} + +// export function applyTagsOnCharacterSelect(character, tags) { +// //clearTagsFilter(); +// const chid = character.id; +// const key = characters[chid].avatar; +// const tags = getTagsList(key); + +// $("#tagList").empty(); + +// for (const tag of tags) { +// appendTagToList("#tagList", tag, { removable: true }); +// } +// } + function applyTagsOnGroupSelect() { //clearTagsFilter(); const key = $(this).attr('grid'); diff --git a/server.js b/server.js index dcf6f8dcd..ed8535590 100644 --- a/server.js +++ b/server.js @@ -781,6 +781,7 @@ function readFromV2(char) { mes_example: 'mes_example', talkativeness: 'extensions.talkativeness', fav: 'extensions.fav', + tags: 'tags', }; _.forEach(fieldMappings, (v2Path, charField) => {