mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #1594 from valadaptive/generate-cleanups-3
Clean up Generate(), part 3
This commit is contained in:
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);
|
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.
|
* Empties, then re-assembles the container containing the prompt list.
|
||||||
*/
|
*/
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
Generate,
|
|
||||||
characters,
|
characters,
|
||||||
online_status,
|
online_status,
|
||||||
main_api,
|
main_api,
|
||||||
@@ -18,6 +17,7 @@ import {
|
|||||||
menu_type,
|
menu_type,
|
||||||
substituteParams,
|
substituteParams,
|
||||||
callPopup,
|
callPopup,
|
||||||
|
sendTextareaMessage,
|
||||||
} from '../script.js';
|
} from '../script.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -954,9 +954,9 @@ export function initRossMods() {
|
|||||||
//Enter to send when send_textarea in focus
|
//Enter to send when send_textarea in focus
|
||||||
if ($(':focus').attr('id') === 'send_textarea') {
|
if ($(':focus').attr('id') === 'send_textarea') {
|
||||||
const sendOnEnter = shouldSendOnEnter();
|
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();
|
event.preventDefault();
|
||||||
Generate();
|
sendTextareaMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($(':focus').attr('id') === 'dialogue_popup_input' && !isMobile()) {
|
if ($(':focus').attr('id') === 'dialogue_popup_input' && !isMobile()) {
|
||||||
|
@@ -482,7 +482,10 @@ function setOpenAIMessageExamples(mesExamplesArray) {
|
|||||||
*/
|
*/
|
||||||
function setupChatCompletionPromptManager(openAiSettings) {
|
function setupChatCompletionPromptManager(openAiSettings) {
|
||||||
// Do not set up prompt manager more than once
|
// Do not set up prompt manager more than once
|
||||||
if (promptManager) return promptManager;
|
if (promptManager) {
|
||||||
|
promptManager.render(false);
|
||||||
|
return promptManager;
|
||||||
|
}
|
||||||
|
|
||||||
promptManager = new PromptManager();
|
promptManager = new PromptManager();
|
||||||
|
|
||||||
@@ -1031,9 +1034,6 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
|
|||||||
prompts.set(jbReplacement, prompts.index('jailbreak'));
|
prompts.set(jbReplacement, prompts.index('jailbreak'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow subscribers to manipulate the prompts object
|
|
||||||
eventSource.emit(event_types.OAI_BEFORE_CHATCOMPLETION, prompts);
|
|
||||||
|
|
||||||
return prompts;
|
return prompts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -443,7 +443,7 @@ async function sendMistralAIRequest(request, response) {
|
|||||||
const messages = Array.isArray(request.body.messages) ? request.body.messages : [];
|
const messages = Array.isArray(request.body.messages) ? request.body.messages : [];
|
||||||
const lastMsg = messages[messages.length - 1];
|
const lastMsg = messages[messages.length - 1];
|
||||||
if (messages.length > 0 && lastMsg && (lastMsg.role === 'system' || lastMsg.role === 'assistant')) {
|
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;
|
lastMsg.content = lastMsg.name + ': ' + lastMsg.content;
|
||||||
} else if (lastMsg.role === 'system') {
|
} else if (lastMsg.role === 'system') {
|
||||||
lastMsg.content = '[INST] ' + lastMsg.content + ' [/INST]';
|
lastMsg.content = '[INST] ' + lastMsg.content + ' [/INST]';
|
||||||
|
Reference in New Issue
Block a user