From c6eee88cd46d55e339d41e2c010f8bc570866400 Mon Sep 17 00:00:00 2001 From: maver Date: Sun, 28 May 2023 15:55:03 +0200 Subject: [PATCH] Add prompt manager setup --- public/script.js | 2 ++ public/scripts/openai.js | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 64b2dae33..d838ef50b 100644 --- a/public/script.js +++ b/public/script.js @@ -79,6 +79,7 @@ import { import { setOpenAIMessageExamples, setOpenAIMessages, + setupOpenAIPromptManager, prepareOpenAIMessages, sendOpenAIRequest, loadOpenAISettings, @@ -5107,6 +5108,7 @@ async function getSettings(type) { // OpenAI loadOpenAISettings(data, settings); + setupOpenAIPromptManager(settings); // Horde loadHordeSettings(settings); diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 8ab219ad7..0df146ade 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -22,7 +22,14 @@ import { is_send_press, main_api, } from "../script.js"; -import { groups, selected_group } from "./group-chats.js"; +import {groups, selected_group} from "./group-chats.js"; + +import { + defaultPromptManagerSettings, + openAiDefaultPromptLists, + openAiDefaultPrompts, + PromptManagerModule as PromptManager +} from "./PromptManager.js"; import { power_user, @@ -50,6 +57,7 @@ export { loadOpenAISettings, setOpenAIMessages, setOpenAIMessageExamples, + setupOpenAIPromptManager, generateOpenAIPromptCache, prepareOpenAIMessages, sendOpenAIRequest, @@ -188,6 +196,8 @@ export function getTokenCountOpenAI(text) { return countTokens(message, true); } +let promptManager = null; + function validateReverseProxy() { if (!oai_settings.reverse_proxy) { return; @@ -261,6 +271,25 @@ function setOpenAIMessageExamples(mesExamplesArray) { } } +function setupOpenAIPromptManager(settings) { + promptManager = new PromptManager(); + const configuration = { + prefix: 'openai_', + containerIdentifier: 'openai_prompt_manager', + listIdentifier: 'openai_prompt_manager_list', + draggable: true + }; + + promptManager.saveServiceSettings = () => { + saveSettingsDebounced(); + } + + promptManager.init(configuration, settings, default_settings); + promptManager.render(); + + +} + function generateOpenAIPromptCache() { openai_msgs = openai_msgs.reverse(); openai_msgs.forEach(function (msg, i, arr) {