Skip to content

Commit bced22a

Browse files
committed
modified prompt and removed unnecessary comments
1 parent cac9981 commit bced22a

File tree

11 files changed

+139
-161
lines changed

11 files changed

+139
-161
lines changed

backend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ JWT_SECRET=
22
REFRESH_SECRET=
33
SALTING=
44
API_URL=
5+
GEMINI_API_KEY=
56
GOOGLE_CLIENT_ID=
67
GOOGLE_CLIENT_SECRET=
78
GOOGLE_CALLBACK_URL=

backend/src/ai/chatBrain.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ export function buildPrompt({
1818
}) {
1919
const baseRole = `
2020
You are Cortex, an intelligent AI analyst for "Call of Code".
21-
CRITICAL: Do NOT start a mock interview. Do NOT introduce yourself as Alex.
22-
Your ONLY job is to answer the user's question using the DATASET provided below.
23-
If the DATASET is empty, tell the user you don't see any interviews yet.
24-
Rules:
25-
- Always start with a helpful hint.
26-
- Do NOT give full solution unless user explicitly asks.
27-
- Be concise, friendly, and use markdown formatting.
28-
- Do NOT act as an interviewer.
29-
- Do NOT introduce yourself as "Alex" or start a mock session.
30-
- Be concise and use markdown.
21+
STRICT LIMITATION: Your knowledge is limited EXCLUSIVELY to DSA and Interview Experiences.
22+
23+
🎯 YOUR GOALS:
24+
1. DSA HELP (3-Step Method):
25+
- Start with a **simple hint** only.
26+
- If user asks for solution (e.g., "give code", "solve it"), provide: (a) Brute-force logic + code, (b) Optimal solution + code.
27+
- Suggest 2-3 similar practice problems from LeetCode/GFG/CodeChef.
28+
2. CAREER QUESTIONS: Define the role, list skills, give a step-by-step roadmap, and suggest learning platforms.
29+
3. INTERVIEW ANALYSIS: Provide direct answers based on stories. DO NOT give hints for interview data queries.
30+
31+
RULES:
32+
- If the query is NOT about DSA/Interviews, use the Refusal Message: "I am Cortex, specialized only in DSA and Interview analysis. Let's stay focused on your preparation!"
33+
- Do NOT start a mock interview. Do NOT act as Alex.
34+
- Use Markdown (bold, headers, code blocks) and emojis 🚀.
3135
`;
3236

3337
console.log("🧠 QUESTION CONTEXT IN chatBrain 👉", questionContext);

backend/src/controllers/chatController.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@ export async function chatController(req: Request, res: Response) {
1212
history,
1313
} = req.body;
1414

15-
// 1️⃣ Debugging: Check what the frontend is actually sending
16-
console.log("📥 Incoming Request Context:", JSON.stringify(questionContext, null, 2));
1715

18-
// 2️⃣ Fetch RAG data (Ab ye Topic aur Question dono handle karega)
16+
// Fetch RAG data
1917
const ragData = await fetchRAGContext(questionContext);
2018
if (ragData) {
21-
console.log("✅ DATA FOUND. Company:", ragData.company || "N/A");
22-
console.log("📝 CONTENT PREVIEW:", ragData.content?.substring(0, 50) + "...");
23-
} else {
24-
console.log("🔍 DATA TO AI: No record found.");
25-
}
26-
27-
// 3️⃣ Build smart prompt
28-
// Isme hum context pass kar rahe hain taaki AI ko pata chale user kahan hai
19+
console.log("✅ DATA FOUND. Company:", ragData.company || "N/A");
20+
console.log("📝 CONTENT PREVIEW:", ragData.content?.substring(0, 50) + "...");
21+
} else {
22+
console.log("🔍 DATA TO AI: No record found.");
23+
}
24+
2925
const prompt = buildPrompt({
3026
path,
3127
ragData,
@@ -34,23 +30,23 @@ export async function chatController(req: Request, res: Response) {
3430
history,
3531
});
3632

37-
// 4️⃣ Call Gemini
33+
// Call Gemini
3834
const chat = geminiModel.startChat({
39-
history: [], // History hum buildPrompt ke andar handle kar rahe hain string format mein
35+
history: [], // History handled in prompt
4036
});
4137

42-
const result = await chat.sendMessage(prompt); // 'prompt' mein baseRole, ragData, aur history sab hai.
38+
const result = await chat.sendMessage(prompt); // prompt has all context
4339
const reply = result.response.text();
4440

45-
// 5️⃣ Send Response
41+
// Send Response
4642
res.json({ reply });
4743

4844
} catch (error) {
49-
console.error("Chat Controller Error:", error);
45+
console.error("Chat Controller Error:", error);
5046

5147
const err = error as Error;
5248

53-
// Error response ko thoda better banaya taaki debugging easy ho
49+
5450
res.status(500).json({
5551
reply: "Cortex is having trouble accessing the context right now. Please try again.",
5652
error: err.message

backend/src/services/retrival.ts

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,39 @@ export async function fetchRAGContext(questionContext?: any) {
1818
}
1919

2020
// --- 2. INTERVIEW COLLECTION (Analysis Mode) ---
21-
// --- 2. INTERVIEW COLLECTION (Analysis Mode) ---
22-
if (questionContext.type === "INTERVIEW_COLLECTION") {
23-
// Option A: Specific IDs fetch karein (Agar API support karti hai)
24-
if (questionContext.interviewIds && questionContext.interviewIds.length > 0) {
25-
// Aap ek query parameter bhej sakte hain ya loop chala sakte hain
26-
const res = await fetch(`${process.env.API_URL}/interviews?ids=${questionContext.interviewIds.join(',')}`);
27-
const data = await res.json() as any;
28-
return Array.isArray(data) ? data : (data.interviews || []);
29-
}
3021

31-
// Option B: Backup - Saare fetch karein (Jo aap abhi kar rahe hain)
32-
const res = await fetch(`${process.env.API_URL}/interviews/all`);
33-
if (!res.ok) return [];
34-
const data = await res.json() as any;
35-
return Array.isArray(data) ? data : (data.interviews || []);
36-
}
22+
if (questionContext.type === "INTERVIEW_COLLECTION") {
23+
if (questionContext.interviewIds && questionContext.interviewIds.length > 0) {
24+
const res = await fetch(`${process.env.API_URL}/interviews?ids=${questionContext.interviewIds.join(',')}`);
25+
const data = await res.json() as any;
26+
return Array.isArray(data) ? data : (data.interviews || []);
27+
}
28+
29+
const res = await fetch(`${process.env.API_URL}/interviews/all`);
30+
if (!res.ok) return [];
31+
const data = await res.json() as any;
32+
return Array.isArray(data) ? data : (data.interviews || []);
33+
}
34+
3735

38-
// --- 3. SINGLE INTERVIEW (Specific Experience) ---
39-
// retrival.ts fix
36+
if (questionContext.type === "INTERVIEW_EXPERIENCE") {
37+
const res = await fetch(`http://localhost:3000/api/v1/interviews/${questionContext.id}`);
4038

41-
// --- 3. SINGLE INTERVIEW (Specific Experience) ---
42-
// retrival.ts
43-
// retrival.ts
44-
if (questionContext.type === "INTERVIEW_EXPERIENCE") {
45-
// Added /v1 to match app.use("/api/v1", routes(upload)) in app.ts
46-
const res = await fetch(`http://localhost:3000/api/v1/interviews/${questionContext.id}`);
47-
48-
if (res.ok) {
49-
const json = await res.json() as any;
50-
51-
// Extract the actual data (handling potential API wrappers)
52-
const actualData = json.data || json.interview || json;
53-
54-
console.log("✅ SUCCESS: Data found for", actualData.company);
55-
return { ...questionContext, ...actualData };
56-
}
57-
console.log("❌ Fetch failed. Status:", res.status);
58-
return questionContext;
59-
}
39+
if (res.ok) {
40+
const json = await res.json() as any;
41+
42+
// Extract the actual data (handling potential API wrappers)
43+
const actualData = json.data || json.interview || json;
44+
45+
console.log("SUCCESS: Data found for", actualData.company);
46+
return { ...questionContext, ...actualData };
47+
}
48+
console.log("Fetch failed. Status:", res.status);
49+
return questionContext;
50+
}
6051

6152
} catch (error) {
62-
console.error("Error in RAG retrieval:", error);
53+
console.error("Error in RAG retrieval:", error);
6354
return null;
6455
}
6556

frontend/public/Chatbot-icon.png

-21.9 KB
Binary file not shown.

frontend/src/components/chatbot/ChatbotIcon.jsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ export default function ChatbotIcon({ onClick }) {
6262
initial={{ opacity: 0, y: 10 }}
6363
animate={{ opacity: 1, y: -10 }}
6464
exit={{ opacity: 0, y: 10 }}
65-
/* BOX DYNAMICS:
66-
- w-fit: Box sirf text jitna bada hoga.
67-
- dark:bg-white: Black theme mein white bg ho jayega.
68-
- bg-black: White theme mein black bg ho jayega.
69-
*/
7065
className="mb-4 bg-black dark:bg-white text-white dark:text-black px-3 py-1.5 text-[10px] font-mono border-l-4 border-[#C1502E] shadow-[4px_4px_0_0_#2C1810] w-fit"
7166
>
7267
<div className="flex flex-col">
@@ -87,7 +82,6 @@ export default function ChatbotIcon({ onClick }) {
8782
borderColor: DARK_BROWN,
8883
backgroundColor: hovered ? "#FFFFFF" : OFF_WHITE_LIGHT,
8984
borderRadius: "12px",
90-
/* SHADOW: Glow add kiya hai for dark mode popping */
9185
boxShadow: hovered
9286
? `8px 8px 0px ${BURNT_ORANGE}, 0px 0px 15px rgba(193, 80, 46, 0.4)`
9387
: `6px 6px 0px ${DARK_BROWN}`,

frontend/src/components/chatbot/ChatbotWrapper.jsx

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import { motion, AnimatePresence } from "framer-motion";
33
import ReactMarkdown from "react-markdown";
44
import { useState, useRef, useEffect } from "react";
5-
import ChatbotIcon from "./ChatbotIcon"; // Import the icon component
5+
import ChatbotIcon from "./ChatbotIcon";
66
import { useLocation } from "react-router-dom";
77

8-
// Specific theme colors from QuestionsView.jsx
8+
99
const COLORS = {
1010
border: "var(--color-chatbot-border, #000000)",
11-
window: "var(--color-chatbot-bg-window, #F5E6D3)", // Light: #F5E6D3, Dark: #1A0D08
11+
window: "var(--color-chatbot-bg-window, #F5E6D3)",
1212
messages: "var(--color-chatbot-bg-messages, #EAD8C3)",
1313
text: "var(--color-chatbot-text, #2C1810)",
1414

@@ -40,8 +40,6 @@ const TerminalIcon = ({ size = "md" }) => {
4040
);
4141
};
4242

43-
44-
4543
export default function ChatbotWrapper({ currentQuestionContext }) {
4644
const [isOpen, setIsOpen] = useState(false);
4745
const [isFull, setIsFull] = useState(false);
@@ -112,7 +110,7 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
112110
const userQuery = input;
113111
const currentPath = location.pathname; // This is the "Context Awareness" part!
114112

115-
// Add user message to UI
113+
116114
const updatedMessages = [...messages, { from: "user", text: userQuery }];
117115
setMessages(updatedMessages);
118116
setInput("");
@@ -153,10 +151,10 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
153151

154152
return (
155153
<>
156-
{/* 1. Floating Icon */}
154+
157155
<ChatbotIcon onClick={toggleChat} />
158156

159-
{/* 2. Chat Window */}
157+
160158
<AnimatePresence>
161159
{isOpen && (
162160
// Wrapper to hold the floating effect
@@ -201,7 +199,6 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
201199

202200
{/* Header Buttons */}
203201
<div className="flex gap-2">
204-
{/* Maximize Button - Turns GREEN on hover */}
205202
<button
206203
onClick={toggleFullScreen}
207204
className="bg-transparent border-2 border-black p-1 shadow-[2px_2px_0_0_black] hover:bg-green-500 hover:text-white transition-all active:translate-y-0.5 active:shadow-none"
@@ -217,8 +214,6 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
217214
</svg>
218215
)}
219216
</button>
220-
221-
{/* Close Button - Turns RED on hover */}
222217
<button
223218
onClick={() => setIsOpen(false)}
224219
className="bg-transparent border-2 border-black p-1 shadow-[2px_2px_0_0_black] hover:bg-red-500 hover:text-white transition-all active:translate-y-0.5 active:shadow-none"
@@ -233,7 +228,6 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
233228
</div>
234229

235230
{/* Messages */}
236-
{/* Message Area */}
237231
<div className="flex-1 overflow-y-auto p-6 space-y-6" style={{ backgroundColor: COLORS.messages, scrollbarWidth: "none" }}>
238232
{messages.map((msg, idx) => (
239233
<div key={idx} className={`flex ${msg.from === "user" ? 'justify-end' : 'justify-start'}`}>
@@ -266,19 +260,19 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
266260
))}
267261

268262
{isTyping && (
269-
<div className="flex items-center gap-3">
270-
<TerminalIcon size="sm" />
271-
<div
272-
className="flex gap-1.5 px-4 py-3 border-4 border-black bg-black shadow-[4px_4px_0_0_black]"
273-
style={{ borderRadius: "15px 15px 15px 2px" }}
274-
>
275-
{/* Dots: Light theme mein Saffron, Dark theme mein White */}
276-
<div className="w-2 h-2 rounded-full animate-bounce [animation-delay:-0.3s] bg-[#FF9933] dark:bg-white" />
277-
<div className="w-2 h-2 rounded-full animate-bounce [animation-delay:-0.15s] bg-[#FF9933] dark:bg-white" />
278-
<div className="w-2 h-2 rounded-full animate-bounce bg-[#FF9933] dark:bg-white" />
279-
</div>
280-
</div>
281-
)}
263+
<div className="flex items-center gap-3">
264+
<TerminalIcon size="sm" />
265+
<div
266+
className="flex gap-1.5 px-4 py-3 border-4 border-black bg-black shadow-[4px_4px_0_0_black]"
267+
style={{ borderRadius: "15px 15px 15px 2px" }}
268+
>
269+
270+
<div className="w-2 h-2 rounded-full animate-bounce [animation-delay:-0.3s] bg-[#FF9933] dark:bg-white" />
271+
<div className="w-2 h-2 rounded-full animate-bounce [animation-delay:-0.15s] bg-[#FF9933] dark:bg-white" />
272+
<div className="w-2 h-2 rounded-full animate-bounce bg-[#FF9933] dark:bg-white" />
273+
</div>
274+
</div>
275+
)}
282276

283277
<div ref={messagesEndRef} />
284278
</div>
@@ -293,7 +287,7 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
293287
onChange={(e) => setInput(e.target.value)}
294288
onKeyDown={(e) => e.key === "Enter" && sendMessage()}
295289
placeholder="ENTER QUERY..."
296-
/* "text-black" add kiya hai taaki light theme mein typing dikhe */
290+
297291
className="flex-1 bg-white border-4 border-black p-3 text-xs font-bold uppercase text-black placeholder:text-black/40 focus:outline-none"
298292
style={{ boxShadow: `4px 4px 0 0 ${COLORS.border}` }}
299293
/>
@@ -306,7 +300,7 @@ export default function ChatbotWrapper({ currentQuestionContext }) {
306300
</button>
307301
</div>
308302
</div>
309-
303+
310304
</motion.div>
311305
</div>
312306
)}

frontend/src/components/dsa/questions/QuestionView.jsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,13 @@ export function QuestionsView({ selectedTopic, onBack, setCurrentQuestionContext
141141
{/* Main floating card */}
142142
<div
143143
onClick={() => {
144-
145-
const ctx= buildQuestionContext({
146-
topic: selectedTopic,
147-
question,
148-
});
144+
145+
const ctx = buildQuestionContext({
146+
topic: selectedTopic,
147+
question,
148+
});
149149
setCurrentQuestionContext(ctx);
150-
console.log("BUILT CTX 👉", ctx);
151-
150+
152151
}}
153152
className="relative border-4 border-black bg-[#FFF6EE] dark:bg-[#2C1810]
154153
p-8 rounded-lg shadow-[10px_10px_0_0_#2C1810]
@@ -183,7 +182,7 @@ export function QuestionsView({ selectedTopic, onBack, setCurrentQuestionContext
183182
{/* Actions */}
184183
<div className="flex justify-between items-center">
185184
<button
186-
onClick={(e) =>{
185+
onClick={(e) => {
187186
e.stopPropagation();
188187
handleToggle(question.id)
189188
}}
@@ -202,8 +201,8 @@ export function QuestionsView({ selectedTopic, onBack, setCurrentQuestionContext
202201
</button>
203202

204203
<button
205-
onClick={(e) =>{
206-
e.stopPropagation();
204+
onClick={(e) => {
205+
e.stopPropagation();
207206
window.open(question.link, "_blank", "noopener,noreferrer")
208207
}}
209208
className="relative border-4 border-black bg-[#F5E6D3] dark:bg-[#FFF6EE]

frontend/src/components/interview/InterviewExperienceItem.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function InterviewExperienceItem({
1616
showProfileInfo = true,
1717
onEdit,
1818
onDelete,
19-
setCurrentQuestionContext
19+
setCurrentQuestionContext // For chatbot context setting
2020
}) {
2121
const [isExpanded, setIsExpanded] = useState(false);
2222

frontend/src/pages/DsaDashboard.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export default function DsaDashboard({ setCurrentQuestionContext }) {
77
const [selectedTopic, setSelectedTopic] = useState(null);
88

99

10-
11-
const handleBackToTopics = () => {
10+
const handleBackToTopics = () => {
1211
setCurrentView("topics");
1312
setSelectedTopic(null);
1413
};
@@ -21,7 +20,7 @@ const [selectedTopic, setSelectedTopic] = useState(null);
2120
type: "DSA",
2221
topicId: topic.id,
2322
topicTitle: topic.title,
24-
isTopicOnly: true // Isse backend ko pata chalega ki abhi koi question select nahi hua hai
23+
isTopicOnly: true
2524
});
2625
};
2726

0 commit comments

Comments
 (0)