Merge branch 'staging' into wi-regex-keys

This commit is contained in:
Cohee 2024-05-16 22:18:32 +03:00
commit 2eaabe13e3
9 changed files with 112 additions and 22 deletions

View File

@ -193,7 +193,8 @@
filter: brightness(75%) saturate(0.6); filter: brightness(75%) saturate(0.6);
} }
.tag_as_folder:hover { .tag_as_folder:hover,
.tag_as_folder.flash {
filter: brightness(150%) saturate(0.6) !important; filter: brightness(150%) saturate(0.6) !important;
} }

View File

@ -191,7 +191,7 @@ import { NOTE_MODULE_NAME, initAuthorsNote, metadata_keys, setFloatingPrompt, sh
import { registerPromptManagerMigration } from './scripts/PromptManager.js'; import { registerPromptManagerMigration } from './scripts/PromptManager.js';
import { getRegexedString, regex_placement } from './scripts/extensions/regex/engine.js'; import { getRegexedString, regex_placement } from './scripts/extensions/regex/engine.js';
import { initLogprobs, saveLogprobsForActiveMessage } from './scripts/logprobs.js'; import { initLogprobs, saveLogprobsForActiveMessage } from './scripts/logprobs.js';
import { FILTER_TYPES, FilterHelper } from './scripts/filters.js'; import { FILTER_STATES, FILTER_TYPES, FilterHelper, isFilterState } from './scripts/filters.js';
import { getCfgPrompt, getGuidanceScale, initCfg } from './scripts/cfg-scale.js'; import { getCfgPrompt, getGuidanceScale, initCfg } from './scripts/cfg-scale.js';
import { import {
force_output_sequence, force_output_sequence,
@ -1387,7 +1387,7 @@ function verifyCharactersSearchSortRule() {
* @typedef {object} Entity - Object representing a display entity * @typedef {object} Entity - Object representing a display entity
* @property {Character|Group|import('./scripts/tags.js').Tag|*} item - The item * @property {Character|Group|import('./scripts/tags.js').Tag|*} item - The item
* @property {string|number} id - The id * @property {string|number} id - The id
* @property {string} type - The type of this entity (character, group, tag) * @property {'character'|'group'|'tag'} type - The type of this entity (character, group, tag)
* @property {Entity[]} [entities] - An optional list of entities relevant for this item * @property {Entity[]} [entities] - An optional list of entities relevant for this item
* @property {number} [hidden] - An optional number representing how many hidden entities this entity contains * @property {number} [hidden] - An optional number representing how many hidden entities this entity contains
*/ */
@ -1462,7 +1462,11 @@ export function getEntitiesList({ doFilter = false, doSort = true } = {}) {
const subCount = subEntities.length; const subCount = subEntities.length;
subEntities = filterByTagState(entities, { subForEntity: entity }); subEntities = filterByTagState(entities, { subForEntity: entity });
if (doFilter) { if (doFilter) {
subEntities = entitiesFilter.applyFilters(subEntities, { clearScoreCache: false }); // sub entities filter "hacked" because folder filter should not be applied there, so even in "only folders" mode characters show up
subEntities = entitiesFilter.applyFilters(subEntities, { clearScoreCache: false, tempOverrides: { [FILTER_TYPES.FOLDER]: FILTER_STATES.UNDEFINED } });
}
if (doSort) {
sortEntitiesList(subEntities);
} }
entity.entities = subEntities; entity.entities = subEntities;
entity.hidden = subCount - subEntities.length; entity.hidden = subCount - subEntities.length;
@ -1471,8 +1475,13 @@ export function getEntitiesList({ doFilter = false, doSort = true } = {}) {
// Second run filters, hiding whatever should be filtered later // Second run filters, hiding whatever should be filtered later
if (doFilter) { if (doFilter) {
entities = filterByTagState(entities, { globalDisplayFilters: true }); const beforeFinalEntities = filterByTagState(entities, { globalDisplayFilters: true });
entities = entitiesFilter.applyFilters(entities); entities = entitiesFilter.applyFilters(beforeFinalEntities);
// Magic for folder filter. If that one is enabled, and no folders are display anymore, we remove that filter to actually show the characters.
if (isFilterState(entitiesFilter.getFilterData(FILTER_TYPES.FOLDER), FILTER_STATES.SELECTED) && entities.filter(x => x.type == 'tag').length == 0) {
entities = entitiesFilter.applyFilters(beforeFinalEntities, { tempOverrides: { [FILTER_TYPES.FOLDER]: FILTER_STATES.UNDEFINED } });
}
} }
if (doSort) { if (doSort) {
@ -1524,6 +1533,18 @@ function getCharacterSource(chId = this_chid) {
return `https://pygmalion.chat/${pygmalionId}`; return `https://pygmalion.chat/${pygmalionId}`;
} }
const githubRepo = characters[chId]?.data?.extensions?.github_repo;
if (githubRepo) {
return `https://github.com/${githubRepo}`;
}
const sourceUrl = characters[chId]?.data?.extensions?.source_url;
if (sourceUrl) {
return sourceUrl;
}
return ''; return '';
} }

View File

@ -70,6 +70,8 @@
* @property {"system" | "user" | "assistant"} depth_prompt.role - The role the character takes on during the prompted interaction (system, user, or assistant). * @property {"system" | "user" | "assistant"} depth_prompt.role - The role the character takes on during the prompted interaction (system, user, or assistant).
* // Non-standard extensions added by external tools * // Non-standard extensions added by external tools
* @property {string} [pygmalion_id] - The unique identifier assigned to the character by the Pygmalion.chat. * @property {string} [pygmalion_id] - The unique identifier assigned to the character by the Pygmalion.chat.
* @property {string} [github_repo] - The gitHub repository associated with the character.
* @property {string} [source_url] - The source URL associated with the character.
* @property {{full_path: string}} [chub] - The Chub-specific data associated with the character. * @property {{full_path: string}} [chub] - The Chub-specific data associated with the character.
*/ */

View File

@ -261,6 +261,7 @@ async function playAudioData(audioJob) {
audioElement.addEventListener('ended', completeCurrentAudioJob); audioElement.addEventListener('ended', completeCurrentAudioJob);
audioElement.addEventListener('canplay', () => { audioElement.addEventListener('canplay', () => {
console.debug('Starting TTS playback'); console.debug('Starting TTS playback');
audioElement.playbackRate = extension_settings.tts.playback_rate;
audioElement.play(); audioElement.play();
}); });
} }
@ -529,6 +530,10 @@ function loadSettings() {
$('#tts_pass_asterisks').prop('checked', extension_settings.tts.pass_asterisks); $('#tts_pass_asterisks').prop('checked', extension_settings.tts.pass_asterisks);
$('#tts_skip_codeblocks').prop('checked', extension_settings.tts.skip_codeblocks); $('#tts_skip_codeblocks').prop('checked', extension_settings.tts.skip_codeblocks);
$('#tts_skip_tags').prop('checked', extension_settings.tts.skip_tags); $('#tts_skip_tags').prop('checked', extension_settings.tts.skip_tags);
$('#playback_rate').val(extension_settings.tts.playback_rate);
$('#playback_rate_counter').val(Number(extension_settings.tts.playback_rate).toFixed(2));
$('#playback_rate_block').toggle(extension_settings.tts.currentProvider !== 'System');
$('body').toggleClass('tts', extension_settings.tts.enabled); $('body').toggleClass('tts', extension_settings.tts.enabled);
} }
@ -538,6 +543,7 @@ const defaultSettings = {
currentProvider: 'ElevenLabs', currentProvider: 'ElevenLabs',
auto_generation: true, auto_generation: true,
narrate_user: false, narrate_user: false,
playback_rate: 1,
}; };
function setTtsStatus(status, success) { function setTtsStatus(status, success) {
@ -649,6 +655,7 @@ async function loadTtsProvider(provider) {
function onTtsProviderChange() { function onTtsProviderChange() {
const ttsProviderSelection = $('#tts_provider').val(); const ttsProviderSelection = $('#tts_provider').val();
extension_settings.tts.currentProvider = ttsProviderSelection; extension_settings.tts.currentProvider = ttsProviderSelection;
$('#playback_rate_block').toggle(extension_settings.tts.currentProvider !== 'System');
loadTtsProvider(ttsProviderSelection); loadTtsProvider(ttsProviderSelection);
} }
@ -1022,6 +1029,20 @@ $(document).ready(function () {
<small>Pass Asterisks to TTS Engine</small> <small>Pass Asterisks to TTS Engine</small>
</label> </label>
</div> </div>
<div id="playback_rate_block" class="range-block">
<hr>
<div class="range-block-title justifyLeft" data-i18n="Audio Playback Speed">
<small>Audio Playback Speed</small>
</div>
<div class="range-block-range-and-counter">
<div class="range-block-range">
<input type="range" id="playback_rate" name="volume" min="0" max="3" step="0.05">
</div>
<div class="range-block-counter">
<input type="number" min="0" max="3" step="0.05" data-for="playback_rate" id="playback_rate_counter">
</div>
</div>
</div>
<div id="tts_voicemap_block"> <div id="tts_voicemap_block">
</div> </div>
<hr> <hr>
@ -1046,6 +1067,15 @@ $(document).ready(function () {
$('#tts_pass_asterisks').on('click', onPassAsterisksClick); $('#tts_pass_asterisks').on('click', onPassAsterisksClick);
$('#tts_auto_generation').on('click', onAutoGenerationClick); $('#tts_auto_generation').on('click', onAutoGenerationClick);
$('#tts_narrate_user').on('click', onNarrateUserClick); $('#tts_narrate_user').on('click', onNarrateUserClick);
$('#playback_rate').on('input', function () {
const value = $(this).val();
const formattedValue = Number(value).toFixed(2);
extension_settings.tts.playback_rate = value;
$('#playback_rate_counter').val(formattedValue);
saveSettingsDebounced();
});
$('#tts_voices').on('click', onTtsVoicesClick); $('#tts_voices').on('click', onTtsVoicesClick);
for (const provider in ttsProviders) { for (const provider in ttsProviders) {
$('#tts_provider').append($('<option />').val(provider).text(provider)); $('#tts_provider').append($('<option />').val(provider).text(provider));

View File

@ -258,9 +258,8 @@ export class FilterHelper {
*/ */
folderFilter(data) { folderFilter(data) {
const state = this.filterData[FILTER_TYPES.FOLDER]; const state = this.filterData[FILTER_TYPES.FOLDER];
// Slightly different than the other filters, as a positive folder filter means it doesn't filter anything (folders get "not hidden" at another place), // Filter directly on folder. Special rules on still displaying characters with active folder filter are implemented in 'getEntitiesList' directly.
// while a negative state should then filter out all folders. const isFolder = entity => entity.type === 'tag';
const isFolder = entity => isFilterState(state, FILTER_STATES.SELECTED) ? true : entity.type === 'tag';
return this.filterDataByState(data, state, isFolder); return this.filterDataByState(data, state, isFolder);
} }
@ -342,15 +341,40 @@ export class FilterHelper {
* Applies all filters to the given data. * Applies all filters to the given data.
* @param {any[]} data - The data to filter. * @param {any[]} data - The data to filter.
* @param {object} options - Optional call parameters * @param {object} options - Optional call parameters
* @param {boolean|FilterType} [options.clearScoreCache=true] - Whether the score * @param {boolean} [options.clearScoreCache=true] - Whether the score cache should be cleared.
* @param {Object.<FilterType, any>} [options.tempOverrides={}] - Temporarily override specific filters for this filter application
* @returns {any[]} The filtered data. * @returns {any[]} The filtered data.
*/ */
applyFilters(data, { clearScoreCache = true } = {}) { applyFilters(data, { clearScoreCache = true, tempOverrides = {} } = {}) {
if (clearScoreCache) this.clearScoreCache(); if (clearScoreCache) this.clearScoreCache();
return Object.values(this.filterFunctions)
.reduce((data, fn) => fn(data), data); // Save original filter states
const originalStates = {};
for (const key in tempOverrides) {
originalStates[key] = this.filterData[key];
this.filterData[key] = tempOverrides[key];
}
try {
const result = Object.values(this.filterFunctions)
.reduce((data, fn) => fn(data), data);
// Restore original filter states
for (const key in originalStates) {
this.filterData[key] = originalStates[key];
}
return result;
} catch (error) {
// Restore original filter states in case of an error
for (const key in originalStates) {
this.filterData[key] = originalStates[key];
}
throw error;
}
} }
/** /**
* Cache scores for a specific filter type * Cache scores for a specific filter type
* @param {FilterType} type - The type of data being cached * @param {FilterType} type - The type of data being cached

View File

@ -637,7 +637,7 @@ function isValidImageUrl(url) {
if (Object.keys(url).length === 0) { if (Object.keys(url).length === 0) {
return false; return false;
} }
return isDataURL(url) || (url && url.startsWith('user')); return isDataURL(url) || (url && (url.startsWith('user') || url.startsWith('/user')));
} }
function getGroupAvatar(group) { function getGroupAvatar(group) {
@ -1418,6 +1418,10 @@ function select_group_chats(groupId, skipAnimation) {
* @returns {Promise<void>} - A promise that resolves when the processing and upload is complete. * @returns {Promise<void>} - A promise that resolves when the processing and upload is complete.
*/ */
async function uploadGroupAvatar(event) { async function uploadGroupAvatar(event) {
if (!(event.target instanceof HTMLInputElement) || !event.target.files.length) {
return;
}
const file = event.target.files[0]; const file = event.target.files[0];
if (!file) { if (!file) {

View File

@ -17,6 +17,7 @@ import { FILTER_TYPES, FILTER_STATES, DEFAULT_FILTER_STATE, isFilterState, Filte
import { groupCandidatesFilter, groups, selected_group } from './group-chats.js'; import { groupCandidatesFilter, groups, selected_group } from './group-chats.js';
import { download, onlyUnique, parseJsonFile, uuidv4, getSortableDelay, flashHighlight } from './utils.js'; import { download, onlyUnique, parseJsonFile, uuidv4, getSortableDelay, flashHighlight } from './utils.js';
import { power_user } from './power-user.js'; import { power_user } from './power-user.js';
import { debounce_timeout } from './constants.js';
export { export {
TAG_FOLDER_TYPES, TAG_FOLDER_TYPES,
@ -63,7 +64,7 @@ export const tag_filter_types = {
const ACTIONABLE_TAGS = { const ACTIONABLE_TAGS = {
FAV: { id: '1', sort_order: 1, name: 'Show only favorites', color: 'rgba(255, 255, 0, 0.5)', action: filterByFav, icon: 'fa-solid fa-star', class: 'filterByFavorites' }, FAV: { id: '1', sort_order: 1, name: 'Show only favorites', color: 'rgba(255, 255, 0, 0.5)', action: filterByFav, icon: 'fa-solid fa-star', class: 'filterByFavorites' },
GROUP: { id: '0', sort_order: 2, name: 'Show only groups', color: 'rgba(100, 100, 100, 0.5)', action: filterByGroups, icon: 'fa-solid fa-users', class: 'filterByGroups' }, GROUP: { id: '0', sort_order: 2, name: 'Show only groups', color: 'rgba(100, 100, 100, 0.5)', action: filterByGroups, icon: 'fa-solid fa-users', class: 'filterByGroups' },
FOLDER: { id: '4', sort_order: 3, name: 'Always show folders', color: 'rgba(120, 120, 120, 0.5)', action: filterByFolder, icon: 'fa-solid fa-folder-plus', class: 'filterByFolder' }, FOLDER: { id: '4', sort_order: 3, name: 'Show only folders', color: 'rgba(120, 120, 120, 0.5)', action: filterByFolder, icon: 'fa-solid fa-folder-plus', class: 'filterByFolder' },
VIEW: { id: '2', sort_order: 4, name: 'Manage tags', color: 'rgba(150, 100, 100, 0.5)', action: onViewTagsListClick, icon: 'fa-solid fa-gear', class: 'manageTags' }, VIEW: { id: '2', sort_order: 4, name: 'Manage tags', color: 'rgba(150, 100, 100, 0.5)', action: onViewTagsListClick, icon: 'fa-solid fa-gear', class: 'manageTags' },
HINT: { id: '3', sort_order: 5, name: 'Show Tag List', color: 'rgba(150, 100, 100, 0.5)', action: onTagListHintClick, icon: 'fa-solid fa-tags', class: 'showTagList' }, HINT: { id: '3', sort_order: 5, name: 'Show Tag List', color: 'rgba(150, 100, 100, 0.5)', action: onTagListHintClick, icon: 'fa-solid fa-tags', class: 'showTagList' },
UNFILTER: { id: '5', sort_order: 6, name: 'Clear all filters', action: onClearAllFiltersClick, icon: 'fa-solid fa-filter-circle-xmark', class: 'clearAllFilters' }, UNFILTER: { id: '5', sort_order: 6, name: 'Clear all filters', action: onClearAllFiltersClick, icon: 'fa-solid fa-filter-circle-xmark', class: 'clearAllFilters' },
@ -174,9 +175,8 @@ function filterByTagState(entities, { globalDisplayFilters = false, subForEntity
} }
// Hide folders that have 0 visible sub entities after the first filtering round // Hide folders that have 0 visible sub entities after the first filtering round
const alwaysFolder = isFilterState(entitiesFilter.getFilterData(FILTER_TYPES.FOLDER), FILTER_STATES.SELECTED);
if (entity.type === 'tag') { if (entity.type === 'tag') {
return alwaysFolder || entity.entities.length > 0; return entity.entities.length > 0;
} }
return true; return true;
@ -322,6 +322,13 @@ function filterByGroups(filterHelper) {
* @param {FilterHelper} filterHelper Instance of FilterHelper class. * @param {FilterHelper} filterHelper Instance of FilterHelper class.
*/ */
function filterByFolder(filterHelper) { function filterByFolder(filterHelper) {
if (!power_user.bogus_folders) {
$('#bogus_folders').prop('checked', true).trigger('input');
onViewTagsListClick();
flashHighlight($('#dialogue_popup .tag_as_folder, #dialogue_popup .tag_folder_indicator'));
return;
}
const state = toggleTagThreeState($(this)); const state = toggleTagThreeState($(this));
ACTIONABLE_TAGS.FOLDER.filter_state = state; ACTIONABLE_TAGS.FOLDER.filter_state = state;
filterHelper.setFilterData(FILTER_TYPES.FOLDER, state); filterHelper.setFilterData(FILTER_TYPES.FOLDER, state);
@ -883,8 +890,9 @@ function printTagFilters(type = tag_filter_types.character) {
const FILTER_SELECTOR = type === tag_filter_types.character ? CHARACTER_FILTER_SELECTOR : GROUP_FILTER_SELECTOR; const FILTER_SELECTOR = type === tag_filter_types.character ? CHARACTER_FILTER_SELECTOR : GROUP_FILTER_SELECTOR;
$(FILTER_SELECTOR).empty(); $(FILTER_SELECTOR).empty();
// Print all action tags. (Exclude folder if that setting isn't chosen) // Print all action tags. (Rework 'Folder' button to some kind of onboarding if no folders are enabled yet)
const actionTags = Object.values(ACTIONABLE_TAGS).filter(tag => power_user.bogus_folders || tag.id != ACTIONABLE_TAGS.FOLDER.id); const actionTags = Object.values(ACTIONABLE_TAGS);
actionTags.find(x => x == ACTIONABLE_TAGS.FOLDER).name = power_user.bogus_folders ? 'Show only folders' : 'Enable \'Tags as Folder\'\n\nAllows characters to be grouped in folders by their assigned tags.\nTags have to be explicitly chosen as folder to show up.\n\nClick here to start';
printTagList($(FILTER_SELECTOR), { empty: false, sort: false, tags: actionTags, tagActionSelector: tag => tag.action, tagOptions: { isGeneralList: true } }); printTagList($(FILTER_SELECTOR), { empty: false, sort: false, tags: actionTags, tagActionSelector: tag => tag.action, tagOptions: { isGeneralList: true } });
const inListActionTags = Object.values(InListActionable); const inListActionTags = Object.values(InListActionable);

View File

@ -2814,7 +2814,7 @@ grammarly-extension {
#result_info_text { #result_info_text {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
line-height: 1; line-height: 0.9;
text-align: right; text-align: right;
} }

View File

@ -351,7 +351,7 @@ function parseChubUrl(str) {
let domainIndex = -1; let domainIndex = -1;
splitStr.forEach((part, index) => { splitStr.forEach((part, index) => {
if (part === 'www.chub.ai' || part === 'chub.ai') { if (part === 'www.chub.ai' || part === 'chub.ai' || part === 'www.characterhub.org' || part === 'characterhub.org') {
domainIndex = index; domainIndex = index;
} }
}); });
@ -521,7 +521,7 @@ router.post('/importURL', jsonParser, async (request, response) => {
let result; let result;
let type; let type;
const isChub = host.includes('chub.ai'); const isChub = host.includes('chub.ai') || host.includes('characterhub.org');
const isJannnyContent = host.includes('janitorai'); const isJannnyContent = host.includes('janitorai');
const isPygmalionContent = host.includes('pygmalion.chat'); const isPygmalionContent = host.includes('pygmalion.chat');
const isAICharacterCardsContent = host.includes('aicharactercards.com'); const isAICharacterCardsContent = host.includes('aicharactercards.com');