From 3391905254980b6c5b5670fbb0eb2588df000b3e Mon Sep 17 00:00:00 2001 From: Jordan Wages Date: Sat, 19 Jul 2025 18:42:39 -0500 Subject: [PATCH] Remove context length option --- _locales/en-US/messages.json | 3 +-- background.js | 23 +++++++++++++---------- options/options.html | 6 ------ options/options.js | 6 +----- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/_locales/en-US/messages.json b/_locales/en-US/messages.json index fb439b9..65181c8 100644 --- a/_locales/en-US/messages.json +++ b/_locales/en-US/messages.json @@ -19,8 +19,7 @@ "options.stripUrlParams": { "message": "Remove URL tracking parameters" }, "options.altTextImages": { "message": "Replace images with alt text" }, "options.collapseWhitespace": { "message": "Collapse long whitespace" }, - "options.tokenReduction": { "message": "Aggressive token reduction" }, - "options.contextLength": { "message": "Context length" } + "options.tokenReduction": { "message": "Aggressive token reduction" } ,"action.read": { "message": "read" } ,"action.flag": { "message": "flag" } ,"action.copy": { "message": "copy" } diff --git a/background.js b/background.js index c44bfed..b5667e6 100644 --- a/background.js +++ b/background.js @@ -27,7 +27,7 @@ let stripUrlParams = false; let altTextImages = false; let collapseWhitespace = false; let tokenReduction = false; -let contextLength = 16384; +let maxTokens = 4096; let TurndownService = null; let userTheme = 'auto'; let currentTheme = 'light'; @@ -262,8 +262,8 @@ async function processMessage(id) { try { const full = await messenger.messages.getFull(id); let text = buildEmailText(full); - if (tokenReduction && contextLength > 0) { - const limit = Math.floor(contextLength * 0.9); + if (tokenReduction && maxTokens > 0) { + const limit = Math.floor(maxTokens * 0.9); if (text.length > limit) { text = text.slice(0, limit); } @@ -425,7 +425,7 @@ async function clearCacheForMessages(idsInput) { } try { - const store = await storage.local.get(["endpoint", "templateName", "customTemplate", "customSystemPrompt", "aiParams", "debugLogging", "htmlToMarkdown", "stripUrlParams", "altTextImages", "collapseWhitespace", "tokenReduction", "contextLength", "aiRules", "theme", "errorPending"]); + const store = await storage.local.get(["endpoint", "templateName", "customTemplate", "customSystemPrompt", "aiParams", "debugLogging", "htmlToMarkdown", "stripUrlParams", "altTextImages", "collapseWhitespace", "tokenReduction", "aiRules", "theme", "errorPending"]); logger.setDebug(store.debugLogging); await AiClassifier.setConfig(store); userTheme = store.theme || 'auto'; @@ -436,7 +436,9 @@ async function clearCacheForMessages(idsInput) { altTextImages = store.altTextImages === true; collapseWhitespace = store.collapseWhitespace === true; tokenReduction = store.tokenReduction === true; - contextLength = parseInt(store.contextLength) || contextLength; + if (store.aiParams && typeof store.aiParams.max_tokens !== 'undefined') { + maxTokens = parseInt(store.aiParams.max_tokens) || maxTokens; + } errorPending = store.errorPending === true; const savedStats = await storage.local.get('classifyStats'); if (savedStats.classifyStats && typeof savedStats.classifyStats === 'object') { @@ -459,7 +461,12 @@ async function clearCacheForMessages(idsInput) { if (changes.templateName) config.templateName = changes.templateName.newValue; if (changes.customTemplate) config.customTemplate = changes.customTemplate.newValue; if (changes.customSystemPrompt) config.customSystemPrompt = changes.customSystemPrompt.newValue; - if (changes.aiParams) config.aiParams = changes.aiParams.newValue; + if (changes.aiParams) { + config.aiParams = changes.aiParams.newValue; + if (changes.aiParams.newValue && typeof changes.aiParams.newValue.max_tokens !== 'undefined') { + maxTokens = parseInt(changes.aiParams.newValue.max_tokens) || maxTokens; + } + } if (changes.debugLogging) { config.debugLogging = changes.debugLogging.newValue === true; logger.setDebug(config.debugLogging); @@ -487,10 +494,6 @@ async function clearCacheForMessages(idsInput) { tokenReduction = changes.tokenReduction.newValue === true; logger.aiLog("tokenReduction updated from storage change", { debug: true }, tokenReduction); } - if (changes.contextLength) { - contextLength = parseInt(changes.contextLength.newValue) || contextLength; - logger.aiLog("contextLength updated from storage change", { debug: true }, contextLength); - } if (changes.errorPending) { errorPending = changes.errorPending.newValue === true; updateActionIcon(); diff --git a/options/options.html b/options/options.html index 108d7f9..69158b1 100644 --- a/options/options.html +++ b/options/options.html @@ -149,12 +149,6 @@ Aggressive token reduction -
- -
- -
-
diff --git a/options/options.js b/options/options.js index f5af1b6..ee2914a 100644 --- a/options/options.js +++ b/options/options.js @@ -17,7 +17,6 @@ document.addEventListener('DOMContentLoaded', async () => { 'altTextImages', 'collapseWhitespace', 'tokenReduction', - 'contextLength', 'aiRules', 'aiCache', 'theme' @@ -120,8 +119,6 @@ document.addEventListener('DOMContentLoaded', async () => { const tokenReductionToggle = document.getElementById('token-reduction'); tokenReductionToggle.checked = defaults.tokenReduction === true; - const contextLengthInput = document.getElementById('context-length'); - contextLengthInput.value = defaults.contextLength || 16384; const aiParams = Object.assign({}, DEFAULT_AI_PARAMS, defaults.aiParams || {}); for (const [key, val] of Object.entries(aiParams)) { @@ -800,9 +797,8 @@ document.addEventListener('DOMContentLoaded', async () => { const altTextImages = altTextToggle.checked; const collapseWhitespace = collapseWhitespaceToggle.checked; const tokenReduction = tokenReductionToggle.checked; - const contextLength = parseInt(contextLengthInput.value) || 0; const theme = themeSelect.value; - await storage.local.set({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt, aiParams: aiParamsSave, debugLogging, htmlToMarkdown, stripUrlParams, altTextImages, collapseWhitespace, tokenReduction, contextLength, aiRules: rules, theme }); + await storage.local.set({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt, aiParams: aiParamsSave, debugLogging, htmlToMarkdown, stripUrlParams, altTextImages, collapseWhitespace, tokenReduction, aiRules: rules, theme }); await applyTheme(theme); try { await AiClassifier.setConfig({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt, aiParams: aiParamsSave, debugLogging });