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 -