From 6fa4c2c1c8e5a6866f3b4048ae69f3297badc3dc Mon Sep 17 00:00:00 2001 From: Sanskar Tiwari Date: Sun, 21 May 2023 14:16:30 +0530 Subject: [PATCH 1/3] Make openai credit error a catch all --- public/scripts/openai.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index ef5f41cd6..85b78622b 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -497,9 +497,10 @@ function tryParseStreamingError(str) { } function checkQuotaError(data) { - const errorText = `

You have no credits left to use with this API key.
- Check your billing details on the - OpenAI website.

`; + const errorText = `

Encountered an error while processing your request.
+ Check you have credits available on your + OpenAI account.
+ If you have sufficient credits, please try again later.

`; if (!data) { return; From 8a3772f06b01eff5b1ef5d3bef24971b72bb63a9 Mon Sep 17 00:00:00 2001 From: SillyLossy Date: Sun, 21 May 2023 15:06:49 +0300 Subject: [PATCH 2/3] Set is_name=true for instruct mode --- public/script.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 1ff4bb145..be84c8119 100644 --- a/public/script.js +++ b/public/script.js @@ -2955,7 +2955,9 @@ function extractNameFromMessage(getMessage, force_name2, isImpersonate) { // Like OAI, Poe is very unlikely to send you an incomplete message. // But it doesn't send "name:" either, so we assume that we always have a name // prepend to have clearer logs when building up a prompt context. - if (force_name2 || main_api == 'poe') + // Instruct mode needs to have it on to make sure you won't have names lost + // if disable in a middle of a solo chat. + if (force_name2 || main_api == 'poe' || power_user.instruct.enabled) this_mes_is_name = true; if (isImpersonate) { From 71d2f98391408c1acbab7b5ccaa4f3c0201a5b26 Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Sun, 21 May 2023 22:49:03 +0900 Subject: [PATCH 3/3] items in char list now stop rendering out of view --- public/script.js | 62 +++++++++++++++++++++++++++++++++--- public/scripts/power-user.js | 12 ++++--- public/scripts/utils.js | 31 ++++++++++++------ 3 files changed, 87 insertions(+), 18 deletions(-) diff --git a/public/script.js b/public/script.js index 1ff4bb145..61d43caf5 100644 --- a/public/script.js +++ b/public/script.js @@ -107,7 +107,17 @@ import { setPoeOnlineStatus, } from "./scripts/poe.js"; -import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence, countOccurrences, isOdd } from "./scripts/utils.js"; +import { + debounce, + delay, + restoreCaretPosition, + saveCaretPosition, + end_trim_to_sentence, + countOccurrences, + isOdd, + isElementInViewport, +} from "./scripts/utils.js"; + import { extension_settings, loadExtensionSettings } from "./scripts/extensions.js"; import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js"; import { @@ -194,6 +204,7 @@ export { talkativeness_default, default_ch_mes, extension_prompt_types, + setCharListVisible, } // API OBJECT FOR EXTERNAL WIRING @@ -791,6 +802,7 @@ function printCharacters() { printGroups(); sortCharactersList(); favsToHotswap(); + setCharListVisible(); } async function getCharacters() { @@ -4755,6 +4767,33 @@ const swipe_right = () => { } } +function setCharListVisible() { + const $children = $("#rm_print_characters_block").children(); + $children.each(function () { + if (isElementInViewport($(this))) { + $(this) + //.css('opacity', 1); + //.css('display', 'flex'); + .stop(true, false).animate({ opacity: 1 }, { duration: 50, queue: false }); + } + + if (!isElementInViewport($(this)) && + ($(this).css('opacity') === '1' || $(this).css('opacity') === undefined)) { + //.css('opacity', 0); + + $(this) + //.css('opacity', 0); + //.css('display', 'none'); + .stop(true, false).animate({ opacity: 0 }, { duration: 50, queue: false }); + }; + /* console.log(`chid ${$(elem).find('.ch_name').text()} + inview? ${isElementInViewport($(elem))} + opacity? ${$(elem).css('opacity')}` + + ); */ + }) +} + $(document).ready(function () { @@ -5676,13 +5715,11 @@ $(document).ready(function () { duration: 250, easing: animation_easing, }); - console.log('displayed AN panel'); if ($("#ANBlockToggle") .siblings('.inline-drawer-content') .css('display') !== 'block') { $("#ANBlockToggle").click(); - console.log('opened AN box'); } } else { $("#floatingPrompt").transition({ @@ -5692,7 +5729,6 @@ $(document).ready(function () { }); setTimeout(function () { $("#floatingPrompt").hide(); - console.log('hid AN panel'); }, 250); } @@ -6153,6 +6189,24 @@ $(document).ready(function () { showSwipeButtons(); }); + setTimeout(function () { + const $children = $("#rm_print_characters_block").children(); + const originalHeight = $children.length * $children.first().outerHeight(); + $("#rm_print_characters_block").css('height', originalHeight); + //show and hide charlist divs on pageload (causes load lag) + //$children.each(function () { setCharListVisible($(this)) }); + + $("#rm_print_characters_block").on('scroll', debounce(function () { + const containerHeight = $children.length * $children.first().outerHeight(); + $("#rm_print_characters_block").css('height', containerHeight); + //show and hide on scroll + setCharListVisible(); + }, 1)); + //delay timer to allow for charlist to populate, + //should be set to an onload for rm_print_characters or windows? + }, 1000); + + $(document).on("click", ".mes_edit_delete", function () { if (!confirm("Are you sure you want to delete this message?")) { return; diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index b67bc1afd..6e9d9d6d0 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -8,6 +8,7 @@ import { reloadCurrentChat, getRequestHeaders, substituteParams, + setCharListVisible, } from "../script.js"; import { favsToHotswap } from "./RossAscends-mods.js"; import { @@ -643,8 +644,8 @@ function loadInstructMode() { export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar) { const includeNames = isNarrator ? false : (power_user.instruct.names || !!selected_group || !!forceAvatar); const sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence; - const separator = power_user.instruct.wrap ? '\n' : ''; - const separatorSequence = power_user.instruct.separator_sequence && !isUser + const separator = power_user.instruct.wrap ? '\n' : ''; + const separatorSequence = power_user.instruct.separator_sequence && !isUser ? power_user.instruct.separator_sequence : (power_user.instruct.wrap ? '\n' : ''); const textArray = includeNames ? [sequence, `${name}: ${mes}`, separatorSequence] : [sequence, mes, separatorSequence]; @@ -668,7 +669,7 @@ export function formatInstructModePrompt(name, isImpersonate, promptBias) { let text = includeNames ? (separator + sequence + separator + `${name}:`) : (separator + sequence); if (!isImpersonate && promptBias) { - text += (includeNames ? promptBias : (separator + promptBias)); + text += (includeNames ? promptBias : (separator + promptBias)); } return text.trimEnd(); @@ -718,6 +719,7 @@ function sortCharactersList() { for (const item of array) { $(`${item.selector}[${item.attribute}="${item.id}"]`).css({ 'order': orderedList.indexOf(item) }); } + setCharListVisible(); } function sortGroupMembers(selector) { @@ -882,7 +884,7 @@ $(document).ready(() => { // include newline is the child of trim sentences // if include newline is checked, trim sentences must be checked // if trim sentences is unchecked, include newline must be unchecked - $("#trim_sentences_checkbox").change(function() { + $("#trim_sentences_checkbox").change(function () { power_user.trim_sentences = !!$(this).prop("checked"); if (!$(this).prop("checked")) { $("#include_newline_checkbox").prop("checked", false); @@ -891,7 +893,7 @@ $(document).ready(() => { saveSettingsDebounced(); }); - $("#include_newline_checkbox").change(function() { + $("#include_newline_checkbox").change(function () { power_user.include_newline = !!$(this).prop("checked"); if ($(this).prop("checked")) { $("#trim_sentences_checkbox").prop("checked", true); diff --git a/public/scripts/utils.js b/public/scripts/utils.js index 77763b536..e0cb97f72 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -80,6 +80,19 @@ export function debounce(func, timeout = 300) { }; } +export function isElementInViewport(el) { + if (typeof jQuery === "function" && el instanceof jQuery) { + el = el[0]; + } + var rect = el.getBoundingClientRect(); + return ( + rect.top >= 0 && + rect.left >= 0 && + rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /* or $(window).height() */ + rect.right <= (window.innerWidth || document.documentElement.clientWidth) /* or $(window).width() */ + ); +} + export function getUniqueName(name, exists) { let i = 1; let baseName = name; @@ -218,17 +231,17 @@ export function end_trim_to_sentence(input, include_newline = false) { } export function countOccurrences(string, character) { - let count = 0; - - for (let i = 0; i < string.length; i++) { - if (string[i] === character) { - count++; + let count = 0; + + for (let i = 0; i < string.length; i++) { + if (string[i] === character) { + count++; + } } - } - - return count; + + return count; } export function isOdd(number) { - return number % 2 !== 0; + return number % 2 !== 0; } \ No newline at end of file