mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	[WIP} infinity context
This commit is contained in:
		| @@ -107,7 +107,7 @@ import { | |||||||
| } from "./scripts/poe.js"; | } from "./scripts/poe.js"; | ||||||
|  |  | ||||||
| import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence } from "./scripts/utils.js"; | import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence } from "./scripts/utils.js"; | ||||||
| import { extension_settings, loadExtensionSettings } from "./scripts/extensions.js"; | import { extension_settings, loadExtensionSettings, runGenerationInterceptors } from "./scripts/extensions.js"; | ||||||
| import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js"; | import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js"; | ||||||
| import { | import { | ||||||
|     tag_map, |     tag_map, | ||||||
| @@ -1652,6 +1652,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, | |||||||
|     tokens_already_generated = 0; |     tokens_already_generated = 0; | ||||||
|     generation_started = new Date(); |     generation_started = new Date(); | ||||||
|      |      | ||||||
|  |     await runGenerationInterceptors(); | ||||||
|  |  | ||||||
|     const isImpersonate = type == "impersonate"; |     const isImpersonate = type == "impersonate"; | ||||||
|     const isInstruct = power_user.instruct.enabled; |     const isInstruct = power_user.instruct.enabled; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ export { | |||||||
|     getContext, |     getContext, | ||||||
|     getApiUrl, |     getApiUrl, | ||||||
|     loadExtensionSettings, |     loadExtensionSettings, | ||||||
|  |     runGenerationInterceptors, | ||||||
|     defaultRequestArgs, |     defaultRequestArgs, | ||||||
|     modules, |     modules, | ||||||
|     extension_settings, |     extension_settings, | ||||||
| @@ -26,6 +27,7 @@ const extension_settings = { | |||||||
|     dice: {}, |     dice: {}, | ||||||
|     tts: {}, |     tts: {}, | ||||||
|     sd: {}, |     sd: {}, | ||||||
|  |     chromadb: {}, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| let modules = []; | let modules = []; | ||||||
| @@ -317,6 +319,19 @@ async function loadExtensionSettings(settings) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function runGenerationInterceptors() { | ||||||
|  |     for (const manifest of Object.values(manifests)) { | ||||||
|  |         const interceptorKey = manifest.generate_interceptor; | ||||||
|  |         if (typeof window[interceptorKey] === 'function') { | ||||||
|  |             try { | ||||||
|  |                 await window[interceptorKey](); | ||||||
|  |             } catch(e) { | ||||||
|  |                 console.error(`Failed running interceptor for ${manifest.display_name}`, e); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| $(document).ready(async function () { | $(document).ready(async function () { | ||||||
|     setTimeout(function () { addExtensionsButtonAndMenu(); }, 100) |     setTimeout(function () { addExtensionsButtonAndMenu(); }, 100) | ||||||
|     $("#extensions_connect").on('click', connectClickHandler); |     $("#extensions_connect").on('click', connectClickHandler); | ||||||
|   | |||||||
							
								
								
									
										75
									
								
								public/scripts/extensions/infinity-context/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								public/scripts/extensions/infinity-context/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | |||||||
|  | import { | ||||||
|  |     saveSettingsDebounced, | ||||||
|  | } from "../../../script.js"; | ||||||
|  | import { getApiUrl, getContext, extension_settings, defaultRequestArgs } from "../../extensions.js"; | ||||||
|  | export { MODULE_NAME, chromadb_interceptGeneration }; | ||||||
|  |  | ||||||
|  | const MODULE_NAME = 'chromadb'; | ||||||
|  |  | ||||||
|  | const defaultSettings = { | ||||||
|  |     keep_context: 10, | ||||||
|  |     keep_context_min: 1, | ||||||
|  |     keep_context_max: 100, | ||||||
|  |     keep_context_step: 1, | ||||||
|  |  | ||||||
|  |     n_results: 20, | ||||||
|  |     n_results_min: 1, | ||||||
|  |     n_results_max: 100, | ||||||
|  |     n_results_step: 1, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function loadSettings() { | ||||||
|  |     if (Object.keys(extension_settings.chromadb).length === 0) { | ||||||
|  |         Object.assign(extension_settings.chromadb, defaultSettings); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     $('#chromadb_keep_context').val(extension_settings.chromadb.keep_context).trigger('input'); | ||||||
|  |     $('#chromadb_n_results').val(extension_settings.chromadb.n_results).trigger('input'); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function onKeepContextInput() { | ||||||
|  |     extension_settings.chromadb.keep_context = Number($('#chromadb_keep_context').val()); | ||||||
|  |     $('#chromadb_keep_context_value').text(extension_settings.chromadb.keep_context); | ||||||
|  |     saveSettingsDebounced(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function onNResultsInput() { | ||||||
|  |     extension_settings.chromadb.n_results = Number($('#chromadb_n_results').val()); | ||||||
|  |     $('#chromadb_n_results_value').text(extension_settings.chromadb.n_results); | ||||||
|  |     saveSettingsDebounced(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function moduleWorker() { | ||||||
|  |     // ???  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | setInterval(moduleWorker, UPDATE_INTERVAL); | ||||||
|  |  | ||||||
|  | window.chromadb_interceptGeneration = async () => { | ||||||
|  |     const context = getContext(); | ||||||
|  |  | ||||||
|  |     // TODO substitute context | ||||||
|  | } | ||||||
|  |  | ||||||
|  | jQuery(async () => { | ||||||
|  |     const settingsHtml = ` | ||||||
|  |     <div class="chromadb_settings"> | ||||||
|  |         <div class="inline-drawer"> | ||||||
|  |             <div class="inline-drawer-toggle inline-drawer-header"> | ||||||
|  |             <b>Infinity Context</b> | ||||||
|  |             <div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div> | ||||||
|  |         </div> | ||||||
|  |         <div class="inline-drawer-content"> | ||||||
|  |             <label for="chromadb_keep_context">How many messages to keep (<span id="chromadb_keep_context_value"></span>)</label> | ||||||
|  |             <input id="chromadb_keep_context" type="range" min="${defaultSettings.keep_context_min}" max="${defaultSettings.keep_context_max}" step="${defaultSettings.keep_context_step}" value="${defaultSettings.keep_context}" /> | ||||||
|  |             <label for="chromadb_n_results">Max messages to inject (<span id="chromadb_n_results_value"></span>)</label> | ||||||
|  |             <input id="chromadb_n_results" type="range" min="${defaultSettings.n_results_min}" max="${defaultSettings.n_results_max}" step="${defaultSettings.n_results_step}" value="${defaultSettings.n_results}" /> | ||||||
|  |         </div> | ||||||
|  |     </div>`; | ||||||
|  |  | ||||||
|  |     $('#extensions_settings').append(settingsHtml); | ||||||
|  |     $('#chromadb_keep_context').on('input', onKeepContextInput); | ||||||
|  |     $('#chromadb_n_results').on('input', onNResultsInput); | ||||||
|  |  | ||||||
|  |     await loadSettings(); | ||||||
|  | }); | ||||||
							
								
								
									
										14
									
								
								public/scripts/extensions/infinity-context/manifest.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								public/scripts/extensions/infinity-context/manifest.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | { | ||||||
|  |     "display_name": "Infinity Context", | ||||||
|  |     "loading_order": 11, | ||||||
|  |     "requires": [ | ||||||
|  |         "chromadb" | ||||||
|  |     ], | ||||||
|  |     "optional": [], | ||||||
|  |     "generate_interceptor": "chromadb_interceptGeneration", | ||||||
|  |     "js": "index.js", | ||||||
|  |     "css": "style.css", | ||||||
|  |     "author": "maceter636@proton.me", | ||||||
|  |     "version": "1.0.0", | ||||||
|  |     "homePage": "https://github.com/Cohee1207/SillyTavern" | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user