Refactor and simplify setup method for prompt manager.

This commit is contained in:
maver 2023-07-24 17:30:31 +02:00
parent ad6575887a
commit 63d224d8af
2 changed files with 17 additions and 28 deletions

View File

@ -79,7 +79,7 @@ import {
import {
setOpenAIMessageExamples,
setOpenAIMessages,
setupOpenAIPromptManager,
setupChatCompletionPromptManager,
prepareOpenAIMessages,
sendOpenAIRequest,
loadOpenAISettings,
@ -90,8 +90,6 @@ import {
openai_messages_count,
getTokenCountOpenAI,
chat_completion_sources,
setupWindowAiPromptManager,
setupClaudePromptManager,
getTokenizerModel,
getChatCompletionModel,
} from "./scripts/openai.js";
@ -4562,20 +4560,13 @@ function changeMainAPI() {
}
switch (oai_settings.chat_completion_source) {
case chat_completion_sources.OPENAI:
setupOpenAIPromptManager(oai_settings);
break;
case chat_completion_sources.CLAUDE:
setupClaudePromptManager(oai_settings);
break;
case chat_completion_sources.WINDOWAI:
setupWindowAiPromptManager(oai_settings);
break;
case chat_completion_sources.OPENROUTER:
setupWindowAiPromptManager(oai_settings);
break;
case chat_completion_sources.SCALE:
setupWindowAiPromptManager(oai_settings);
case chat_completion_sources.OPENROUTER:
case chat_completion_sources.WINDOWAI:
case chat_completion_sources.CLAUDE:
case chat_completion_sources.OPENAI:
default:
setupChatCompletionPromptManager(oai_settings);
break;
}
}

View File

@ -61,9 +61,7 @@ export {
loadOpenAISettings,
setOpenAIMessages,
setOpenAIMessageExamples,
setupOpenAIPromptManager,
setupClaudePromptManager,
setupWindowAiPromptManager,
setupChatCompletionPromptManager,
generateOpenAIPromptCache,
prepareOpenAIMessages,
sendOpenAIRequest,
@ -294,9 +292,15 @@ function setOpenAIMessageExamples(mesExamplesArray) {
}
}
function setupOpenAIPromptManager(openAiSettings) {
/**
* One-time setup for prompt manager module.
*
* @param openAiSettings
* @returns {PromptManagerModule|null}
*/
function setupChatCompletionPromptManager(openAiSettings) {
// Do not set up prompt manager more than once
if (promptManager) return true;
if (promptManager) return promptManager;
promptManager = new PromptManager();
@ -326,14 +330,8 @@ function setupOpenAIPromptManager(openAiSettings) {
promptManager.init(configuration, openAiSettings);
promptManager.render();
}
function setupClaudePromptManager(claudeSettings) {
setupOpenAIPromptManager(claudeSettings);
}
function setupWindowAiPromptManager(windowAiSettings) {
setupOpenAIPromptManager(windowAiSettings);
return promptManager;
}
function generateOpenAIPromptCache() {