Remove context length option
This commit is contained in:
parent
91b8d15573
commit
3391905254
4 changed files with 15 additions and 23 deletions
|
@ -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" }
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -149,12 +149,6 @@
|
|||
<input type="checkbox" id="token-reduction"> Aggressive token reduction
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="context-length">Context length</label>
|
||||
<div class="control">
|
||||
<input class="input" type="number" id="context-length">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="max_tokens">Max tokens</label>
|
||||
<div class="control">
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue