mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Refactor and simplify setup method for prompt manager.
This commit is contained in:
		| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user