mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Unmerge plus first try at importing card tags
This commit is contained in:
@ -2269,6 +2269,9 @@
|
|||||||
<label for="show_card_avatar_urls"><input id="show_card_avatar_urls" type="checkbox" />
|
<label for="show_card_avatar_urls"><input id="show_card_avatar_urls" type="checkbox" />
|
||||||
<span data-i18n="Show avatar filenames">Show avatar filenames</span>
|
<span data-i18n="Show avatar filenames">Show avatar filenames</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label for="show_card_tags"><input id="show_card_tags" type="checkbox" />
|
||||||
|
<span data-i18n="Show Card Tags">Show Card Tags</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="inline-drawer wide100p flexFlowColumn">
|
<div class="inline-drawer wide100p flexFlowColumn">
|
||||||
<div class="inline-drawer-toggle inline-drawer-header">
|
<div class="inline-drawer-toggle inline-drawer-header">
|
||||||
|
@ -136,7 +136,7 @@ import {
|
|||||||
getCharaFilename,
|
getCharaFilename,
|
||||||
} from "./scripts/utils.js";
|
} 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 { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js";
|
||||||
import {
|
import {
|
||||||
tag_map,
|
tag_map,
|
||||||
@ -147,6 +147,7 @@ import {
|
|||||||
appendTagToList,
|
appendTagToList,
|
||||||
createTagMapFromList,
|
createTagMapFromList,
|
||||||
renameTagKey,
|
renameTagKey,
|
||||||
|
importTags,
|
||||||
} from "./scripts/tags.js";
|
} from "./scripts/tags.js";
|
||||||
import {
|
import {
|
||||||
SECRET_KEYS,
|
SECRET_KEYS,
|
||||||
@ -6311,9 +6312,18 @@ function importCharacter(file) {
|
|||||||
if (this_chid != undefined && this_chid != "invalid-safety-id") {
|
if (this_chid != undefined && this_chid != "invalid-safety-id") {
|
||||||
oldSelectedChar = characters[this_chid].avatar;
|
oldSelectedChar = characters[this_chid].avatar;
|
||||||
}
|
}
|
||||||
|
console.log("importing tags");
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
await getCharacters();
|
await getCharacters();
|
||||||
select_rm_info(`char_import`, data.file_name, oldSelectedChar);
|
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 });
|
$("#rm_info_block").transition({ opacity: 1, duration: 1000 });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -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 = `
|
|
||||||
<div class="auto-tagger-settings">
|
|
||||||
<div class="inline-drawer">
|
|
||||||
<div class="inline-drawer-toggle inline-drawer-header">
|
|
||||||
<b>auto-tagger</b>
|
|
||||||
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
|
||||||
</div>
|
|
||||||
<div class="inline-drawer-content">
|
|
||||||
|
|
||||||
|
|
||||||
<div class="auto-tagger_block flex-container">
|
|
||||||
<input id="compare-characters" class="menu_button" type="submit" value="Compare Characters" /> <!-- New button for comparison -->
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- New div for comparison results -->
|
|
||||||
<div id="comparison-results"></div>
|
|
||||||
|
|
||||||
<hr class="sysHR">
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
// Append settingsHtml to extensions_settings
|
|
||||||
$('#extensions_settings').append(settingsHtml);
|
|
||||||
$('#compare-characters').on('click', onButtonClick);
|
|
||||||
});
|
|
@ -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"
|
|
||||||
}
|
|
@ -571,6 +571,7 @@ function loadPowerUserSettings(settings, data) {
|
|||||||
$(`#tokenizer option[value="${power_user.tokenizer}"]`).attr('selected', true);
|
$(`#tokenizer option[value="${power_user.tokenizer}"]`).attr('selected', true);
|
||||||
$(`#pygmalion_formatting option[value=${power_user.pygmalion_formatting}]`).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);
|
$(`#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);
|
$("#collapse-newlines-checkbox").prop("checked", power_user.collapse_newlines);
|
||||||
$("#pin-examples-checkbox").prop("checked", power_user.pin_examples);
|
$("#pin-examples-checkbox").prop("checked", power_user.pin_examples);
|
||||||
$("#disable-description-formatting-checkbox").prop("checked", power_user.disable_description_formatting);
|
$("#disable-description-formatting-checkbox").prop("checked", power_user.disable_description_formatting);
|
||||||
@ -1313,6 +1314,11 @@ $(document).ready(() => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#show_card_tags").on('input', function () {
|
||||||
|
power_user.show_card_tags = !!$(this).prop('checked');
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
$("#render_formulas").on("input", function () {
|
$("#render_formulas").on("input", function () {
|
||||||
power_user.render_formulas = !!$(this).prop('checked');
|
power_user.render_formulas = !!$(this).prop('checked');
|
||||||
reloadMarkdownProcessor(power_user.render_formulas);
|
reloadMarkdownProcessor(power_user.render_formulas);
|
||||||
|
@ -19,6 +19,7 @@ export {
|
|||||||
appendTagToList,
|
appendTagToList,
|
||||||
createTagMapFromList,
|
createTagMapFromList,
|
||||||
renameTagKey,
|
renameTagKey,
|
||||||
|
importTags,
|
||||||
};
|
};
|
||||||
|
|
||||||
const random_id = () => Math.round(Date.now() * Math.random()).toString();
|
const random_id = () => Math.round(Date.now() * Math.random()).toString();
|
||||||
@ -201,6 +202,28 @@ function selectTag(event, ui, listSelector) {
|
|||||||
return false;
|
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) {
|
function createNewTag(tagName) {
|
||||||
const tag = {
|
const tag = {
|
||||||
id: random_id(),
|
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() {
|
function applyTagsOnGroupSelect() {
|
||||||
//clearTagsFilter();
|
//clearTagsFilter();
|
||||||
const key = $(this).attr('grid');
|
const key = $(this).attr('grid');
|
||||||
|
@ -781,6 +781,7 @@ function readFromV2(char) {
|
|||||||
mes_example: 'mes_example',
|
mes_example: 'mes_example',
|
||||||
talkativeness: 'extensions.talkativeness',
|
talkativeness: 'extensions.talkativeness',
|
||||||
fav: 'extensions.fav',
|
fav: 'extensions.fav',
|
||||||
|
tags: 'tags',
|
||||||
};
|
};
|
||||||
|
|
||||||
_.forEach(fieldMappings, (v2Path, charField) => {
|
_.forEach(fieldMappings, (v2Path, charField) => {
|
||||||
|
Reference in New Issue
Block a user