Merge pull request #1594 from valadaptive/generate-cleanups-3

Clean up Generate(), part 3
This commit is contained in:
Cohee 2024-01-01 18:33:27 +02:00 committed by GitHub
commit 7b3ea57ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 981 additions and 1009 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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.
*/

View File

@ -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()) {

View File

@ -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;
}

View File

@ -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]';