diff --git a/backend/ai_core/prompts.py b/backend/ai_core/prompts.py index 5670097..c117805 100644 --- a/backend/ai_core/prompts.py +++ b/backend/ai_core/prompts.py @@ -1,8 +1,45 @@ from datetime import datetime +TONE_MAP = { + "beginner": """ +Write in a beginner-friendly style. +Explain concepts using simple language. +Avoid unnecessary jargon. +Use examples wherever possible. +""", + + "professional": """ +Write in a professional technical blogging style. +Maintain clarity and industry-standard explanations. +""", + + "academic": """ +Write in an academic and analytical style. +Provide detailed reasoning and technical depth. +""", + + "humorous": """ +Write in a light-hearted and engaging style. +Use appropriate humor while keeping technical accuracy. +""", + + "concise": """ +Write concise explanations. +Avoid unnecessary details. +Focus on key insights only. +""" +} + def build_prompt(problem, current_time: str) -> str: custom_instructions = "" + tone_instructions = "" + + if hasattr(problem, "tone") and problem.tone: + tone_instructions = TONE_MAP.get( + problem.tone.lower(), + "" + ) default_prompt = f""" You are a professional technical writer and competitive programmer. @@ -48,6 +85,9 @@ def build_prompt(problem, current_time: str) -> str: return f""" {default_prompt} +Selected Writing Tone: +{tone_instructions} + {custom_instructions} """ diff --git a/extension/content.js b/extension/content.js index a7fdbca..2e9cf0a 100644 --- a/extension/content.js +++ b/extension/content.js @@ -14,7 +14,10 @@ const AUTO_TRIGGER_MIN_INTERVAL_MS = 60 * 1000; // 1 minute between auto-triggers for same submission // Function to handle data extraction and blog generation - const triggerBlogGeneration = async (custom_prompt = "") => { + const triggerBlogGeneration = async ( + custom_prompt = "", + tone = "beginner" + ) => { if (isProcessing) return; isProcessing = true; @@ -103,7 +106,18 @@ // Send to background script chrome.runtime.sendMessage({ type: 'GENERATE_BLOG', - payload: { title, description, code, author, client_time, custom_prompt, difficulty, language, topics } + payload: { + title, + description, + code, + author, + client_time, + custom_prompt, + tone, + difficulty, + language, + topics + } }); @@ -153,7 +167,10 @@ // Start of Listener for manual triggers from popup and status updates chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.type === 'MANUAL_TRIGGER') { - triggerBlogGeneration(request.custom_prompt || ""); //usage of custom prompt + triggerBlogGeneration( + request.custom_prompt || "", + request.tone || "beginner" + ); //usage of custom prompt } else if (request.type === 'STATUS_UPDATE') { if (request.status === 'success' || request.status === 'error') { isProcessing = false; diff --git a/extension/popup.js b/extension/popup.js index 17b217d..fe36cd9 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -293,14 +293,20 @@ document.addEventListener('DOMContentLoaded', async () => { chrome.storage.local.get({ publishingPlatforms: ['devto'], - publishAsDraft: false - }, ({ publishingPlatforms, publishAsDraft }) => { + publishAsDraft: false, + selectedTone: 'beginner' + }, ({ publishingPlatforms, publishAsDraft, selectedTone }) => { platformInputs.forEach(input => { input.checked = publishingPlatforms.includes(input.value); }); draftInput.checked = publishAsDraft; + const toneSelect = document.getElementById('toneSelect'); + + if (toneSelect) { + toneSelect.value = selectedTone; + } }); const savePublishingSettings = () => { @@ -321,12 +327,16 @@ document.addEventListener('DOMContentLoaded', async () => { chrome.storage.local.set({ publishingPlatforms: selectedPlatforms, - publishAsDraft: draftInput.checked + publishAsDraft: draftInput.checked, + selectedTone: document.getElementById('toneSelect').value }); }; platformInputs.forEach(input => input.addEventListener('change', savePublishingSettings)); draftInput.addEventListener('change', savePublishingSettings); + document + .getElementById('toneSelect') + ?.addEventListener('change', savePublishingSettings); // Load generated blog from storage chrome.storage.local.get( @@ -411,6 +421,9 @@ document.addEventListener('DOMContentLoaded', async () => { .getElementById('customPrompt') .value .trim(); + const tone = document + .getElementById('toneSelect') + .value; if (!tab || !tab.url || !tab.url.includes("leetcode.com/problems/")) { statusEl.innerText = "Please open a LeetCode problem page!"; @@ -435,7 +448,8 @@ document.addEventListener('DOMContentLoaded', async () => { await chrome.tabs.sendMessage(tab.id, { type: 'MANUAL_TRIGGER', - custom_prompt: customPrompt + custom_prompt: customPrompt, + tone: tone }); } catch (msgErr) { @@ -452,11 +466,19 @@ document.addEventListener('DOMContentLoaded', async () => { if (generateBtn) generateBtn.disabled = false; if (copyBtn) copyBtn.disabled = false; - await chrome.tabs.sendMessage(tab.id, { type: 'MANUAL_TRIGGER' }); + await chrome.tabs.sendMessage(tab.id, { + type: 'MANUAL_TRIGGER', + custom_prompt: customPrompt, + tone: tone + }); setTimeout(async () => { try { - await chrome.tabs.sendMessage(tab.id, { type: 'MANUAL_TRIGGER' }); + await chrome.tabs.sendMessage(tab.id, { + type: 'MANUAL_TRIGGER', + custom_prompt: customPrompt, + tone: tone + }); } catch (e2) { statusEl.innerText = "Error: Please refresh LeetCode page!"; statusEl.className = "error-status";