mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add token counter for author's notes
This commit is contained in:
@ -1,4 +1,11 @@
|
|||||||
import { chat_metadata, saveSettingsDebounced, this_chid } from "../../../script.js";
|
import {
|
||||||
|
chat_metadata,
|
||||||
|
eventSource,
|
||||||
|
event_types,
|
||||||
|
getTokenCount,
|
||||||
|
saveSettingsDebounced,
|
||||||
|
this_chid,
|
||||||
|
} from "../../../script.js";
|
||||||
import { selected_group } from "../../group-chats.js";
|
import { selected_group } from "../../group-chats.js";
|
||||||
import { ModuleWorkerWrapper, extension_settings, getContext, saveMetadataDebounced } from "../../extensions.js";
|
import { ModuleWorkerWrapper, extension_settings, getContext, saveMetadataDebounced } from "../../extensions.js";
|
||||||
import { registerSlashCommand } from "../../slash-commands.js";
|
import { registerSlashCommand } from "../../slash-commands.js";
|
||||||
@ -66,6 +73,7 @@ function setNotePositionCommand(_, text) {
|
|||||||
|
|
||||||
async function onExtensionFloatingPromptInput() {
|
async function onExtensionFloatingPromptInput() {
|
||||||
chat_metadata[metadata_keys.prompt] = $(this).val();
|
chat_metadata[metadata_keys.prompt] = $(this).val();
|
||||||
|
$('#extension_floating_prompt_token_counter').text(getTokenCount(chat_metadata[metadata_keys.prompt]));
|
||||||
saveMetadataDebounced();
|
saveMetadataDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +101,7 @@ async function onExtensionFloatingPositionInput(e) {
|
|||||||
|
|
||||||
function onExtensionFloatingDefaultInput() {
|
function onExtensionFloatingDefaultInput() {
|
||||||
extension_settings.note.default = $(this).val();
|
extension_settings.note.default = $(this).val();
|
||||||
|
$('#extension_floating_default_token_counter').text(getTokenCount(extension_settings.note.default));
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +182,13 @@ function onANMenuItemClick() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onChatChanged() {
|
||||||
|
const tokenCounter1 = chat_metadata[metadata_keys.prompt] ? getTokenCount(chat_metadata[metadata_keys.prompt]) : 0;
|
||||||
|
const tokenCounter2 = extension_settings.note.default ? getTokenCount(extension_settings.note.default) : 0;
|
||||||
|
$('#extension_floating_prompt_token_counter').text(tokenCounter1);
|
||||||
|
$('#extension_floating_default_token_counter').text(tokenCounter2);
|
||||||
|
}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
function addExtensionsSettings() {
|
function addExtensionsSettings() {
|
||||||
const settingsHtml = `
|
const settingsHtml = `
|
||||||
@ -195,6 +211,7 @@ function onANMenuItemClick() {
|
|||||||
</small>
|
</small>
|
||||||
|
|
||||||
<textarea id="extension_floating_prompt" class="text_pole" rows="8" maxlength="10000"></textarea>
|
<textarea id="extension_floating_prompt" class="text_pole" rows="8" maxlength="10000"></textarea>
|
||||||
|
<div class="extension_token_counter">Tokens: <span id="extension_floating_prompt_token_counter">0</small></div>
|
||||||
|
|
||||||
<div class="floating_prompt_radio_group">
|
<div class="floating_prompt_radio_group">
|
||||||
<label>
|
<label>
|
||||||
@ -228,6 +245,7 @@ function onANMenuItemClick() {
|
|||||||
|
|
||||||
<textarea id="extension_floating_default" class="text_pole" rows="8" maxlength="10000"
|
<textarea id="extension_floating_default" class="text_pole" rows="8" maxlength="10000"
|
||||||
placeholder="Example:\n[Scenario: wacky adventures; Genre: romantic comedy; Style: verbose, creative]"></textarea>
|
placeholder="Example:\n[Scenario: wacky adventures; Genre: romantic comedy; Style: verbose, creative]"></textarea>
|
||||||
|
<div class="extension_token_counter">Tokens: <span id="extension_floating_default_token_counter">0</small></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -265,4 +283,5 @@ function onANMenuItemClick() {
|
|||||||
registerSlashCommand('depth', setNoteDepthCommand, [], "<span class='monospace'>(number)</span> – sets an author's note depth for in-chat positioning", true, true);
|
registerSlashCommand('depth', setNoteDepthCommand, [], "<span class='monospace'>(number)</span> – sets an author's note depth for in-chat positioning", true, true);
|
||||||
registerSlashCommand('freq', setNoteIntervalCommand, ['interval'], "<span class='monospace'>(number)</span> – sets an author's note insertion frequency", true, true);
|
registerSlashCommand('freq', setNoteIntervalCommand, ['interval'], "<span class='monospace'>(number)</span> – sets an author's note insertion frequency", true, true);
|
||||||
registerSlashCommand('pos', setNotePositionCommand, ['position'], "(<span class='monospace'>chat</span> or <span class='monospace'>scenario</span>) – sets an author's note position", true, true);
|
registerSlashCommand('pos', setNotePositionCommand, ['position'], "(<span class='monospace'>chat</span> or <span class='monospace'>scenario</span>) – sets an author's note position", true, true);
|
||||||
|
eventSource.on(event_types.CHAT_CHANGED, onChatChanged);
|
||||||
})();
|
})();
|
||||||
|
@ -1,61 +1,67 @@
|
|||||||
#floatingPrompt {
|
#floatingPrompt {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
max-width: 90svw;
|
max-width: 90svw;
|
||||||
max-height: 90svh;
|
max-height: 90svh;
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
min-height: 100px;
|
min-height: 100px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
border: 1px solid var(--white30a);
|
border: 1px solid var(--white30a);
|
||||||
position: fixed;
|
position: fixed;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
padding-top: 25px;
|
padding-top: 25px;
|
||||||
display: none;
|
display: none;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
box-shadow: 0 0 10px var(--black70a);
|
box-shadow: 0 0 10px var(--black70a);
|
||||||
z-index: 3000;
|
z-index: 3000;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
right: unset;
|
right: unset;
|
||||||
width: calc(((100svw - var(--sheldWidth)) / 2) - 1px);
|
width: calc(((100svw - var(--sheldWidth)) / 2) - 1px);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.floating_prompt_radio_group {
|
.floating_prompt_radio_group {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
#extension_floating_counter {
|
#extension_floating_counter {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: orange;
|
color: orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
.floating_prompt_settings textarea {
|
.extension_token_counter {
|
||||||
font-size: calc(var(--mainFontSize) * 0.9);
|
font-size: calc(var(--mainFontSize) * 0.9);
|
||||||
line-height: 1.2;
|
width: 100%;
|
||||||
}
|
text-align: right;
|
||||||
|
}
|
||||||
#ANClose {
|
|
||||||
height: 15px;
|
.floating_prompt_settings textarea {
|
||||||
aspect-ratio: 1 / 1;
|
font-size: calc(var(--mainFontSize) * 0.9);
|
||||||
font-size: 20px;
|
line-height: 1.2;
|
||||||
opacity: 0.5;
|
}
|
||||||
transition: all 250ms;
|
|
||||||
}
|
#ANClose {
|
||||||
|
height: 15px;
|
||||||
#ANClose:hover {
|
aspect-ratio: 1 / 1;
|
||||||
cursor: pointer;
|
font-size: 20px;
|
||||||
opacity: 1;
|
opacity: 0.5;
|
||||||
}
|
transition: all 250ms;
|
||||||
|
}
|
||||||
.panelControlBar {
|
|
||||||
position: absolute;
|
#ANClose:hover {
|
||||||
right: 5px;
|
cursor: pointer;
|
||||||
top: 5px;
|
opacity: 1;
|
||||||
margin-right: 5px;
|
}
|
||||||
}
|
|
||||||
|
.panelControlBar {
|
||||||
#floatingPrompt .drag-grabber {
|
position: absolute;
|
||||||
position: unset;
|
right: 5px;
|
||||||
}
|
top: 5px;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#floatingPrompt .drag-grabber {
|
||||||
|
position: unset;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user