Skip to content

Commit

Permalink
auto model token limits
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsenpai committed Oct 13, 2024
1 parent 6a01bb6 commit 08394ba
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 39 deletions.
2 changes: 1 addition & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function summarizeContent(content, systemPrompt) {
const endpoint = `${
settings.ollamaEndpoint || "http://localhost:11434"
}/api/generate`;
const model = settings.ollamaModel || "llama2";
const model = settings.ollamaModel || "llama3.1:8b";
const tokenLimit = settings.tokenLimit || 4096;

const maxContentTokens = tokenLimit - estimateTokenCount(systemPrompt) - 100; // Reserve 100 tokens for safety
Expand Down
67 changes: 30 additions & 37 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
{
"manifest_version": 2,
"name": "SpaceLLama",
"version": "1.0",
"description": "Summarize web pages using OLLAMA",
"permissions": [
"activeTab",
"storage",
"<all_urls>",
"tabs"
],
"browser_action": {
"default_title": "SpaceLLama",
"default_icon": "icon.png"
},
"sidebar_action": {
"default_title": "SpaceLLama",
"default_panel": "sidebar/sidebar.html",
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content_scripts/content.js"]
}
],
"options_ui": {
"page": "options/options.html",
"open_in_tab": true
},
"web_accessible_resources": [
"sidebar/marked.min.js"
]
}
"manifest_version": 2,
"name": "SpaceLLama",
"version": "1.1",
"description": "Summarize web pages using Ollama. Supports custom models, token limits, system prompts, chunking, and more. See https://github.com/tcsenpai/spacellama for more information.",
"permissions": ["activeTab", "storage", "<all_urls>", "tabs"],
"browser_action": {
"default_title": "SpaceLLama",
"default_icon": "icon.png"
},
"sidebar_action": {
"default_title": "SpaceLLama",
"default_panel": "sidebar/sidebar.html",
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content_scripts/content.js"]
}
],
"options_ui": {
"page": "options/options.html",
"open_in_tab": true
},
"web_accessible_resources": ["sidebar/marked.min.js", "model_tokens.json"]
}
26 changes: 26 additions & 0 deletions model_tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"llama2": 4096,
"llama2:13b": 4096,
"llama2:70b": 4096,
"codellama": 16384,
"codellama:13b": 16384,
"codellama:34b": 16384,
"mistral": 8192,
"mixtral": 32768,
"phi": 2048,
"qwen": 8192,
"qwen:14b": 8192,
"qwen:72b": 8192,
"stablelm": 4096,
"stablelm-zephyr": 4096,
"neural-chat": 8192,
"openhermes": 8192,
"starling-lm": 8192,
"orca2": 4096,
"vicuna": 8192,
"wizardcoder": 16384,
"wizardcoder:python": 16384,
"wizardmath": 8192,
"llama3.1:8b": 128000,
"llama3.1:70b": 128000
}
22 changes: 21 additions & 1 deletion options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ async function restoreOptions() {
document.getElementById("endpoint").value = endpoint;
document.getElementById("model").value = result.ollamaModel || "llama2";
document.getElementById("system-prompt").value = result.systemPrompt || defaultSystemPrompt;
document.getElementById("token-limit").value = result.tokenLimit || 4096;

await updateTokenLimit();

const isValid = await validateEndpoint(endpoint);
updateEndpointStatus(isValid);
}
Expand All @@ -72,3 +74,21 @@ document.getElementById("endpoint").addEventListener("blur", async (e) => {
updateEndpointStatus(isValid);
});

async function loadModelTokens() {
const response = await fetch(browser.runtime.getURL('model_tokens.json'));
return await response.json();
}

async function updateTokenLimit() {
const modelTokens = await loadModelTokens();
const model = document.getElementById("model").value;
const tokenLimitInput = document.getElementById("token-limit");

if (model in modelTokens) {
tokenLimitInput.value = modelTokens[model];
} else {
tokenLimitInput.value = 4096; // Default value
}
}

document.getElementById("model").addEventListener("change", updateTokenLimit);

0 comments on commit 08394ba

Please sign in to comment.