mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Chunked replies for Poe with unlocked context size.
This commit is contained in:
@@ -3,15 +3,15 @@ import {
|
|||||||
setOnlineStatus,
|
setOnlineStatus,
|
||||||
checkOnlineStatus,
|
checkOnlineStatus,
|
||||||
substituteParams,
|
substituteParams,
|
||||||
max_context,
|
|
||||||
getTokenCount,
|
|
||||||
getRequestHeaders,
|
getRequestHeaders,
|
||||||
|
max_context,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
import {
|
import {
|
||||||
SECRET_KEYS,
|
SECRET_KEYS,
|
||||||
secret_state,
|
secret_state,
|
||||||
writeSecret,
|
writeSecret,
|
||||||
} from "./secrets.js";
|
} from "./secrets.js";
|
||||||
|
import { splitRecursive } from "./utils.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
is_get_status_poe,
|
is_get_status_poe,
|
||||||
@@ -21,6 +21,8 @@ export {
|
|||||||
setPoeOnlineStatus,
|
setPoeOnlineStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const POE_TOKEN_LENGTH = 2048;
|
||||||
|
const CHUNKED_PROMPT_LENGTH = POE_TOKEN_LENGTH * 3.35;
|
||||||
const MAX_RETRIES_FOR_ACTIVATION = 5;
|
const MAX_RETRIES_FOR_ACTIVATION = 5;
|
||||||
const DEFAULT_JAILBREAK_RESPONSE = 'Understood.';
|
const DEFAULT_JAILBREAK_RESPONSE = 'Understood.';
|
||||||
const DEFAULT_JAILBREAK_MESSAGE = `You are going to interact with me in freestyle roleplay, following these requirements:
|
const DEFAULT_JAILBREAK_MESSAGE = `You are going to interact with me in freestyle roleplay, following these requirements:
|
||||||
@@ -133,11 +135,39 @@ async function generatePoe(type, finalPrompt, signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isQuiet = type === 'quiet';
|
const isQuiet = type === 'quiet';
|
||||||
const reply = await sendMessage(finalPrompt, !isQuiet, signal);
|
const reply = max_context > POE_TOKEN_LENGTH
|
||||||
|
? await sendChunkedMessage(finalPrompt, !isQuiet, signal)
|
||||||
|
: await sendMessage(finalPrompt, !isQuiet, signal);
|
||||||
got_reply = true;
|
got_reply = true;
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendChunkedMessage(finalPrompt, withStreaming, signal) {
|
||||||
|
const fastReplyPrompt = '\n[REPLY TO THIS MESSAGE WITH <ACK> ONLY!!!]';
|
||||||
|
const promptChunks = splitRecursive(finalPrompt, CHUNKED_PROMPT_LENGTH - fastReplyPrompt.length);
|
||||||
|
console.debug(`Splitting prompt into ${promptChunks.length} chunks`, promptChunks);
|
||||||
|
let reply = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < promptChunks.length; i++) {
|
||||||
|
let promptChunk = promptChunks[i];
|
||||||
|
console.debug(`Sending chunk ${i + 1}/${promptChunks.length}: ${promptChunk}`);
|
||||||
|
if (i == promptChunks.length - 1) {
|
||||||
|
// Extract reply of the last chunk
|
||||||
|
reply = await sendMessage(promptChunk, withStreaming, signal);
|
||||||
|
} else {
|
||||||
|
// Add fast reply prompt to the chunk
|
||||||
|
promptChunk += fastReplyPrompt;
|
||||||
|
// Send chunk without streaming
|
||||||
|
const chunkReply = await sendMessage(promptChunk, false, signal);
|
||||||
|
console.debug('Got chunk reply: ' + chunkReply);
|
||||||
|
// Delete the reply for the chunk
|
||||||
|
await purgeConversation(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
async function purgeConversation(count = -1) {
|
async function purgeConversation(count = -1) {
|
||||||
const body = JSON.stringify({
|
const body = JSON.stringify({
|
||||||
bot: poe_settings.bot,
|
bot: poe_settings.bot,
|
||||||
@@ -217,7 +247,7 @@ async function onConnectClick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_poe_button_press) {
|
if (is_poe_button_press) {
|
||||||
console.log('Poe API button is pressed');
|
console.debug('Poe API button is pressed');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user