Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions backend/ai_core/prompts.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -48,6 +85,9 @@ def build_prompt(problem, current_time: str) -> str:
return f"""
{default_prompt}

Selected Writing Tone:
{tone_instructions}

{custom_instructions}
"""

Expand Down
23 changes: 20 additions & 3 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
});


Expand Down Expand Up @@ -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;
Expand Down
34 changes: 28 additions & 6 deletions extension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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(
Expand Down Expand Up @@ -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!";
Expand All @@ -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) {
Expand All @@ -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";
Expand Down
Loading