mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-01 11:56:48 +01:00
Merge pull request #1594 from valadaptive/generate-cleanups-3
Clean up Generate(), part 3
This commit is contained in:
commit
7b3ea57ded
1946
public/script.js
1946
public/script.js
File diff suppressed because it is too large
Load Diff
@ -1293,34 +1293,6 @@ class PromptManager {
|
||||
this.log('Updated token usage with ' + this.tokenUsage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates legacy token counts
|
||||
*
|
||||
* @deprecated This might serve no purpose and should be evaluated for removal
|
||||
*
|
||||
* @param {MessageCollection} messages
|
||||
*/
|
||||
populateLegacyTokenCounts(messages) {
|
||||
// Update general token counts
|
||||
const chatHistory = messages.getItemByIdentifier('chatHistory');
|
||||
const startChat = chatHistory?.getCollection()[0]?.getTokens() || 0;
|
||||
const continueNudge = chatHistory?.getCollection().find(message => message.identifier === 'continueNudge')?.getTokens() || 0;
|
||||
|
||||
this.tokenHandler.counts = {
|
||||
...this.tokenHandler.counts,
|
||||
...{
|
||||
'start_chat': startChat,
|
||||
'prompt': 0,
|
||||
'bias': this.tokenHandler.counts.bias ?? 0,
|
||||
'nudge': continueNudge,
|
||||
'jailbreak': this.tokenHandler.counts.jailbreak ?? 0,
|
||||
'impersonate': 0,
|
||||
'examples': this.tokenHandler.counts.dialogueExamples ?? 0,
|
||||
'conversation': this.tokenHandler.counts.chatHistory ?? 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Empties, then re-assembles the container containing the prompt list.
|
||||
*/
|
||||
|
@ -1,5 +1,4 @@
|
||||
import {
|
||||
Generate,
|
||||
characters,
|
||||
online_status,
|
||||
main_api,
|
||||
@ -18,6 +17,7 @@ import {
|
||||
menu_type,
|
||||
substituteParams,
|
||||
callPopup,
|
||||
sendTextareaMessage,
|
||||
} from '../script.js';
|
||||
|
||||
import {
|
||||
@ -954,9 +954,9 @@ export function initRossMods() {
|
||||
//Enter to send when send_textarea in focus
|
||||
if ($(':focus').attr('id') === 'send_textarea') {
|
||||
const sendOnEnter = shouldSendOnEnter();
|
||||
if (!event.shiftKey && !event.ctrlKey && !event.altKey && event.key == 'Enter' && is_send_press == false && sendOnEnter) {
|
||||
if (!event.shiftKey && !event.ctrlKey && !event.altKey && event.key == 'Enter' && sendOnEnter) {
|
||||
event.preventDefault();
|
||||
Generate();
|
||||
sendTextareaMessage();
|
||||
}
|
||||
}
|
||||
if ($(':focus').attr('id') === 'dialogue_popup_input' && !isMobile()) {
|
||||
|
@ -482,7 +482,10 @@ function setOpenAIMessageExamples(mesExamplesArray) {
|
||||
*/
|
||||
function setupChatCompletionPromptManager(openAiSettings) {
|
||||
// Do not set up prompt manager more than once
|
||||
if (promptManager) return promptManager;
|
||||
if (promptManager) {
|
||||
promptManager.render(false);
|
||||
return promptManager;
|
||||
}
|
||||
|
||||
promptManager = new PromptManager();
|
||||
|
||||
@ -1031,9 +1034,6 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
|
||||
prompts.set(jbReplacement, prompts.index('jailbreak'));
|
||||
}
|
||||
|
||||
// Allow subscribers to manipulate the prompts object
|
||||
eventSource.emit(event_types.OAI_BEFORE_CHATCOMPLETION, prompts);
|
||||
|
||||
return prompts;
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ async function sendMistralAIRequest(request, response) {
|
||||
const messages = Array.isArray(request.body.messages) ? request.body.messages : [];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
if (messages.length > 0 && lastMsg && (lastMsg.role === 'system' || lastMsg.role === 'assistant')) {
|
||||
if (lastMsg.role === 'assistant') {
|
||||
if (lastMsg.role === 'assistant' && lastMsg.name) {
|
||||
lastMsg.content = lastMsg.name + ': ' + lastMsg.content;
|
||||
} else if (lastMsg.role === 'system') {
|
||||
lastMsg.content = '[INST] ' + lastMsg.content + ' [/INST]';
|
||||
|
Loading…
x
Reference in New Issue
Block a user