From 6912f54ab22ace27e8f4f5efd14319c9a8c51353 Mon Sep 17 00:00:00 2001 From: suryansh24-coder Date: Sun, 31 May 2026 19:45:19 +0530 Subject: [PATCH 1/3] feat: add hint progression mode infrastructure --- backend/ai.py | 44 ++++++++++++++++++++++++++ backend/main.py | 31 ++++++++++++++++++ extension/background.js | 25 +++++++++++++++ extension/popup.html | 36 +++++++++++++++++++++ extension/popup.js | 70 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 206 insertions(+) diff --git a/backend/ai.py b/backend/ai.py index e23e07e..f67a49b 100644 --- a/backend/ai.py +++ b/backend/ai.py @@ -348,3 +348,47 @@ def rate_code_efficiency(title: str, code: str, language: str = "python") -> dic raise last_error or Exception( "All Gemini models are currently quota-limited. Please wait a minute and try again." ) + +def generate_hint( + title: str, + description: str, + difficulty: str, + hint_level: int +) -> str: + + hint_prompts = { + 1: "Give only a direction hint. Do not reveal algorithm or code.", + 2: "Suggest useful data structures. Do not reveal solution.", + 3: "Explain the intuition. No code.", + 4: "Provide pseudocode only.", + 5: "Provide the complete optimized solution." + } + + prompt = f""" + You are a LeetCode mentor. + + Problem Title: + {title} + + Problem Description: + {description} + + Difficulty: + {difficulty} + + Task: + {hint_prompts.get(hint_level, hint_prompts[1])} + + Keep response concise. + """ + + api_key = os.getenv("GEMINI_API_KEY") + + client = genai.Client(api_key=api_key) + + response = client.models.generate_content( + model="models/gemini-2.5-flash", + contents=prompt + ) + + return response.text \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index b3ef2d0..8b88e32 100644 --- a/backend/main.py +++ b/backend/main.py @@ -13,6 +13,7 @@ # --- UPDATED AI PATH --- from ai_core.blog_generator import generate_blog +from ai import generate_hint from devto import publish_to_platforms from models.reminder import PublishRecord from services.reminder_scheduler import start_scheduler @@ -96,6 +97,12 @@ def health_check(): # ----------------------------- # Blog Generator Endpoint # ----------------------------- +class HintRequest(BaseModel): + title: str + description: str + difficulty: str = "Unknown" + hint_level: int + @app.post("/generate-blog") async def create_blog(problem: Problem): """ @@ -203,6 +210,30 @@ async def create_blog(problem: Problem): "social": social_results, }, } + +@app.post("/generate-hint") +async def generate_hint_api(request: HintRequest): + + try: + + hint = generate_hint( + request.title, + request.description, + request.difficulty, + request.hint_level + ) + + return { + "status": "success", + "hint": hint + } + + except Exception as e: + + return { + "status": "error", + "message": str(e) + } # ----------------------------- diff --git a/extension/background.js b/extension/background.js index a3f4a96..a40e461 100644 --- a/extension/background.js +++ b/extension/background.js @@ -33,6 +33,31 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { }); } + chrome.runtime.onMessage.addListener((request) => { + + if (request.type === "GENERATE_HINT") { + + fetch(`${API_BASE_URL}/generate-hint`, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(request.payload) + }) + .then(res => res.json()) + .then(data => { + + chrome.runtime.sendMessage({ + type: "HINT_READY", + hint: data.hint + }); + + }); + + } + + }); + if (data.status === 'success' || data.status === 'partial_success') { const platforms = data.data?.platforms || []; const postedPlatforms = platforms diff --git a/extension/popup.html b/extension/popup.html index 93052b7..bb1bde8 100644 --- a/extension/popup.html +++ b/extension/popup.html @@ -255,6 +255,42 @@

+
+ +

Hint Progression Mode

+ +
+ + +
+ +
+ + +
+ + + + + +
+
Ready to blog! 🚀