Refactor and simplify setup method for prompt manager.
This commit is contained in:
parent
ad6575887a
commit
63d224d8af
|
@ -79,7 +79,7 @@ import {
|
||||||
import {
|
import {
|
||||||
setOpenAIMessageExamples,
|
setOpenAIMessageExamples,
|
||||||
setOpenAIMessages,
|
setOpenAIMessages,
|
||||||
setupOpenAIPromptManager,
|
setupChatCompletionPromptManager,
|
||||||
prepareOpenAIMessages,
|
prepareOpenAIMessages,
|
||||||
sendOpenAIRequest,
|
sendOpenAIRequest,
|
||||||
loadOpenAISettings,
|
loadOpenAISettings,
|
||||||
|
@ -90,8 +90,6 @@ import {
|
||||||
openai_messages_count,
|
openai_messages_count,
|
||||||
getTokenCountOpenAI,
|
getTokenCountOpenAI,
|
||||||
chat_completion_sources,
|
chat_completion_sources,
|
||||||
setupWindowAiPromptManager,
|
|
||||||
setupClaudePromptManager,
|
|
||||||
getTokenizerModel,
|
getTokenizerModel,
|
||||||
getChatCompletionModel,
|
getChatCompletionModel,
|
||||||
} from "./scripts/openai.js";
|
} from "./scripts/openai.js";
|
||||||
|
@ -4562,20 +4560,13 @@ function changeMainAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (oai_settings.chat_completion_source) {
|
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:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,9 +61,7 @@ export {
|
||||||
loadOpenAISettings,
|
loadOpenAISettings,
|
||||||
setOpenAIMessages,
|
setOpenAIMessages,
|
||||||
setOpenAIMessageExamples,
|
setOpenAIMessageExamples,
|
||||||
setupOpenAIPromptManager,
|
setupChatCompletionPromptManager,
|
||||||
setupClaudePromptManager,
|
|
||||||
setupWindowAiPromptManager,
|
|
||||||
generateOpenAIPromptCache,
|
generateOpenAIPromptCache,
|
||||||
prepareOpenAIMessages,
|
prepareOpenAIMessages,
|
||||||
sendOpenAIRequest,
|
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
|
// Do not set up prompt manager more than once
|
||||||
if (promptManager) return true;
|
if (promptManager) return promptManager;
|
||||||
|
|
||||||
promptManager = new PromptManager();
|
promptManager = new PromptManager();
|
||||||
|
|
||||||
|
@ -326,14 +330,8 @@ function setupOpenAIPromptManager(openAiSettings) {
|
||||||
|
|
||||||
promptManager.init(configuration, openAiSettings);
|
promptManager.init(configuration, openAiSettings);
|
||||||
promptManager.render();
|
promptManager.render();
|
||||||
}
|
|
||||||
|
|
||||||
function setupClaudePromptManager(claudeSettings) {
|
return promptManager;
|
||||||
setupOpenAIPromptManager(claudeSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupWindowAiPromptManager(windowAiSettings) {
|
|
||||||
setupOpenAIPromptManager(windowAiSettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateOpenAIPromptCache() {
|
function generateOpenAIPromptCache() {
|
||||||
|
|
Loading…
Reference in New Issue