diff --git a/background.js b/background.js index df189ae..ccd4295 100644 --- a/background.js +++ b/background.js @@ -6,50 +6,58 @@ browser.browserAction.onClicked.addListener(() => { browser.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.action === "summarize") { - summarizeContent(request.content) - .then(summary => { + summarizeContent(request.content, request.systemPrompt) + .then((summary) => { sendResponse({ summary }); }) - .catch(error => { - console.error('Error in summarizeContent:', error); + .catch((error) => { + console.error("Error in summarizeContent:", error); sendResponse({ error: error.toString(), details: error.details }); }); return true; // Indicates that we will send a response asynchronously } }); -async function summarizeContent(content) { - const settings = await browser.storage.local.get(['ollamaEndpoint', 'ollamaModel']); - const endpoint = `${settings.ollamaEndpoint || 'http://localhost:11434'}/api/generate`; - const model = settings.ollamaModel || 'llama2'; +async function summarizeContent(content, systemPrompt) { + const settings = await browser.storage.local.get([ + "ollamaEndpoint", + "ollamaModel", + ]); + const endpoint = `${ + settings.ollamaEndpoint || "http://localhost:11434" + }/api/generate`; + const model = settings.ollamaModel || "llama3.1:8b"; try { + console.log(`Using system prompt: ${systemPrompt}`); const response = await fetch(endpoint, { - method: 'POST', + method: "POST", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, body: JSON.stringify({ - prompt: `Summarize the following text:\n\n${content}`, + prompt: `${systemPrompt}\n\nFollow the above instructions and summarize the following text:\n\n${content}`, model: model, - stream: false + stream: false, }), }); if (!response.ok) { const errorText = await response.text(); - throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`); + throw new Error( + `HTTP error! status: ${response.status}, message: ${errorText}` + ); } const data = await response.json(); return data.response; } catch (error) { - console.error('Error details:', error); + console.error("Error details:", error); error.details = { endpoint: endpoint, model: model, - message: error.message + message: error.message, }; throw error; } -} \ No newline at end of file +} diff --git a/options/options.css b/options/options.css index f696dd9..b733068 100644 --- a/options/options.css +++ b/options/options.css @@ -1,90 +1,104 @@ body { - font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; - margin: 0; - padding: 0; - background-color: #f5f5f5; - color: #333; + font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; + margin: 0; + padding: 0; + background-color: #f5f5f5; + color: #333; } .container { - max-width: 600px; - margin: 0 auto; - padding: 40px 20px; + max-width: 600px; + margin: 0 auto; + padding: 40px 20px; } h1 { - font-size: 28px; - margin-bottom: 30px; - color: #2c3e50; + font-size: 28px; + margin-bottom: 30px; + color: #2c3e50; } .form-group { - margin-bottom: 20px; + margin-bottom: 20px; } label { - display: block; - margin-bottom: 5px; - font-weight: bold; - color: #34495e; + display: block; + margin-bottom: 5px; + font-weight: bold; + color: #34495e; } .input-group { - display: flex; - align-items: center; + display: flex; + align-items: center; } input[type="text"] { - width: 100%; - padding: 10px; - font-size: 16px; - border: 1px solid #bdc3c7; - border-radius: 5px; - transition: border-color 0.3s ease; + width: 100%; + padding: 10px; + font-size: 16px; + border: 1px solid #bdc3c7; + border-radius: 5px; + transition: border-color 0.3s ease; } input[type="text"]:focus { - outline: none; - border-color: #3498db; + outline: none; + border-color: #3498db; } .status-indicator { - margin-left: 10px; - font-size: 20px; + margin-left: 10px; + font-size: 20px; } .btn { - display: inline-block; - padding: 10px 20px; - font-size: 16px; - border: none; - border-radius: 5px; - cursor: pointer; - transition: background-color 0.3s ease; + display: inline-block; + padding: 10px 20px; + font-size: 16px; + border: none; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s ease; } .btn-primary { - background-color: #3498db; - color: white; + background-color: #3498db; + color: white; } .btn-primary:hover { - background-color: #2980b9; + background-color: #2980b9; } .status-message { - margin-top: 20px; - padding: 10px; - border-radius: 5px; - font-weight: bold; + margin-top: 20px; + padding: 10px; + border-radius: 5px; + font-weight: bold; } .status-message.success { - background-color: #2ecc71; - color: white; + background-color: #2ecc71; + color: white; } .status-message.error { - background-color: #e74c3c; - color: white; -} \ No newline at end of file + background-color: #e74c3c; + color: white; +} + +textarea { + width: 100%; + padding: 10px; + font-size: 16px; + border: 1px solid #bdc3c7; + border-radius: 5px; + transition: border-color 0.3s ease; + resize: vertical; +} +textarea:focus { + outline: none; + border-color: #3498db; +} diff --git a/options/options.html b/options/options.html index 270d370..2ed91ec 100644 --- a/options/options.html +++ b/options/options.html @@ -1,30 +1,38 @@ -
- - -