Merge branch 'staging' into fnr
| @@ -472,6 +472,11 @@ label[for="trim_spaces"]:has(input:checked) i.warning { | ||
| 472 | 472 | display: none; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | +label[for="trim_spaces"]:not(:has(input:checked)) small { | |
| 476 | + color: var(--warning); | |
| 477 | + opacity: 1; | |
| 478 | +} | |
| 479 | + | |
| 475 | 480 | #claude_function_prefill_warning { |
| 476 | 481 | display: none; |
| 477 | 482 | color: red; |
| @@ -1981,13 +1981,13 @@ | ||
| 1981 | 1981 | <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand"> |
| 1982 | 1982 | <input id="openai_show_thoughts" type="checkbox" /> |
| 1983 | 1983 | <span> |
| 1984 | 1984 | <span data-i18n="ShowRequest model reasoning">ShowRequest model reasoning</span> |
| 1985 | 1985 | <i class="opacity50p fa-solid fa-circle-info" title="Gemini 2.0 Thinking / DeepSeek Reasoner"></i> |
| 1986 | 1986 | </span> |
| 1987 | 1987 | </label> |
| 1988 | 1988 | <div class="toggle-description justifyLeft marginBot5"> |
| 1989 | 1989 | <span data-i18n="DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess."> |
| 1990 | 1990 | DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess. |
| 1991 | 1991 | </span> |
| 1992 | 1992 | </div> |
| 1993 | 1993 | </div> |
| @@ -3227,32 +3227,19 @@ | ||
| 3227 | 3227 | <h4 data-i18n="Perplexity Model">Perplexity Model</h4> |
| 3228 | 3228 | <select id="model_perplexity_select"> |
| 3229 | 3229 | <optgroup label="Perplexity Sonar Models"> |
| 3230 | + <option value="sonar">sonar</option> | |
| 3231 | + <option value="sonar-pro">sonar-pro</option> | |
| 3232 | + <option value="sonar-reasoning">sonar-reasoning</option> | |
| 3233 | + </optgroup> | |
| 3234 | + <optgroup label="Deprecated Models"> | |
| 3235 | + <!-- These are scheduled for deprecation after 2/22/2025 --> | |
| 3230 | 3236 | <option value="llama-3.1-sonar-small-128k-online">llama-3.1-sonar-small-128k-online</option> |
| 3231 | 3237 | <option value="llama-3.1-sonar-large-128k-online">llama-3.1-sonar-large-128k-online</option> |
| 3232 | 3238 | <option value="llama-3.1-sonar-huge-128k-online">llama-3.1-sonar-huge-128k-online</option> |
| 3233 | - </optgroup> | |
| 3239 | + <!-- These are not listed on the site anymore --> | |
| 3234 | - <optgroup label="Perplexity Chat Models"> | |
| 3235 | 3240 | <option value="llama-3.1-sonar-small-128k-chat">llama-3.1-sonar-small-128k-chat</option> |
| 3236 | 3241 | <option value="llama-3.1-sonar-large-128k-chat">llama-3.1-sonar-large-128k-chat</option> |
| 3237 | 3242 | </optgroup> |
| 3238 | - <optgroup label="Open-Source Models"> | |
| 3239 | - <option value="llama-3.1-8b-instruct">llama-3.1-8b-instruct</option> | |
| 3240 | - <option value="llama-3.1-70b-instruct">llama-3.1-70b-instruct</option> | |
| 3241 | - </optgroup> | |
| 3242 | - <optgroup label="Deprecated Models"> | |
| 3243 | - <option value="llama-3-sonar-small-32k-chat">llama-3-sonar-small-32k-chat</option> | |
| 3244 | - <option value="llama-3-sonar-small-32k-online">llama-3-sonar-small-32k-online</option> | |
| 3245 | - <option value="llama-3-sonar-large-32k-chat">llama-3-sonar-large-32k-chat</option> | |
| 3246 | - <option value="llama-3-sonar-large-32k-online">llama-3-sonar-large-32k-online</option> | |
| 3247 | - <option value="sonar-small-chat">sonar-small-chat</option> | |
| 3248 | - <option value="sonar-small-online">sonar-small-online</option> | |
| 3249 | - <option value="sonar-medium-chat">sonar-medium-chat</option> | |
| 3250 | - <option value="sonar-medium-online">sonar-medium-online</option> | |
| 3251 | - <option value="llama-3-8b-instruct">llama-3-8b-instruct</option> | |
| 3252 | - <option value="llama-3-70b-instruct">llama-3-70b-instruct</option> | |
| 3253 | - <option value="mistral-7b-instruct">mistral-7b-instruct (v0.2)</option> | |
| 3254 | - <option value="mixtral-8x7b-instruct">mixtral-8x7b-instruct</option> | |
| 3255 | - </optgroup> | |
| 3256 | 3243 | </select> |
| 3257 | 3244 | </div> |
| 3258 | 3245 | <form id="cohere_form" data-source="cohere" action="javascript:void(null);" method="post" enctype="multipart/form-data"> |
| @@ -3804,6 +3791,12 @@ | ||
| 3804 | 3791 | <span data-i18n="Reasoning">Reasoning</span> |
| 3805 | 3792 | </h4> |
| 3806 | 3793 | <div> |
| 3794 | + <label class="checkbox_label" for="reasoning_auto_parse" title="Automatically parse reasoning blocks from main content between the reasoning prefix/suffix. Both fields must be defined and non-empty." data-i18n="[title]reasoning_auto_parse"> | |
| 3795 | + <input id="reasoning_auto_parse" type="checkbox" /> | |
| 3796 | + <small data-i18n="Auto-Parse Reasoning"> | |
| 3797 | + Auto-Parse Reasoning | |
| 3798 | + </small> | |
| 3799 | + </label> | |
| 3807 | 3800 | <label class="checkbox_label" for="reasoning_add_to_prompts" title="Add existing reasoning blocks to prompts. To add a new reasoning block, use the message edit menu." data-i18n="[title]reasoning_add_to_prompts"> |
| 3808 | 3801 | <input id="reasoning_add_to_prompts" type="checkbox" /> |
| 3809 | 3802 | <small data-i18n="Add Reasoning to Prompts"> |
| @@ -1385,8 +1385,8 @@ | ||
| 1385 | 1385 | "enable_functions_desc_1": "Autorise l'utilisation", |
| 1386 | 1386 | "enable_functions_desc_2": "outils de fonction", |
| 1387 | 1387 | "enable_functions_desc_3": "Peut être utilisé par diverses extensions pour fournir des fonctionnalités supplémentaires.", |
| 1388 | 1388 | "ShowRequest model reasoning": "AfficherDemander les pensées du modèle", |
| 1389 | 1389 | "DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.": "AfficherPermet lesau penséesmodèle internesde duretourner modèleson dansprocessus lade réponseréflexion.", |
| 1390 | 1390 | "Confirm token parsing with": "Confirmer l'analyse des tokens avec", |
| 1391 | 1391 | "openai_logit_bias_no_items": "Aucun élément", |
| 1392 | 1392 | "api_no_connection": "Pas de connection...", |
| @@ -266,8 +266,8 @@ | ||
| 266 | 266 | "Use system prompt": "使用系统提示词", |
| 267 | 267 | "Merges_all_system_messages_desc_1": "合并所有系统消息,直到第一条具有非系统角色的消息,然后通过", |
| 268 | 268 | "Merges_all_system_messages_desc_2": "字段发送。", |
| 269 | 269 | "ShowRequest model reasoning": "展示思维链请求思维链", |
| 270 | 270 | "DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.": "展示模型在回复时的内部思维链允许模型返回其思维过程。", |
| 271 | 271 | "Assistant Prefill": "AI预填", |
| 272 | 272 | "Expand the editor": "展开编辑器", |
| 273 | 273 | "Start Claude's answer with...": "以如下内容开始Claude的回答...", |
| @@ -2357,8 +2357,8 @@ | ||
| 2357 | 2357 | "Forbid": "禁止", |
| 2358 | 2358 | "Aphrodite only. Determines the order of samplers. Skew is always applied post-softmax, so it's not included here.": "僅限 Aphrodite 使用。決定採樣器的順序。偏移總是在 softmax 後應用,因此不包括在此。", |
| 2359 | 2359 | "Aphrodite only. Determines the order of samplers.": "僅限 Aphrodite 使用。決定採樣器的順序。", |
| 2360 | 2360 | "ShowRequest model reasoning": "顯示模型思維鏈請求模型思維鏈", |
| 2361 | 2361 | "DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.": "在回應中顯示模型的思維鏈(內部思考過程)讓模型回傳其思考過程。", |
| 2362 | 2362 | "Generic (OpenAI-compatible) [LM Studio, LiteLLM, etc.]": "通用(兼容 OpenAI)[LM Studio, LiteLLM 等]", |
| 2363 | 2363 | "Model ID (optional)": "模型 ID(可選)", |
| 2364 | 2364 | "DeepSeek API Key": "DeepSeek API 金鑰", |
| @@ -95,6 +95,7 @@ import { | ||
| 95 | 95 | resetMovableStyles, |
| 96 | 96 | forceCharacterEditorTokenize, |
| 97 | 97 | applyPowerUserSettings, |
| 98 | + generatedTextFiltered, | |
| 98 | 99 | } from './scripts/power-user.js'; |
| 99 | 100 | |
| 100 | 101 | import { |
| @@ -169,6 +170,7 @@ import { | ||
| 169 | 170 | toggleDrawer, |
| 170 | 171 | isElementInViewport, |
| 171 | 172 | copyText, |
| 173 | + escapeHtml, | |
| 172 | 174 | } from './scripts/utils.js'; |
| 173 | 175 | import { debounce_timeout } from './scripts/constants.js'; |
| 174 | 176 | |
| @@ -1993,14 +1995,15 @@ export async function sendTextareaMessage() { | ||
| 1993 | 1995 | * @param {boolean} isUser If the message was sent by the user |
| 1994 | 1996 | * @param {number} messageId Message index in chat array |
| 1995 | 1997 | * @param {object} [sanitizerOverrides] DOMPurify sanitizer option overrides |
| 1998 | + * @param {boolean} [isReasoning] If the message is reasoning output | |
| 1996 | 1999 | * @returns {string} HTML string |
| 1997 | 2000 | */ |
| 1998 | 2001 | export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, sanitizerOverrides = {}, isReasoning = false) { |
| 1999 | 2002 | if (!mes) { |
| 2000 | 2003 | return ''; |
| 2001 | 2004 | } |
| 2002 | 2005 | |
| 2003 | 2006 | if (Number(messageId) === 0 && !isSystem && !isUser && !isReasoning) { |
| 2004 | 2007 | const mesBeforeReplace = mes; |
| 2005 | 2008 | const chatMessage = chat[messageId]; |
| 2006 | 2009 | mes = substituteParams(mes, undefined, ch_name); |
| @@ -2029,6 +2032,9 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san | ||
| 2029 | 2032 | if (!isSystem) { |
| 2030 | 2033 | function getRegexPlacement() { |
| 2031 | 2034 | try { |
| 2035 | + if (isReasoning) { | |
| 2036 | + return regex_placement.REASONING; | |
| 2037 | + } | |
| 2032 | 2038 | if (isUser) { |
| 2033 | 2039 | return regex_placement.USER_INPUT; |
| 2034 | 2040 | } else if (chat[messageId]?.extra?.type === 'narrator') { |
| @@ -2062,6 +2068,17 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san | ||
| 2062 | 2068 | mes = mes.replaceAll('<', '<').replaceAll('>', '>'); |
| 2063 | 2069 | } |
| 2064 | 2070 | |
| 2071 | + // Make sure reasoning strings are always shown, even if they include "<" or ">" | |
| 2072 | + [power_user.reasoning.prefix, power_user.reasoning.suffix].forEach((reasoningString) => { | |
| 2073 | + if (!reasoningString || !reasoningString.trim().length) { | |
| 2074 | + return; | |
| 2075 | + } | |
| 2076 | + // Only replace the first occurrence of the reasoning string | |
| 2077 | + if (mes.includes(reasoningString)) { | |
| 2078 | + mes = mes.replace(reasoningString, escapeHtml(reasoningString)); | |
| 2079 | + } | |
| 2080 | + }); | |
| 2081 | + | |
| 2065 | 2082 | if (!isSystem) { |
| 2066 | 2083 | // Save double quotes in tags as a special character to prevent them from being encoded |
| 2067 | 2084 | if (!power_user.encode_tags) { |
| @@ -2250,8 +2267,8 @@ function getMessageFromTemplate({ | ||
| 2250 | 2267 | export function updateMessageBlock(messageId, message) { |
| 2251 | 2268 | const messageElement = $(`#chat [mesid="${messageId}"]`); |
| 2252 | 2269 | const text = message?.extra?.display_text ?? message.mes; |
| 2253 | 2270 | messageElement.find('.mes_text').html(messageFormatting(text, message.name, message.is_system, message.is_user, messageId, {}, false)); |
| 2254 | 2271 | messageElement.find('.mes_reasoning').html(messageFormatting(message.extra?.reasoning ?? '', '', false, false, -1messageId, {}, true)); |
| 2255 | 2272 | addCopyToCodeBlocks(messageElement); |
| 2256 | 2273 | appendMediaToMessage(message, messageElement); |
| 2257 | 2274 | } |
| @@ -2408,9 +2425,10 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll | ||
| 2408 | 2425 | mes.is_user, |
| 2409 | 2426 | chat.indexOf(mes), |
| 2410 | 2427 | sanitizerOverrides, |
| 2428 | + false, | |
| 2411 | 2429 | ); |
| 2412 | 2430 | const bias = messageFormatting(mes.extra?.bias ?? '', '', false, false, -1, {}, false); |
| 2413 | 2431 | const reasoning = messageFormatting(mes.extra?.reasoning ?? '', '', false, false, -1chat.indexOf(mes), {}, true); |
| 2414 | 2432 | let bookmarkLink = mes?.extra?.bookmark_link ?? ''; |
| 2415 | 2433 | |
| 2416 | 2434 | let params = { |
| @@ -3153,7 +3171,7 @@ class StreamingProcessor { | ||
| 3153 | 3171 | this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true })); |
| 3154 | 3172 | } |
| 3155 | 3173 | else { |
| 3156 | 3174 | await saveReply(this.type, text, true, '', [], ''); |
| 3157 | 3175 | messageId = chat.length - 1; |
| 3158 | 3176 | this.#checkDomElements(messageId); |
| 3159 | 3177 | this.showMessageButtons(messageId); |
| @@ -3203,9 +3221,9 @@ class StreamingProcessor { | ||
| 3203 | 3221 | } |
| 3204 | 3222 | |
| 3205 | 3223 | if (this.reasoning) { |
| 3206 | 3224 | chat[messageId]['extra']['reasoning'] = power_user.trim_spaces ? this.reasoning.trim() : this.reasoning; |
| 3207 | 3225 | if (this.messageReasoningDom instanceof HTMLElement) { |
| 3208 | 3226 | const formattedReasoning = messageFormatting(this.reasoning, '', false, false, -1messageId, {}, true); |
| 3209 | 3227 | this.messageReasoningDom.innerHTML = formattedReasoning; |
| 3210 | 3228 | } |
| 3211 | 3229 | } |
| @@ -3232,6 +3250,8 @@ class StreamingProcessor { | ||
| 3232 | 3250 | chat[messageId].is_system, |
| 3233 | 3251 | chat[messageId].is_user, |
| 3234 | 3252 | messageId, |
| 3253 | + {}, | |
| 3254 | + false, | |
| 3235 | 3255 | ); |
| 3236 | 3256 | if (this.messageTextDom instanceof HTMLElement) { |
| 3237 | 3257 | this.messageTextDom.innerHTML = formattedText; |
| @@ -3283,39 +3303,11 @@ class StreamingProcessor { | ||
| 3283 | 3303 | unblockGeneration(); |
| 3284 | 3304 | generatedPromptCache = ''; |
| 3285 | 3305 | |
| 3286 | - //console.log("Generated text size:", text.length, text) | |
| 3287 | - | |
| 3288 | 3306 | const isAborted = this.abortController.signal.aborted; |
| 3289 | 3307 | if (!isAborted && power_user.auto_swipe && !isAbortedgeneratedTextFiltered(text)) { |
| 3290 | - function containsBlacklistedWords(str, blacklist, threshold) { | |
| 3308 | + return swipe_right(); | |
| 3291 | - const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi'); | |
| 3292 | - const matches = str.match(regex) || []; | |
| 3293 | - return matches.length >= threshold; | |
| 3294 | 3309 | } |
| 3295 | 3310 | |
| 3296 | - const generatedTextFiltered = (text) => { | |
| 3297 | - if (text) { | |
| 3298 | - if (power_user.auto_swipe_minimum_length) { | |
| 3299 | - if (text.length < power_user.auto_swipe_minimum_length && text.length !== 0) { | |
| 3300 | - console.log('Generated text size too small'); | |
| 3301 | - return true; | |
| 3302 | - } | |
| 3303 | - } | |
| 3304 | - if (power_user.auto_swipe_blacklist_threshold) { | |
| 3305 | - if (containsBlacklistedWords(text, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) { | |
| 3306 | - console.log('Generated text has blacklisted words'); | |
| 3307 | - return true; | |
| 3308 | - } | |
| 3309 | - } | |
| 3310 | - } | |
| 3311 | - return false; | |
| 3312 | - }; | |
| 3313 | - | |
| 3314 | - if (generatedTextFiltered(text)) { | |
| 3315 | - swipe_right(); | |
| 3316 | - return; | |
| 3317 | - } | |
| 3318 | - } | |
| 3319 | 3311 | playMessageSound(); |
| 3320 | 3312 | } |
| 3321 | 3313 | |
| @@ -3373,7 +3365,7 @@ class StreamingProcessor { | ||
| 3373 | 3365 | const timestamps = []; |
| 3374 | 3366 | for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) { |
| 3375 | 3367 | timestamps.push(Date.now()); |
| 3376 | 3368 | if (this.isStopped || this.abortController.signal.aborted) { |
| 3377 | 3369 | return; |
| 3378 | 3370 | } |
| 3379 | 3371 | |
| @@ -3383,7 +3375,7 @@ class StreamingProcessor { | ||
| 3383 | 3375 | if (logprobs) { |
| 3384 | 3376 | this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs])); |
| 3385 | 3377 | } |
| 3386 | 3378 | this.reasoning = getRegexedString(state?.reasoning ?? '', regex_placement.REASONING); |
| 3387 | 3379 | await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text); |
| 3388 | 3380 | await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text)); |
| 3389 | 3381 | } |
| @@ -3850,14 +3842,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 3850 | 3842 | coreChat.pop(); |
| 3851 | 3843 | } |
| 3852 | 3844 | |
| 3853 | - const reasoning = new PromptReasoning(); | |
| 3854 | - for (let i = coreChat.length - 1; i >= 0; i--) { | |
| 3855 | - if (reasoning.isLimitReached()) { | |
| 3856 | - break; | |
| 3857 | - } | |
| 3858 | - coreChat[i] = { ...coreChat[i], mes: reasoning.addToMessage(coreChat[i].mes, coreChat[i].extra?.reasoning) }; | |
| 3859 | - } | |
| 3860 | - | |
| 3861 | 3845 | coreChat = await Promise.all(coreChat.map(async (chatItem, index) => { |
| 3862 | 3846 | let message = chatItem.mes; |
| 3863 | 3847 | let regexType = chatItem.is_user ? regex_placement.USER_INPUT : regex_placement.AI_OUTPUT; |
| @@ -3877,6 +3861,27 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 3877 | 3861 | }; |
| 3878 | 3862 | })); |
| 3879 | 3863 | |
| 3864 | + const reasoning = new PromptReasoning(); | |
| 3865 | + for (let i = coreChat.length - 1; i >= 0; i--) { | |
| 3866 | + const depth = coreChat.length - i - 1; | |
| 3867 | + const isPrefix = isContinue && i === coreChat.length - 1; | |
| 3868 | + coreChat[i] = { | |
| 3869 | + ...coreChat[i], | |
| 3870 | + mes: reasoning.addToMessage( | |
| 3871 | + coreChat[i].mes, | |
| 3872 | + getRegexedString( | |
| 3873 | + String(coreChat[i].extra?.reasoning ?? ''), | |
| 3874 | + regex_placement.REASONING, | |
| 3875 | + { isPrompt: true, depth: depth }, | |
| 3876 | + ), | |
| 3877 | + isPrefix, | |
| 3878 | + ), | |
| 3879 | + }; | |
| 3880 | + if (reasoning.isLimitReached()) { | |
| 3881 | + break; | |
| 3882 | + } | |
| 3883 | + } | |
| 3884 | + | |
| 3880 | 3885 | // Determine token limit |
| 3881 | 3886 | let this_max_context = getMaxContextSize(); |
| 3882 | 3887 | |
| @@ -4785,6 +4790,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4785 | 4790 | const swipes = extractMultiSwipes(data, type); |
| 4786 | 4791 | |
| 4787 | 4792 | messageChunk = cleanUpMessage(getMessage, isImpersonate, isContinue, false); |
| 4793 | + reasoning = getRegexedString(reasoning, regex_placement.REASONING); | |
| 4794 | + | |
| 4795 | + if (power_user.trim_spaces) { | |
| 4796 | + reasoning = reasoning.trim(); | |
| 4797 | + } | |
| 4788 | 4798 | |
| 4789 | 4799 | if (isContinue) { |
| 4790 | 4800 | getMessage = continue_mag + getMessage; |
| @@ -4843,32 +4853,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4843 | 4853 | } |
| 4844 | 4854 | |
| 4845 | 4855 | const isAborted = abortController && abortController.signal.aborted; |
| 4846 | 4856 | if (!isAborted && power_user.auto_swipe && !isAbortedgeneratedTextFiltered(getMessage)) { |
| 4847 | - console.debug('checking for autoswipeblacklist on non-streaming message'); | |
| 4848 | - function containsBlacklistedWords(getMessage, blacklist, threshold) { | |
| 4849 | - console.debug('checking blacklisted words'); | |
| 4850 | - const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi'); | |
| 4851 | - const matches = getMessage.match(regex) || []; | |
| 4852 | - return matches.length >= threshold; | |
| 4853 | - } | |
| 4854 | - | |
| 4855 | - const generatedTextFiltered = (getMessage) => { | |
| 4856 | - if (power_user.auto_swipe_blacklist_threshold) { | |
| 4857 | - if (containsBlacklistedWords(getMessage, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) { | |
| 4858 | - console.debug('Generated text has blacklisted words'); | |
| 4859 | - return true; | |
| 4860 | - } | |
| 4861 | - } | |
| 4862 | - | |
| 4863 | - return false; | |
| 4864 | - }; | |
| 4865 | - if (generatedTextFiltered(getMessage)) { | |
| 4866 | - console.debug('swiping right automatically'); | |
| 4867 | 4857 | is_send_press = false; |
| 4868 | 4858 | return swipe_right(); |
| 4869 | - // TODO: do we want to resolve after an auto-swipe? | |
| 4870 | - return; | |
| 4871 | - } | |
| 4872 | 4859 | } |
| 4873 | 4860 | |
| 4874 | 4861 | console.debug('/api/chats/save called by /Generate'); |
| @@ -6074,6 +6061,19 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | ||
| 6074 | 6061 | return { type, getMessage }; |
| 6075 | 6062 | } |
| 6076 | 6063 | |
| 6064 | +export function syncCurrentSwipeInfoExtras() { | |
| 6065 | + if (!chat.length) { | |
| 6066 | + return; | |
| 6067 | + } | |
| 6068 | + const currentMessage = chat[chat.length - 1]; | |
| 6069 | + if (currentMessage && Array.isArray(currentMessage.swipe_info) && typeof currentMessage.swipe_id === 'number') { | |
| 6070 | + const swipeInfo = currentMessage.swipe_info[currentMessage.swipe_id]; | |
| 6071 | + if (swipeInfo && typeof swipeInfo === 'object') { | |
| 6072 | + swipeInfo.extra = structuredClone(currentMessage.extra); | |
| 6073 | + } | |
| 6074 | + } | |
| 6075 | +} | |
| 6076 | + | |
| 6077 | 6077 | function saveImageToMessage(img, mes) { |
| 6078 | 6078 | if (mes && img.image) { |
| 6079 | 6079 | if (!mes.extra || typeof mes.extra !== 'object') { |
| @@ -7177,9 +7177,11 @@ function messageEditAuto(div) { | ||
| 7177 | 7177 | mes.is_system, |
| 7178 | 7178 | mes.is_user, |
| 7179 | 7179 | this_edit_mes_id, |
| 7180 | + {}, | |
| 7181 | + false, | |
| 7180 | 7182 | )); |
| 7181 | 7183 | mesBlock.find('.mes_bias').empty(); |
| 7182 | 7184 | mesBlock.find('.mes_bias').append(messageFormatting(bias, '', false, false, -1, {}, false)); |
| 7183 | 7185 | saveChatDebounced(); |
| 7184 | 7186 | } |
| 7185 | 7187 | |
| @@ -7201,10 +7203,12 @@ async function messageEditDone(div) { | ||
| 7201 | 7203 | mes.is_system, |
| 7202 | 7204 | mes.is_user, |
| 7203 | 7205 | this_edit_mes_id, |
| 7206 | + {}, | |
| 7207 | + false, | |
| 7204 | 7208 | ), |
| 7205 | 7209 | ); |
| 7206 | 7210 | mesBlock.find('.mes_bias').empty(); |
| 7207 | 7211 | mesBlock.find('.mes_bias').append(messageFormatting(bias, '', false, false, -1, {}, false)); |
| 7208 | 7212 | appendMediaToMessage(mes, div.closest('.mes')); |
| 7209 | 7213 | addCopyToCodeBlocks(div.closest('.mes')); |
| 7210 | 7214 | |
| @@ -8501,6 +8505,9 @@ function swipe_left() { // when we swipe left..but no generation. | ||
| 8501 | 8505 | streamingProcessor.onStopStreaming(); |
| 8502 | 8506 | } |
| 8503 | 8507 | |
| 8508 | + // Make sure ad-hoc changes to extras are saved before swiping away | |
| 8509 | + syncCurrentSwipeInfoExtras(); | |
| 8510 | + | |
| 8504 | 8511 | const swipe_duration = 120; |
| 8505 | 8512 | const swipe_range = '700px'; |
| 8506 | 8513 | chat[chat.length - 1]['swipe_id']--; |
| @@ -8636,6 +8643,9 @@ const swipe_right = () => { | ||
| 8636 | 8643 | return unblockGeneration(); |
| 8637 | 8644 | } |
| 8638 | 8645 | |
| 8646 | + // Make sure ad-hoc changes to extras are saved before swiping away | |
| 8647 | + syncCurrentSwipeInfoExtras(); | |
| 8648 | + | |
| 8639 | 8649 | const swipe_duration = 200; |
| 8640 | 8650 | const swipe_range = 700; |
| 8641 | 8651 | //console.log(swipe_range); |
| @@ -10841,6 +10851,8 @@ jQuery(async function () { | ||
| 10841 | 10851 | chat[this_edit_mes_id].is_system, |
| 10842 | 10852 | chat[this_edit_mes_id].is_user, |
| 10843 | 10853 | this_edit_mes_id, |
| 10854 | + {}, | |
| 10855 | + false, | |
| 10844 | 10856 | )); |
| 10845 | 10857 | appendMediaToMessage(chat[this_edit_mes_id], $(this).closest('.mes')); |
| 10846 | 10858 | addCopyToCodeBlocks($(this).closest('.mes')); |
| @@ -566,7 +566,7 @@ export function initAuthorsNote() { | ||
| 566 | 566 | namedArgumentList: [], |
| 567 | 567 | unnamedArgumentList: [ |
| 568 | 568 | new SlashCommandArgument( |
| 569 | 569 | 'positionrole', [ARGUMENT_TYPE.STRING], false, false, null, ['system', 'user', 'assistant'], |
| 570 | 570 | ), |
| 571 | 571 | ], |
| 572 | 572 | helpString: ` |
| @@ -96,8 +96,13 @@ function highlightLockedBackground() { | ||
| 96 | 96 | }); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | +/** | |
| 100 | + * Locks the background for the current chat | |
| 101 | + * @param {Event} e Click event | |
| 102 | + * @returns {string} Empty string | |
| 103 | + */ | |
| 99 | 104 | function onLockBackgroundClick(e) { |
| 100 | 105 | e?.stopPropagation(); |
| 101 | 106 | |
| 102 | 107 | const chatName = getCurrentChatId(); |
| 103 | 108 | |
| @@ -106,7 +111,7 @@ function onLockBackgroundClick(e) { | ||
| 106 | 111 | return ''; |
| 107 | 112 | } |
| 108 | 113 | |
| 109 | 114 | const relativeBgImage = getUrlParameter(this) ?? background_settings.url; |
| 110 | 115 | |
| 111 | 116 | saveBackgroundMetadata(relativeBgImage); |
| 112 | 117 | setCustomBackground(); |
| @@ -114,8 +119,13 @@ function onLockBackgroundClick(e) { | ||
| 114 | 119 | return ''; |
| 115 | 120 | } |
| 116 | 121 | |
| 122 | +/** | |
| 123 | + * Locks the background for the current chat | |
| 124 | + * @param {Event} e Click event | |
| 125 | + * @returns {string} Empty string | |
| 126 | + */ | |
| 117 | 127 | function onUnlockBackgroundClick(e) { |
| 118 | 128 | e?.stopPropagation(); |
| 119 | 129 | removeBackgroundMetadata(); |
| 120 | 130 | unsetCustomBackground(); |
| 121 | 131 | highlightLockedBackground(); |
| @@ -513,12 +523,12 @@ export function initBackgrounds() { | ||
| 513 | 523 | $('#add_bg_button').on('change', onBackgroundUploadSelected); |
| 514 | 524 | $('#bg-filter').on('input', onBackgroundFilterInput); |
| 515 | 525 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg', |
| 516 | - callback: onLockBackgroundClick, | |
| 526 | + callback: () => onLockBackgroundClick(new CustomEvent('click')), | |
| 517 | 527 | aliases: ['bglock'], |
| 518 | 528 | helpString: 'Locks a background for the currently selected chat', |
| 519 | 529 | })); |
| 520 | 530 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg', |
| 521 | - callback: onUnlockBackgroundClick, | |
| 531 | + callback: () => onUnlockBackgroundClick(new CustomEvent('click')), | |
| 522 | 532 | aliases: ['bgunlock'], |
| 523 | 533 | helpString: 'Unlocks a background for the currently selected chat', |
| 524 | 534 | })); |
| @@ -30,6 +30,7 @@ const CC_COMMANDS = [ | ||
| 30 | 30 | 'api-url', |
| 31 | 31 | 'model', |
| 32 | 32 | 'proxy', |
| 33 | + 'stop-strings', | |
| 33 | 34 | ]; |
| 34 | 35 | |
| 35 | 36 | const TC_COMMANDS = [ |
| @@ -43,6 +44,7 @@ const TC_COMMANDS = [ | ||
| 43 | 44 | 'context', |
| 44 | 45 | 'instruct-state', |
| 45 | 46 | 'tokenizer', |
| 47 | + 'stop-strings', | |
| 46 | 48 | ]; |
| 47 | 49 | |
| 48 | 50 | const FANCY_NAMES = { |
| @@ -57,6 +59,7 @@ const FANCY_NAMES = { | ||
| 57 | 59 | 'instruct': 'Instruct Template', |
| 58 | 60 | 'context': 'Context Template', |
| 59 | 61 | 'tokenizer': 'Tokenizer', |
| 62 | + 'stop-strings': 'Custom Stopping Strings', | |
| 60 | 63 | }; |
| 61 | 64 | |
| 62 | 65 | /** |
| @@ -138,6 +141,7 @@ const profilesProvider = () => [ | ||
| 138 | 141 | * @property {string} [context] Context Template |
| 139 | 142 | * @property {string} [instruct-state] Instruct Mode |
| 140 | 143 | * @property {string} [tokenizer] Tokenizer |
| 144 | + * @property {string} [stop-strings] Custom Stopping Strings | |
| 141 | 145 | * @property {string[]} [exclude] Commands to exclude |
| 142 | 146 | */ |
| 143 | 147 | |
| @@ -883,6 +883,10 @@ export class SlashCommandHandler { | ||
| 883 | 883 | } |
| 884 | 884 | } |
| 885 | 885 | getQuickReply(args) { |
| 886 | + if (!args.id && !args.label) { | |
| 887 | + toastr.error('Please provide a valid id or label.'); | |
| 888 | + return ''; | |
| 889 | + } | |
| 886 | 890 | try { |
| 887 | 891 | return JSON.stringify(this.api.getQrByLabel(args.set, args.id !== undefined ? Number(args.id) : args.label)); |
| 888 | 892 | } catch (ex) { |
| @@ -94,6 +94,12 @@ | ||
| 94 | 94 | <span data-i18n="World Info">World Info</span> |
| 95 | 95 | </label> |
| 96 | 96 | </div> |
| 97 | + <div data-i18n="[title]ext_regex_reasoning_desc" title="Reasoning block contents. When 'Only Format Prompt' is checked, it will also affect the reasoning contents added to the prompt."> | |
| 98 | + <label class="checkbox flex-container"> | |
| 99 | + <input type="checkbox" name="replace_position" value="6"> | |
| 100 | + <span data-i18n="Reasoning">Reasoning</span> | |
| 101 | + </label> | |
| 102 | + </div> | |
| 97 | 103 | <div class="flex-container wide100p marginTop5"> |
| 98 | 104 | <div class="flex1 flex-container flexNoGap"> |
| 99 | 105 | <small data-i18n="[title]ext_regex_min_depth_desc" title="When applied to prompts or display, only affect messages that are at least N levels deep. 0 = last message, 1 = penultimate message, etc. Only counts WI entries @Depth and usable messages, i.e. not hidden or system."> |
| @@ -20,6 +20,7 @@ const regex_placement = { | ||
| 20 | 20 | SLASH_COMMAND: 3, |
| 21 | 21 | // 4 - sendAs (legacy) |
| 22 | 22 | WORLD_INFO: 5, |
| 23 | + REASONING: 6, | |
| 23 | 24 | }; |
| 24 | 25 | |
| 25 | 26 | export const substitute_find_regex = { |
| @@ -94,7 +95,7 @@ function getRegexedString(rawString, placement, { characterOverride, isMarkdown, | ||
| 94 | 95 | // Script applies to Generate and input is Generate |
| 95 | 96 | (script.promptOnly && isPrompt) || |
| 96 | 97 | // Script applies to all cases when neither "only"s are true, but there's no need to do it when `isMarkdown`, the as source (chat history) should already be changed beforehand |
| 97 | 98 | (!script.markdownOnly && !script.promptOnly && !isMarkdown && !isPrompt) |
| 98 | 99 | ) { |
| 99 | 100 | if (isEdit && !script.runOnEdit) { |
| 100 | 101 | console.debug(`getRegexedString: Skipping script ${script.scriptName} because it does not run on edit`); |
| @@ -18,7 +18,7 @@ import { t } from '../../i18n.js'; | ||
| 18 | 18 | * @property {string} replaceString - The replace string |
| 19 | 19 | * @property {string[]} trimStrings - The trim strings |
| 20 | 20 | * @property {string?} findRegex - The find regex |
| 21 | 21 | * @property {stringnumber?} substituteRegex - The substitute regex |
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | /** |
| @@ -388,7 +388,7 @@ class AllTalkTtsProvider { | ||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | async fetchRvcVoiceObjects() { |
| 391 | 391 | if (this.settings.server_version == 'v2v1') { |
| 392 | 392 | console.log('Skipping RVC voices fetch for V1 server'); |
| 393 | 393 | return []; |
| 394 | 394 | } |
| @@ -1031,14 +1031,18 @@ class AllTalkTtsProvider { | ||
| 1031 | 1031 | console.error('fetchTtsGeneration Error Response Text:', errorText); |
| 1032 | 1032 | throw new Error(`HTTP ${response.status}: ${errorText}`); |
| 1033 | 1033 | } |
| 1034 | + | |
| 1034 | 1035 | const data = await response.json(); |
| 1035 | 1036 | |
| 1036 | - // Handle V1/V2 URL differences | |
| 1037 | + // V1 returns a complete URL, V2 returns a relative path | |
| 1037 | 1038 | const outputUrl =if (this.settings.server_version === 'v1') { |
| 1038 | - ? data.output_file_url // V1 returns full URL | |
| 1039 | + // V1: Use the complete URL directly from the response | |
| 1039 | - : `${this.settings.provider_endpoint}${data.output_file_url}`; // V2 returns relative path | |
| 1040 | + return data.output_file_url; | |
| 1041 | + } else { | |
| 1042 | + // V2: Combine the endpoint with the relative path | |
| 1043 | + return `${this.settings.provider_endpoint}${data.output_file_url}`; | |
| 1044 | + } | |
| 1040 | 1045 | |
| 1041 | - return outputUrl; | |
| 1042 | 1046 | } catch (error) { |
| 1043 | 1047 | console.error('[fetchTtsGeneration] Exception caught:', error); |
| 1044 | 1048 | throw error; |
| @@ -30,6 +30,7 @@ import { GoogleTranslateTtsProvider } from './google-translate.js'; | ||
| 30 | 30 | export { talkingAnimation }; |
| 31 | 31 | |
| 32 | 32 | const UPDATE_INTERVAL = 1000; |
| 33 | +const wrapper = new ModuleWorkerWrapper(moduleWorker); | |
| 33 | 34 | |
| 34 | 35 | let voiceMapEntries = []; |
| 35 | 36 | let voiceMap = {}; // {charName:voiceid, charName2:voiceid2} |
| @@ -120,7 +121,7 @@ async function onNarrateOneMessage() { | ||
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | resetTtsPlayback(); |
| 123 | 124 | ttsJobQueue.pushprocessAndQueueTtsMessage(message); |
| 124 | 125 | moduleWorker(); |
| 125 | 126 | } |
| 126 | 127 | |
| @@ -147,7 +148,7 @@ async function onNarrateText(args, text) { | ||
| 147 | 148 | } |
| 148 | 149 | |
| 149 | 150 | resetTtsPlayback(); |
| 150 | 151 | ttsJobQueue.pushprocessAndQueueTtsMessage({ mes: text, name: name }); |
| 151 | 152 | await moduleWorker(); |
| 152 | 153 | |
| 153 | 154 | // Return back to the chat voices |
| @@ -220,6 +221,36 @@ function isTtsProcessing() { | ||
| 220 | 221 | return processing; |
| 221 | 222 | } |
| 222 | 223 | |
| 224 | +/** | |
| 225 | + * Splits a message into lines and adds each non-empty line to the TTS job queue. | |
| 226 | + * @param {Object} message - The message object to be processed. | |
| 227 | + * @param {string} message.mes - The text of the message to be split into lines. | |
| 228 | + * @param {string} message.name - The name associated with the message. | |
| 229 | + * @returns {void} | |
| 230 | + */ | |
| 231 | +function processAndQueueTtsMessage(message) { | |
| 232 | + if (!extension_settings.tts.narrate_by_paragraphs) { | |
| 233 | + ttsJobQueue.push(message); | |
| 234 | + return; | |
| 235 | + } | |
| 236 | + | |
| 237 | + const lines = message.mes.split('\n'); | |
| 238 | + | |
| 239 | + for (let i = 0; i < lines.length; i++) { | |
| 240 | + const line = lines[i]; | |
| 241 | + | |
| 242 | + if (line.length === 0) { | |
| 243 | + continue; | |
| 244 | + } | |
| 245 | + | |
| 246 | + ttsJobQueue.push( | |
| 247 | + Object.assign({}, message, { | |
| 248 | + mes: line, | |
| 249 | + }), | |
| 250 | + ); | |
| 251 | + } | |
| 252 | +} | |
| 253 | + | |
| 223 | 254 | function debugTtsPlayback() { |
| 224 | 255 | console.log(JSON.stringify( |
| 225 | 256 | { |
| @@ -350,7 +381,7 @@ function onAudioControlClicked() { | ||
| 350 | 381 | talkingAnimation(false); |
| 351 | 382 | } else { |
| 352 | 383 | // Default play behavior if not processing or playing is to play the last message. |
| 353 | 384 | ttsJobQueue.pushprocessAndQueueTtsMessage(context.chat[context.chat.length - 1]); |
| 354 | 385 | } |
| 355 | 386 | updateUiAudioPlayState(); |
| 356 | 387 | } |
| @@ -376,6 +407,7 @@ function completeCurrentAudioJob() { | ||
| 376 | 407 | currentAudioJob = null; |
| 377 | 408 | talkingAnimation(false); //stop lip animation |
| 378 | 409 | // updateUiPlayState(); |
| 410 | + wrapper.update(); | |
| 379 | 411 | } |
| 380 | 412 | |
| 381 | 413 | /** |
| @@ -466,7 +498,7 @@ async function processTtsQueue() { | ||
| 466 | 498 | } |
| 467 | 499 | |
| 468 | 500 | if (extension_settings.tts.skip_tags) { |
| 469 | 501 | text = text.replace(/<.*?>.[\s\S]*?<\/.*?>/g, '').trim(); |
| 470 | 502 | } |
| 471 | 503 | |
| 472 | 504 | if (!extension_settings.tts.pass_asterisks) { |
| @@ -569,6 +601,7 @@ function loadSettings() { | ||
| 569 | 601 | $('#tts_narrate_quoted').prop('checked', extension_settings.tts.narrate_quoted_only); |
| 570 | 602 | $('#tts_auto_generation').prop('checked', extension_settings.tts.auto_generation); |
| 571 | 603 | $('#tts_periodic_auto_generation').prop('checked', extension_settings.tts.periodic_auto_generation); |
| 604 | + $('#tts_narrate_by_paragraphs').prop('checked', extension_settings.tts.narrate_by_paragraphs); | |
| 572 | 605 | $('#tts_narrate_translated_only').prop('checked', extension_settings.tts.narrate_translated_only); |
| 573 | 606 | $('#tts_narrate_user').prop('checked', extension_settings.tts.narrate_user); |
| 574 | 607 | $('#tts_pass_asterisks').prop('checked', extension_settings.tts.pass_asterisks); |
| @@ -638,6 +671,11 @@ function onPeriodicAutoGenerationClick() { | ||
| 638 | 671 | saveSettingsDebounced(); |
| 639 | 672 | } |
| 640 | 673 | |
| 674 | +function onNarrateByParagraphsClick() { | |
| 675 | + extension_settings.tts.narrate_by_paragraphs = !!$('#tts_narrate_by_paragraphs').prop('checked'); | |
| 676 | + saveSettingsDebounced(); | |
| 677 | +} | |
| 678 | + | |
| 641 | 679 | |
| 642 | 680 | function onNarrateDialoguesClick() { |
| 643 | 681 | extension_settings.tts.narrate_dialogues_only = !!$('#tts_narrate_dialogues').prop('checked'); |
| @@ -816,7 +854,12 @@ async function onMessageEvent(messageId, lastCharIndex) { | ||
| 816 | 854 | lastChatId = context.chatId; |
| 817 | 855 | |
| 818 | 856 | console.debug(`Adding message from ${message.name} for TTS processing: "${message.mes}"`); |
| 857 | + | |
| 858 | + if (extension_settings.tts.periodic_auto_generation) { | |
| 819 | 859 | ttsJobQueue.push(message); |
| 860 | + } else { | |
| 861 | + processAndQueueTtsMessage(message); | |
| 862 | + } | |
| 820 | 863 | } |
| 821 | 864 | |
| 822 | 865 | async function onMessageDeleted() { |
| @@ -1156,6 +1199,7 @@ jQuery(async function () { | ||
| 1156 | 1199 | $('#tts_pass_asterisks').on('click', onPassAsterisksClick); |
| 1157 | 1200 | $('#tts_auto_generation').on('click', onAutoGenerationClick); |
| 1158 | 1201 | $('#tts_periodic_auto_generation').on('click', onPeriodicAutoGenerationClick); |
| 1202 | + $('#tts_narrate_by_paragraphs').on('click', onNarrateByParagraphsClick); | |
| 1159 | 1203 | $('#tts_narrate_user').on('click', onNarrateUserClick); |
| 1160 | 1204 | |
| 1161 | 1205 | $('#playback_rate').on('input', function () { |
| @@ -1177,7 +1221,6 @@ jQuery(async function () { | ||
| 1177 | 1221 | loadSettings(); // Depends on Extension Controls and loadTtsProvider |
| 1178 | 1222 | loadTtsProvider(extension_settings.tts.currentProvider); // No dependencies |
| 1179 | 1223 | addAudioControl(); // Depends on Extension Controls |
| 1180 | - const wrapper = new ModuleWorkerWrapper(moduleWorker); | |
| 1181 | 1224 | setInterval(wrapper.update.bind(wrapper), UPDATE_INTERVAL); // Init depends on all the things |
| 1182 | 1225 | eventSource.on(event_types.MESSAGE_SWIPED, resetTtsPlayback); |
| 1183 | 1226 | eventSource.on(event_types.CHAT_CHANGED, onChatChanged); |
| @@ -30,6 +30,10 @@ | ||
| 30 | 30 | <input type="checkbox" id="tts_periodic_auto_generation"> |
| 31 | 31 | <small data-i18n="Narrate by paragraphs (when streaming)">Narrate by paragraphs (when streaming)</small> |
| 32 | 32 | </label> |
| 33 | + <label class="checkbox_label" for="tts_narrate_by_paragraphs"> | |
| 34 | + <input type="checkbox" id="tts_narrate_by_paragraphs"> | |
| 35 | + <small data-i18n="Narrate by paragraphs (when not streaming)">Narrate by paragraphs (when not streaming)</small> | |
| 36 | + </label> | |
| 33 | 37 | <label class="checkbox_label" for="tts_narrate_quoted"> |
| 34 | 38 | <input type="checkbox" id="tts_narrate_quoted"> |
| 35 | 39 | <small data-i18n="Only narrate quotes">Only narrate "quotes"</small> |
| @@ -27,21 +27,42 @@ export async function hideLoader() { | ||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | return new Promise((resolve) => { |
| 30 | - // Spinner blurs/fades out | |
| 30 | + const spinner = $('#load-spinner'); | |
| 31 | - $('#load-spinner').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function () { | |
| 31 | + if (!spinner.length) { | |
| 32 | + console.warn('Spinner element not found, skipping animation'); | |
| 33 | + cleanup(); | |
| 34 | + return; | |
| 35 | + } | |
| 36 | + | |
| 37 | + // Check if transitions are enabled | |
| 38 | + const transitionDuration = spinner[0] ? getComputedStyle(spinner[0]).transitionDuration : '0s'; | |
| 39 | + const hasTransitions = parseFloat(transitionDuration) > 0; | |
| 40 | + | |
| 41 | + if (hasTransitions) { | |
| 42 | + Promise.race([ | |
| 43 | + new Promise((r) => setTimeout(r, 500)), // Fallback timeout | |
| 44 | + new Promise((r) => spinner.one('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', r)), | |
| 45 | + ]).finally(cleanup); | |
| 46 | + } else { | |
| 47 | + cleanup(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + function cleanup() { | |
| 32 | 51 | $('#loader').remove(); |
| 33 | 52 | // Yoink preloader entirely; it only exists to cover up unstyled content while loading JS |
| 34 | 53 | // If it's present, we remove it once and then it's gone. |
| 35 | 54 | yoinkPreloader(); |
| 36 | 55 | |
| 37 | 56 | loaderPopup.complete(POPUP_RESULT.AFFIRMATIVE).then(() => { |
| 57 | + .catch((err) => console.error('Error completing loaderPopup:', err)) | |
| 58 | + .finally(() => { | |
| 38 | 59 | loaderPopup = null; |
| 39 | 60 | resolve(); |
| 40 | 61 | }); |
| 41 | 62 | }); |
| 42 | 63 | |
| 43 | - $('#load-spinner') | |
| 64 | + // Apply the styles | |
| 44 | 65 | spinner.css({ |
| 45 | 66 | 'filter': 'blur(15px)', |
| 46 | 67 | 'opacity': '0', |
| 47 | 68 | }); |
| @@ -258,7 +258,7 @@ const default_settings = { | ||
| 258 | 258 | ai21_model: 'jamba-1.5-large', |
| 259 | 259 | mistralai_model: 'mistral-large-latest', |
| 260 | 260 | cohere_model: 'command-r-plus', |
| 261 | 261 | perplexity_model: 'llama-3.1-70bsonar-instructpro', |
| 262 | 262 | groq_model: 'llama-3.1-70b-versatile', |
| 263 | 263 | nanogpt_model: 'gpt-4o-mini', |
| 264 | 264 | zerooneai_model: 'yi-large', |
| @@ -337,7 +337,7 @@ const oai_settings = { | ||
| 337 | 337 | ai21_model: 'jamba-1.5-large', |
| 338 | 338 | mistralai_model: 'mistral-large-latest', |
| 339 | 339 | cohere_model: 'command-r-plus', |
| 340 | 340 | perplexity_model: 'llama-3.1-70bsonar-instructpro', |
| 341 | 341 | groq_model: 'llama-3.1-70b-versatile', |
| 342 | 342 | nanogpt_model: 'gpt-4o-mini', |
| 343 | 343 | zerooneai_model: 'yi-large', |
| @@ -4380,28 +4380,19 @@ async function onModelChange() { | ||
| 4380 | 4380 | if (oai_settings.max_context_unlocked) { |
| 4381 | 4381 | $('#openai_max_context').attr('max', unlocked_max); |
| 4382 | 4382 | } |
| 4383 | + else if (['sonar', 'sonar-reasoning'].includes(oai_settings.perplexity_model)) { | |
| 4384 | + $('#openai_max_context').attr('max', 127000); | |
| 4385 | + } | |
| 4386 | + else if (['sonar-pro'].includes(oai_settings.perplexity_model)) { | |
| 4387 | + $('#openai_max_context').attr('max', 200000); | |
| 4388 | + } | |
| 4383 | 4389 | else if (oai_settings.perplexity_model.includes('llama-3.1')) { |
| 4384 | 4390 | const isOnline = oai_settings.perplexity_model.includes('online'); |
| 4385 | 4391 | const contextSize = isOnline ? 128 * 1024 - 4000 : 128 * 1024; |
| 4386 | 4392 | $('#openai_max_context').attr('max', contextSize); |
| 4387 | 4393 | } |
| 4388 | - else if (['llama-3-sonar-small-32k-chat', 'llama-3-sonar-large-32k-chat'].includes(oai_settings.perplexity_model)) { | |
| 4389 | - $('#openai_max_context').attr('max', max_32k); | |
| 4390 | - } | |
| 4391 | - else if (['llama-3-sonar-small-32k-online', 'llama-3-sonar-large-32k-online'].includes(oai_settings.perplexity_model)) { | |
| 4392 | - $('#openai_max_context').attr('max', 28000); | |
| 4393 | - } | |
| 4394 | - else if (['sonar-small-chat', 'sonar-medium-chat', 'codellama-70b-instruct', 'mistral-7b-instruct', 'mixtral-8x7b-instruct', 'mixtral-8x22b-instruct'].includes(oai_settings.perplexity_model)) { | |
| 4395 | - $('#openai_max_context').attr('max', max_16k); | |
| 4396 | - } | |
| 4397 | - else if (['llama-3-8b-instruct', 'llama-3-70b-instruct'].includes(oai_settings.perplexity_model)) { | |
| 4398 | - $('#openai_max_context').attr('max', max_8k); | |
| 4399 | - } | |
| 4400 | - else if (['sonar-small-online', 'sonar-medium-online'].includes(oai_settings.perplexity_model)) { | |
| 4401 | - $('#openai_max_context').attr('max', 12000); | |
| 4402 | - } | |
| 4403 | 4394 | else { |
| 4404 | 4395 | $('#openai_max_context').attr('max', max_4kmax_128k); |
| 4405 | 4396 | } |
| 4406 | 4397 | oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context); |
| 4407 | 4398 | $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input'); |
| @@ -254,6 +254,7 @@ let power_user = { | ||
| 254 | 254 | }, |
| 255 | 255 | |
| 256 | 256 | reasoning: { |
| 257 | + auto_parse: false, | |
| 257 | 258 | add_to_prompts: false, |
| 258 | 259 | prefix: '<think>\n', |
| 259 | 260 | suffix: '\n</think>', |
| @@ -2917,6 +2918,46 @@ export function flushEphemeralStoppingStrings() { | ||
| 2917 | 2918 | } |
| 2918 | 2919 | |
| 2919 | 2920 | /** |
| 2921 | + * Checks if the generated text should be filtered based on the auto-swipe settings. | |
| 2922 | + * @param {string} text The text to check | |
| 2923 | + * @returns {boolean} If the generated text should be filtered | |
| 2924 | + */ | |
| 2925 | +export function generatedTextFiltered(text) { | |
| 2926 | + /** | |
| 2927 | + * Checks if the given text contains any of the blacklisted words. | |
| 2928 | + * @param {string} text The text to check | |
| 2929 | + * @param {string[]} blacklist The list of blacklisted words | |
| 2930 | + * @param {number} threshold The number of blacklisted words that need to be present to trigger the check | |
| 2931 | + * @returns {boolean} Whether the text contains blacklisted words | |
| 2932 | + */ | |
| 2933 | + function containsBlacklistedWords(text, blacklist, threshold) { | |
| 2934 | + const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi'); | |
| 2935 | + const matches = text.match(regex) || []; | |
| 2936 | + return matches.length >= threshold; | |
| 2937 | + } | |
| 2938 | + | |
| 2939 | + // Make sure a generated text is non-empty | |
| 2940 | + // Otherwise we might get in a loop with a broken API | |
| 2941 | + text = text.trim(); | |
| 2942 | + if (text.length > 0) { | |
| 2943 | + if (power_user.auto_swipe_minimum_length) { | |
| 2944 | + if (text.length < power_user.auto_swipe_minimum_length) { | |
| 2945 | + console.log('Generated text size too small'); | |
| 2946 | + return true; | |
| 2947 | + } | |
| 2948 | + } | |
| 2949 | + if (power_user.auto_swipe_blacklist.length && power_user.auto_swipe_blacklist_threshold) { | |
| 2950 | + if (containsBlacklistedWords(text, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) { | |
| 2951 | + console.log('Generated text has blacklisted words'); | |
| 2952 | + return true; | |
| 2953 | + } | |
| 2954 | + } | |
| 2955 | + } | |
| 2956 | + | |
| 2957 | + return false; | |
| 2958 | +} | |
| 2959 | + | |
| 2960 | +/** | |
| 2920 | 2961 | * Gets the custom stopping strings from the power user settings. |
| 2921 | 2962 | * @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings. |
| 2922 | 2963 | * @returns {string[]} An array of custom stopping strings |
| @@ -4072,4 +4113,45 @@ $(document).ready(() => { | ||
| 4072 | 4113 | ], |
| 4073 | 4114 | helpString: 'activates a movingUI preset by name', |
| 4074 | 4115 | })); |
| 4116 | + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | |
| 4117 | + name: 'stop-strings', | |
| 4118 | + aliases: ['stopping-strings', 'custom-stopping-strings', 'custom-stop-strings'], | |
| 4119 | + helpString: ` | |
| 4120 | + <div> | |
| 4121 | + Sets a list of custom stopping strings. Gets the list if no value is provided. | |
| 4122 | + </div> | |
| 4123 | + <div> | |
| 4124 | + <strong>Examples:</strong> | |
| 4125 | + </div> | |
| 4126 | + <ul> | |
| 4127 | + <li>Value must be a JSON-serialized array: <pre><code class="language-stscript">/stop-strings ["goodbye", "farewell"]</code></pre></li> | |
| 4128 | + <li>Pipe characters must be escaped with a backslash: <pre><code class="language-stscript">/stop-strings ["left\\|right"]</code></pre></li> | |
| 4129 | + </ul> | |
| 4130 | + `, | |
| 4131 | + returns: ARGUMENT_TYPE.LIST, | |
| 4132 | + unnamedArgumentList: [ | |
| 4133 | + SlashCommandArgument.fromProps({ | |
| 4134 | + description: 'list of strings', | |
| 4135 | + typeList: [ARGUMENT_TYPE.LIST], | |
| 4136 | + acceptsMultiple: false, | |
| 4137 | + isRequired: false, | |
| 4138 | + }), | |
| 4139 | + ], | |
| 4140 | + callback: (_, value) => { | |
| 4141 | + if (String(value ?? '').trim()) { | |
| 4142 | + const parsedValue = ((x) => { try { return JSON.parse(x.toString()); } catch { return null; } })(value); | |
| 4143 | + if (!parsedValue || !Array.isArray(parsedValue)) { | |
| 4144 | + throw new Error('Invalid list format. The value must be a JSON-serialized array of strings.'); | |
| 4145 | + } | |
| 4146 | + parsedValue.forEach((item, index) => { | |
| 4147 | + parsedValue[index] = String(item); | |
| 4148 | + }); | |
| 4149 | + power_user.custom_stopping_strings = JSON.stringify(parsedValue); | |
| 4150 | + $('#custom_stopping_strings').val(power_user.custom_stopping_strings); | |
| 4151 | + saveSettingsDebounced(); | |
| 4152 | + } | |
| 4153 | + | |
| 4154 | + return power_user.custom_stopping_strings; | |
| 4155 | + }, | |
| 4156 | + })); | |
| 4075 | 4157 | }); |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { chat, closeMessageEditor, event_types, eventSource, saveChatConditional, saveSettingsDebounced, substituteParams, updateMessageBlock } from '../script.js'; |
| 2 | +import { getRegexedString, regex_placement } from './extensions/regex/engine.js'; | |
| 2 | 3 | import { t } from './i18n.js'; |
| 3 | 4 | import { MacrosParser } from './macros.js'; |
| 4 | 5 | import { Popup } from './popup.js'; |
| @@ -7,7 +8,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js'; | ||
| 7 | 8 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; |
| 8 | 9 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 9 | 10 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; |
| 10 | 11 | import { copyText, escapeRegex, isFalseBoolean } from './utils.js'; |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * Gets a message from a jQuery element. |
| @@ -49,11 +50,12 @@ export class PromptReasoning { | ||
| 49 | 50 | * Add reasoning to a message according to the power user settings. |
| 50 | 51 | * @param {string} content Message content |
| 51 | 52 | * @param {string} reasoning Message reasoning |
| 53 | + * @param {boolean} isPrefix Whether this is the last message prefix | |
| 52 | 54 | * @returns {string} Message content with reasoning |
| 53 | 55 | */ |
| 54 | 56 | addToMessage(content, reasoning, isPrefix) { |
| 55 | 57 | // Disabled or reached limit of additions |
| 56 | 58 | if (!isPrefix && (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions)) { |
| 57 | 59 | return content; |
| 58 | 60 | } |
| 59 | 61 | |
| @@ -70,6 +72,11 @@ export class PromptReasoning { | ||
| 70 | 72 | const separator = substituteParams(power_user.reasoning.separator || ''); |
| 71 | 73 | const suffix = substituteParams(power_user.reasoning.suffix || ''); |
| 72 | 74 | |
| 75 | + // Combine parts with reasoning only | |
| 76 | + if (isPrefix && !content) { | |
| 77 | + return `${prefix}${reasoning}`; | |
| 78 | + } | |
| 79 | + | |
| 73 | 80 | // Combine parts with reasoning and content |
| 74 | 81 | return `${prefix}${reasoning}${suffix}${separator}${content}`; |
| 75 | 82 | } |
| @@ -105,11 +112,18 @@ function loadReasoningSettings() { | ||
| 105 | 112 | power_user.reasoning.max_additions = Number($(this).val()); |
| 106 | 113 | saveSettingsDebounced(); |
| 107 | 114 | }); |
| 115 | + | |
| 116 | + $('#reasoning_auto_parse').prop('checked', power_user.reasoning.auto_parse); | |
| 117 | + $('#reasoning_auto_parse').on('change', function () { | |
| 118 | + power_user.reasoning.auto_parse = !!$(this).prop('checked'); | |
| 119 | + saveSettingsDebounced(); | |
| 120 | + }); | |
| 108 | 121 | } |
| 109 | 122 | |
| 110 | 123 | function registerReasoningSlashCommands() { |
| 111 | 124 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 112 | 125 | name: 'reasoning-get', |
| 126 | + aliases: ['get-reasoning'], | |
| 113 | 127 | returns: ARGUMENT_TYPE.STRING, |
| 114 | 128 | helpString: t`Get the contents of a reasoning block of a message. Returns an empty string if the message does not have a reasoning block.`, |
| 115 | 129 | unnamedArgumentList: [ |
| @@ -129,6 +143,7 @@ function registerReasoningSlashCommands() { | ||
| 129 | 143 | |
| 130 | 144 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 131 | 145 | name: 'reasoning-set', |
| 146 | + aliases: ['set-reasoning'], | |
| 132 | 147 | returns: ARGUMENT_TYPE.STRING, |
| 133 | 148 | helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`, |
| 134 | 149 | namedArgumentList: [ |
| @@ -146,7 +161,7 @@ function registerReasoningSlashCommands() { | ||
| 146 | 161 | }), |
| 147 | 162 | ], |
| 148 | 163 | callback: async (args, value) => { |
| 149 | 164 | const messageId = !isNaN(Number(args[0].at)) ? Number(args[0].at) : chat.length - 1; |
| 150 | 165 | const message = chat[messageId]; |
| 151 | 166 | if (!message?.extra) { |
| 152 | 167 | return ''; |
| @@ -160,6 +175,50 @@ function registerReasoningSlashCommands() { | ||
| 160 | 175 | return message.extra.reasoning; |
| 161 | 176 | }, |
| 162 | 177 | })); |
| 178 | + | |
| 179 | + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | |
| 180 | + name: 'reasoning-parse', | |
| 181 | + aliases: ['parse-reasoning'], | |
| 182 | + returns: 'reasoning string', | |
| 183 | + helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`, | |
| 184 | + namedArgumentList: [ | |
| 185 | + SlashCommandNamedArgument.fromProps({ | |
| 186 | + name: 'regex', | |
| 187 | + description: 'Whether to apply regex scripts to the reasoning content.', | |
| 188 | + typeList: [ARGUMENT_TYPE.BOOLEAN], | |
| 189 | + defaultValue: 'true', | |
| 190 | + isRequired: false, | |
| 191 | + enumProvider: commonEnumProviders.boolean('trueFalse'), | |
| 192 | + }), | |
| 193 | + ], | |
| 194 | + unnamedArgumentList: [ | |
| 195 | + SlashCommandArgument.fromProps({ | |
| 196 | + description: 'input string', | |
| 197 | + typeList: [ARGUMENT_TYPE.STRING], | |
| 198 | + }), | |
| 199 | + ], | |
| 200 | + callback: (args, value) => { | |
| 201 | + if (!value) { | |
| 202 | + return ''; | |
| 203 | + } | |
| 204 | + | |
| 205 | + if (!power_user.reasoning.prefix || !power_user.reasoning.suffix) { | |
| 206 | + toastr.warning(t`Both prefix and suffix must be set in the Reasoning Formatting settings.`); | |
| 207 | + return String(value); | |
| 208 | + } | |
| 209 | + | |
| 210 | + const parsedReasoning = parseReasoningFromString(String(value)); | |
| 211 | + | |
| 212 | + if (!parsedReasoning) { | |
| 213 | + return ''; | |
| 214 | + } | |
| 215 | + | |
| 216 | + const applyRegex = !isFalseBoolean(String(args.regex ?? '')); | |
| 217 | + return applyRegex | |
| 218 | + ? getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING) | |
| 219 | + : parsedReasoning.reasoning; | |
| 220 | + }, | |
| 221 | + })); | |
| 163 | 222 | } |
| 164 | 223 | |
| 165 | 224 | function registerReasoningMacros() { |
| @@ -224,7 +283,7 @@ function setReasoningEventHandlers(){ | ||
| 224 | 283 | } |
| 225 | 284 | |
| 226 | 285 | const textarea = messageBlock.find('.reasoning_edit_textarea'); |
| 227 | 286 | const reasoning = getRegexedString(String(textarea.val()), regex_placement.REASONING, { isEdit: true }); |
| 228 | 287 | message.extra.reasoning = reasoning; |
| 229 | 288 | await saveChatConditional(); |
| 230 | 289 | updateMessageBlock(messageId, message); |
| @@ -289,9 +348,101 @@ function setReasoningEventHandlers(){ | ||
| 289 | 348 | }); |
| 290 | 349 | } |
| 291 | 350 | |
| 351 | +/** | |
| 352 | + * Parses reasoning from a string using the power user reasoning settings. | |
| 353 | + * @typedef {Object} ParsedReasoning | |
| 354 | + * @property {string} reasoning Reasoning block | |
| 355 | + * @property {string} content Message content | |
| 356 | + * @param {string} str Content of the message | |
| 357 | + * @returns {ParsedReasoning|null} Parsed reasoning block and message content | |
| 358 | + */ | |
| 359 | +function parseReasoningFromString(str) { | |
| 360 | + // Both prefix and suffix must be defined | |
| 361 | + if (!power_user.reasoning.prefix || !power_user.reasoning.suffix) { | |
| 362 | + return null; | |
| 363 | + } | |
| 364 | + | |
| 365 | + try { | |
| 366 | + const regex = new RegExp(`${escapeRegex(power_user.reasoning.prefix)}(.*?)${escapeRegex(power_user.reasoning.suffix)}`, 's'); | |
| 367 | + | |
| 368 | + let didReplace = false; | |
| 369 | + let reasoning = ''; | |
| 370 | + let content = String(str).replace(regex, (_match, captureGroup) => { | |
| 371 | + didReplace = true; | |
| 372 | + reasoning = captureGroup; | |
| 373 | + return ''; | |
| 374 | + }); | |
| 375 | + | |
| 376 | + if (didReplace && power_user.trim_spaces) { | |
| 377 | + reasoning = reasoning.trim(); | |
| 378 | + content = content.trim(); | |
| 379 | + } | |
| 380 | + | |
| 381 | + return { reasoning, content }; | |
| 382 | + } catch (error) { | |
| 383 | + console.error('[Reasoning] Error parsing reasoning block', error); | |
| 384 | + return null; | |
| 385 | + } | |
| 386 | +} | |
| 387 | + | |
| 388 | +function registerReasoningAppEvents() { | |
| 389 | + eventSource.makeFirst(event_types.MESSAGE_RECEIVED, (/** @type {number} */ idx) => { | |
| 390 | + if (!power_user.reasoning.auto_parse) { | |
| 391 | + return; | |
| 392 | + } | |
| 393 | + | |
| 394 | + console.debug('[Reasoning] Auto-parsing reasoning block for message', idx); | |
| 395 | + const message = chat[idx]; | |
| 396 | + | |
| 397 | + if (!message) { | |
| 398 | + console.warn('[Reasoning] Message not found', idx); | |
| 399 | + return null; | |
| 400 | + } | |
| 401 | + | |
| 402 | + if (!message.mes || message.mes === '...') { | |
| 403 | + console.debug('[Reasoning] Message content is empty or a placeholder', idx); | |
| 404 | + return null; | |
| 405 | + } | |
| 406 | + | |
| 407 | + const parsedReasoning = parseReasoningFromString(message.mes); | |
| 408 | + | |
| 409 | + // No reasoning block found | |
| 410 | + if (!parsedReasoning) { | |
| 411 | + return; | |
| 412 | + } | |
| 413 | + | |
| 414 | + // Make sure the message has an extra object | |
| 415 | + if (!message.extra || typeof message.extra !== 'object') { | |
| 416 | + message.extra = {}; | |
| 417 | + } | |
| 418 | + | |
| 419 | + const contentUpdated = !!parsedReasoning.reasoning || parsedReasoning.content !== message.mes; | |
| 420 | + | |
| 421 | + // If reasoning was found, add it to the message | |
| 422 | + if (parsedReasoning.reasoning) { | |
| 423 | + message.extra.reasoning = getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING); | |
| 424 | + } | |
| 425 | + | |
| 426 | + // Update the message text if it was changed | |
| 427 | + if (parsedReasoning.content !== message.mes) { | |
| 428 | + message.mes = parsedReasoning.content; | |
| 429 | + } | |
| 430 | + | |
| 431 | + // Find if a message already exists in DOM and must be updated | |
| 432 | + if (contentUpdated) { | |
| 433 | + const messageRendered = document.querySelector(`.mes[mesid="${idx}"]`) !== null; | |
| 434 | + if (messageRendered) { | |
| 435 | + console.debug('[Reasoning] Updating message block', idx); | |
| 436 | + updateMessageBlock(idx, message); | |
| 437 | + } | |
| 438 | + } | |
| 439 | + }); | |
| 440 | +} | |
| 441 | + | |
| 292 | 442 | export function initReasoning() { |
| 293 | 443 | loadReasoningSettings(); |
| 294 | 444 | setReasoningEventHandlers(); |
| 295 | 445 | registerReasoningSlashCommands(); |
| 296 | 446 | registerReasoningMacros(); |
| 447 | + registerReasoningAppEvents(); | |
| 297 | 448 | } |
| @@ -42,6 +42,7 @@ import { | ||
| 42 | 42 | showMoreMessages, |
| 43 | 43 | stopGeneration, |
| 44 | 44 | substituteParams, |
| 45 | + syncCurrentSwipeInfoExtras, | |
| 45 | 46 | system_avatar, |
| 46 | 47 | system_message_types, |
| 47 | 48 | this_chid, |
| @@ -2870,8 +2871,11 @@ async function addSwipeCallback(args, value) { | ||
| 2870 | 2871 | const newSwipeId = lastMessage.swipes.length - 1; |
| 2871 | 2872 | |
| 2872 | 2873 | if (isTrueBoolean(args.switch)) { |
| 2874 | + // Make sure ad-hoc changes to extras are saved before swiping away | |
| 2875 | + syncCurrentSwipeInfoExtras(); | |
| 2873 | 2876 | lastMessage.swipe_id = newSwipeId; |
| 2874 | 2877 | lastMessage.mes = lastMessage.swipes[newSwipeId]; |
| 2878 | + lastMessage.extra = structuredClone(lastMessage.swipe_info?.[newSwipeId]?.extra ?? lastMessage.extra ?? {}); | |
| 2875 | 2879 | } |
| 2876 | 2880 | |
| 2877 | 2881 | await saveChatConditional(); |
| @@ -69,6 +69,7 @@ import { textgenerationwebui_settings } from './textgen-settings.js'; | ||
| 69 | 69 | import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js'; |
| 70 | 70 | import { ToolManager } from './tool-calling.js'; |
| 71 | 71 | import { timestampToMoment, uuidv4 } from './utils.js'; |
| 72 | +import { getGlobalVariable, getLocalVariable, setGlobalVariable, setLocalVariable } from './variables.js'; | |
| 72 | 73 | |
| 73 | 74 | export function getContext() { |
| 74 | 75 | return { |
| @@ -175,6 +176,16 @@ export function getContext() { | ||
| 175 | 176 | humanizedDateTime, |
| 176 | 177 | updateMessageBlock, |
| 177 | 178 | appendMediaToMessage, |
| 179 | + variables: { | |
| 180 | + local: { | |
| 181 | + get: getLocalVariable, | |
| 182 | + set: setLocalVariable, | |
| 183 | + }, | |
| 184 | + global: { | |
| 185 | + get: getGlobalVariable, | |
| 186 | + set: setGlobalVariable, | |
| 187 | + }, | |
| 188 | + }, | |
| 178 | 189 | }; |
| 179 | 190 | } |
| 180 | 191 | |
| @@ -54,6 +54,12 @@ const OPENROUTER_PROVIDERS = [ | ||
| 54 | 54 | 'xAI', |
| 55 | 55 | 'Cloudflare', |
| 56 | 56 | 'SF Compute', |
| 57 | + 'Minimax', | |
| 58 | + 'Nineteen', | |
| 59 | + 'Liquid', | |
| 60 | + 'Nebius', | |
| 61 | + 'Chutes', | |
| 62 | + 'Kluster', | |
| 57 | 63 | '01.AI', |
| 58 | 64 | 'HuggingFace', |
| 59 | 65 | 'Mancer', |
| @@ -501,7 +501,7 @@ export function loadTextGenSettings(data, loadedSettings) { | ||
| 501 | 501 | for (const [type, selector] of Object.entries(SERVER_INPUTS)) { |
| 502 | 502 | const control = $(selector); |
| 503 | 503 | control.val(settings.server_urls[type] ?? '').on('input', function () { |
| 504 | 504 | settings.server_urls[type] = String($(this).val()).trim(); |
| 505 | 505 | saveSettingsDebounced(); |
| 506 | 506 | }); |
| 507 | 507 | } |
| @@ -679,6 +679,9 @@ export function getTokenizerModel() { | ||
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | if (oai_settings.chat_completion_source === chat_completion_sources.PERPLEXITY) { |
| 682 | + if (oai_settings.perplexity_model.includes('sonar-reasoning')) { | |
| 683 | + return deepseekTokenizer; | |
| 684 | + } | |
| 682 | 685 | if (oai_settings.perplexity_model.includes('llama-3') || oai_settings.perplexity_model.includes('llama3')) { |
| 683 | 686 | return llama3Tokenizer; |
| 684 | 687 | } |
| @@ -1733,17 +1733,17 @@ export function hasAnimation(control) { | ||
| 1733 | 1733 | |
| 1734 | 1734 | /** |
| 1735 | 1735 | * Run an action once an animation on a control ends. If the control has no animation, the action will be executed immediately. |
| 1736 | - * | |
| 1736 | + * The action will be executed after the animation ends or after the timeout, whichever comes first. | |
| 1737 | 1737 | * @param {HTMLElement} control - The control element to listen for animation end event |
| 1738 | 1738 | * @param {(control:*?) => void} callback - The callback function to be executed when the animation ends |
| 1739 | + * @param {number} [timeout=500] - The timeout in milliseconds to wait for the animation to end before executing the callback | |
| 1739 | 1740 | */ |
| 1740 | 1741 | export function runAfterAnimation(control, callback, timeout = 500) { |
| 1741 | 1742 | if (hasAnimation(control)) { |
| 1742 | - const onAnimationEnd = () => { | |
| 1743 | + Promise.race([ | |
| 1743 | - control.removeEventListener('animationend', onAnimationEnd); | |
| 1744 | + new Promise((r) => setTimeout(r, timeout)), // Fallback timeout | |
| 1744 | - callback(control); | |
| 1745 | + new Promise((r) => control.addEventListener('animationend', r, { once: true })), | |
| 1745 | - }; | |
| 1746 | + ]).finally(() => callback(control)); | |
| 1746 | - control.addEventListener('animationend', onAnimationEnd); | |
| 1747 | 1747 | } else { |
| 1748 | 1748 | callback(control); |
| 1749 | 1749 | } |
| @@ -19,7 +19,7 @@ import { isFalseBoolean, convertValueType, isTrueBoolean } from './utils.js'; | ||
| 19 | 19 | |
| 20 | 20 | const MAX_LOOPS = 100; |
| 21 | 21 | |
| 22 | 22 | export function getLocalVariable(name, args = {}) { |
| 23 | 23 | if (!chat_metadata.variables) { |
| 24 | 24 | chat_metadata.variables = {}; |
| 25 | 25 | } |
| @@ -45,7 +45,7 @@ function getLocalVariable(name, args = {}) { | ||
| 45 | 45 | return (localVariable?.trim?.() === '' || isNaN(Number(localVariable))) ? (localVariable || '') : Number(localVariable); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | export function setLocalVariable(name, value, args = {}) { |
| 49 | 49 | if (!name) { |
| 50 | 50 | throw new Error('Variable name cannot be empty or undefined.'); |
| 51 | 51 | } |
| @@ -80,7 +80,7 @@ function setLocalVariable(name, value, args = {}) { | ||
| 80 | 80 | return value; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | export function getGlobalVariable(name, args = {}) { |
| 84 | 84 | let globalVariable = extension_settings.variables.global[args.key ?? name]; |
| 85 | 85 | if (args.index !== undefined) { |
| 86 | 86 | try { |
| @@ -102,7 +102,7 @@ function getGlobalVariable(name, args = {}) { | ||
| 102 | 102 | return (globalVariable?.trim?.() === '' || isNaN(Number(globalVariable))) ? (globalVariable || '') : Number(globalVariable); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | export function setGlobalVariable(name, value, args = {}) { |
| 106 | 106 | if (!name) { |
| 107 | 107 | throw new Error('Variable name cannot be empty or undefined.'); |
| 108 | 108 | } |
| @@ -399,6 +399,11 @@ input[type='checkbox']:focus-visible { | ||
| 399 | 399 | color: var(--SmartThemeEmColor); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | +.mes_text q i, | |
| 403 | +.mes_text q em { | |
| 404 | + color: inherit; | |
| 405 | +} | |
| 406 | + | |
| 402 | 407 | .mes_text u, |
| 403 | 408 | .mes_reasoning u { |
| 404 | 409 | color: var(--SmartThemeUnderlineColor); |
| @@ -533,6 +533,7 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => { | ||
| 533 | 533 | |
| 534 | 534 | comfy.post('/generate', jsonParser, async (request, response) => { |
| 535 | 535 | try { |
| 536 | + let item; | |
| 536 | 537 | const url = new URL(urlJoin(request.body.url, '/prompt')); |
| 537 | 538 | |
| 538 | 539 | const controller = new AbortController(); |
| @@ -557,7 +558,6 @@ comfy.post('/generate', jsonParser, async (request, response) => { | ||
| 557 | 558 | /** @type {any} */ |
| 558 | 559 | const data = await promptResult.json(); |
| 559 | 560 | const id = data.prompt_id; |
| 560 | - let item; | |
| 561 | 561 | const historyUrl = new URL(urlJoin(request.body.url, '/history')); |
| 562 | 562 | while (true) { |
| 563 | 563 | const result = await fetch(historyUrl); |