From 89ca8329b78c4a78801c42139f94aefb7e0fa5b6 Mon Sep 17 00:00:00 2001 From: splitclover Date: Tue, 30 Jul 2024 16:07:46 +0200 Subject: [PATCH] Added event after generate data, export sendStreamingRequest and sendGenerationRequest --- public/script.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index f84163bae..b402beb4e 100644 --- a/public/script.js +++ b/public/script.js @@ -439,6 +439,7 @@ export const event_types = { GROUP_CHAT_CREATED: 'group_chat_created', GENERATE_BEFORE_COMBINE_PROMPTS: 'generate_before_combine_prompts', GENERATE_AFTER_COMBINE_PROMPTS: 'generate_after_combine_prompts', + GENERATE_AFTER_DATA: 'generate_after_data', GROUP_MEMBER_DRAFTED: 'group_member_drafted', WORLD_INFO_ACTIVATED: 'world_info_activated', TEXT_COMPLETION_SETTINGS_READY: 'text_completion_settings_ready', @@ -4215,6 +4216,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro } } + await eventSource.emit(event_types.GENERATE_AFTER_DATA, generate_data); + if (dryRun) { generatedPromptCache = ''; return Promise.resolve(); @@ -5078,7 +5081,7 @@ function setInContextMessages(lastmsg, type) { * @param {object} data Generation data * @returns {Promise} Response data from the API */ -async function sendGenerationRequest(type, data) { +export async function sendGenerationRequest(type, data) { if (main_api === 'openai') { return await sendOpenAIRequest(type, data.prompt, abortController.signal); } @@ -5110,7 +5113,7 @@ async function sendGenerationRequest(type, data) { * @param {object} data Generation data * @returns {Promise} Streaming generator */ -async function sendStreamingRequest(type, data) { +export async function sendStreamingRequest(type, data) { if (abortController?.signal?.aborted) { throw new Error('Generation was aborted.'); } @@ -7921,6 +7924,8 @@ window['SillyTavern'].getContext = function () { eventTypes: event_types, addOneMessage: addOneMessage, generate: Generate, + sendStreamingRequest: sendStreamingRequest, + sendGenerationRequest: sendGenerationRequest, stopGeneration: stopGeneration, getTokenCount: getTokenCount, extensionPrompts: extension_prompts,