Skip to content

Commit 5ed886e

Browse files
committed
Finalized Working
1 parent a732d0b commit 5ed886e

File tree

6 files changed

+64
-25
lines changed

6 files changed

+64
-25
lines changed

extension/popup.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
body {
77
font-family: Arial, sans-serif;
88
padding: 10px;
9-
width: 250px;
9+
width: 300px;
1010
}
11+
12+
h3 {
13+
margin-top: 0;
14+
}
15+
1116
#getHelp {
1217
padding: 10px;
1318
background: #4CAF50;
@@ -16,13 +21,24 @@
1621
width: 100%;
1722
border-radius: 5px;
1823
cursor: pointer;
24+
margin-bottom: 10px;
25+
}
26+
27+
ul {
28+
padding-left: 20px;
29+
}
30+
31+
li {
32+
margin-bottom: 5px;
1933
}
2034
</style>
2135
</head>
2236
<body>
2337
<h3>Need Help with LeetCode?</h3>
2438
<button id="getHelp">Get Step-by-Step Help</button>
2539

40+
<ul id="output"></ul> <!-- This is where the guided steps will appear -->
41+
2642
<script src="popup.js"></script>
2743
</body>
2844
</html>

extension/popup.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
console.log("📦 popup.js loaded");
2+
23
document.getElementById("getHelp").addEventListener("click", async () => {
34
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
45
const tab = tabs[0];
@@ -8,20 +9,28 @@ document.getElementById("getHelp").addEventListener("click", async () => {
89
console.log("LeetCode URL:", url);
910
console.log("Problem Title:", title);
1011

11-
// For tomorrow: send to Django here
12-
fetch("http://127.0.0.1:8000/api/solve/", {
13-
method: "POST",
14-
headers: {
15-
"Content-Type": "application/json"
16-
},
17-
body: JSON.stringify({
18-
title: title,
19-
url: url
20-
})
21-
})
22-
.then(response => response.json())
23-
.then(data => console.log("✅ Response from Django:", data))
24-
.catch(error => console.error("❌ Error:", error));
12+
const response = await fetch("http://127.0.0.1:8000/api/solve/", {
13+
method: "POST",
14+
headers: {
15+
"Content-Type": "application/json"
16+
},
17+
body: JSON.stringify({ title, url })
18+
});
19+
20+
const data = await response.json();
21+
console.log("✅ Response from Django:", data);
22+
23+
const output = document.getElementById("output");
24+
output.innerHTML = "";
2525

26+
if (data.steps && Array.isArray(data.steps)) {
27+
data.steps.forEach((step, index) => {
28+
const li = document.createElement("li");
29+
li.textContent = step;
30+
output.appendChild(li);
31+
});
32+
} else {
33+
output.innerHTML = "<p>No steps found.</p>";
34+
}
2635
});
2736
});
921 Bytes
Binary file not shown.

leetcode_backend/api/views.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
from django.http import JsonResponse
22
from django.views.decorators.csrf import csrf_exempt
33
import json
4-
4+
import google.generativeai as genai
5+
from django.conf import settings
56

67
# Create your views here.
8+
9+
genai.configure(api_key=settings.GEMINI_API_KEY)
710
@csrf_exempt
811
def solve_view(request):
912
if request.method == 'POST':
1013
data = json.loads(request.body)
1114
title = data.get("title")
1215
url = data.get("url")
1316
print(f"Received: {title}, {url}")
14-
return JsonResponse({
15-
"steps": [
16-
f"Step 1: Understand the problem '{title}'",
17-
"Step 2: Write edge cases",
18-
"Step 3: Think of brute-force",
19-
"Step 4: Optimize your solution",
20-
f"Step 5: Submit on LeetCode: {url}"
21-
]
22-
})
17+
18+
prompt = f"""
19+
You're an expert LeetCode mentor. A user is working on the problem titled: "{title}" ({url}).
20+
Give them clear, step-by-step guidance to solve it — including edge cases, brute-force thinking, and optimization ideas.
21+
DO NOT write or suggest actual code.
22+
Only provide strategic help in natural language.
23+
"""
24+
25+
26+
model = genai.GenerativeModel("models/gemini-1.5-flash")
27+
response = model.generate_content(prompt)
28+
answer = response.text
29+
30+
31+
steps = answer.strip().split("\n")
32+
steps = [step.strip() for step in steps if step.strip()]
33+
34+
return JsonResponse({"steps": steps})
35+
2336
return JsonResponse({"error": "Only POST allowed"}, status=400)
66 Bytes
Binary file not shown.

leetcode_backend/backend/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
2323
SECRET_KEY = 'django-insecure-3i1tui3mzz&3ovzlutdog7y!j=8o9(vuah3yg*k!a57r%u(6%w'
24+
GEMINI_API_KEY = "AIzaSyDU88ywematkfLK7q9j5GXIRlZhewSDH3E"
2425

2526
# SECURITY WARNING: don't run with debug turned on in production!
2627
DEBUG = True

0 commit comments

Comments
 (0)