Skip to content

Commit 332056b

Browse files
authored
Add files via upload
1 parent 540b844 commit 332056b

File tree

1 file changed

+121
-52
lines changed

1 file changed

+121
-52
lines changed

app.js

Lines changed: 121 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,29 @@ const responses = [
128128
"MD Affan Asghar is a passionate Full Stack Web Developer and Computer Science Engineering student, dedicated to building beautiful, responsive, and user-friendly websites. 💻🚀",
129129
},
130130
{
131-
keywords: ["your name", "creator", "made you", "built you", "build", "who created you"],
131+
keywords: [
132+
"your name",
133+
"creator",
134+
"made you",
135+
"built you",
136+
"build",
137+
"who created you",
138+
],
132139
response: "I'm a chatbot created by MD Affan Asghar. 😊",
133140
},
134141
{
135142
keywords: ["developer name", "who made you", "who is your developer"],
136143
response: "My developer is MD Affan Asghar. 🚀",
137144
},
138145
{
139-
keywords: ["phone number", "contact", "mobile", "phone", "how to contact", "reach affan"],
146+
keywords: [
147+
"phone number",
148+
"contact",
149+
"mobile",
150+
"phone",
151+
"how to contact",
152+
"reach affan",
153+
],
140154
response: "You can contact MD Affan Asghar at 📞 9339828230.",
141155
},
142156
{
@@ -148,28 +162,70 @@ const responses = [
148162
response: "He lives at 🏠 Kankinara, Kolkata, West Bengal.",
149163
},
150164
{
151-
keywords: ["skills", "expertise", "technologies", "tech stack", "what can affan do"],
165+
keywords: [
166+
"skills",
167+
"expertise",
168+
"technologies",
169+
"tech stack",
170+
"what can affan do",
171+
],
152172
response:
153173
"He is skilled in 🔥 Full-Stack Web Development, Node.js, React, Php, MySQL MongoDB, Express.js, JavaScript, HTML, CSS, and more!",
154174
},
155175
{
156-
keywords: ["projects", "work", "portfolio", "project", "what has affan built"],
176+
keywords: [
177+
"projects",
178+
"work",
179+
"portfolio",
180+
"project",
181+
"what has affan built",
182+
],
183+
response:
184+
"His Full Stack projects include 🎯 WanderLust Holidays-Rental-Homes, NoHate website, and a Weather App using React,etc. 🚀",
185+
},
186+
{
187+
keywords: [
188+
"wanderlust",
189+
"wanderlust project",
190+
"holiday project",
191+
"rental homes",
192+
"holiday rental",
193+
],
157194
response:
158-
"His projects include 🎯 WanderLust-Holidays-Rental-Homes, Full Stack NoHate website, and a Weather App using React,etc. 🚀",
195+
"WanderLust Holidays-Rental-Homes is a full-stack web application inspired by Airbnb. It allows users to explore, book, and host rental properties with secure authentication, image uploads, filtering, and responsive design. Built using Node.js, Express.js, MongoDB, and EJS for dynamic rendering. 🌍",
196+
},
197+
{
198+
keywords: [
199+
"nohate",
200+
"no hate",
201+
"hate speech",
202+
"nohate website",
203+
"hate detection project",
204+
"anti hate project",
205+
],
206+
response:
207+
"🛡️ The NoHate website is a full-stack platform built to detect and filter hate speech in user posts. It uses machine learning for content moderation, with a modern frontend in React and backend in Node.js, Express, and MongoDB. It promotes respectful online communication. 💬🚫",
159208
},
160209
{
161210
keywords: ["portfolio", "website", "profile", "personal website"],
162-
response: "Check out his portfolio here: 🌐 https://portfolio-affan.netlify.app/.",
211+
response:
212+
"Check out his portfolio here: 🌐 https://portfolio-affan.netlify.app/.",
163213
},
164214
{
165-
keywords: ["college", "education", "study", "degree", "where did affan study"],
215+
keywords: [
216+
"college",
217+
"education",
218+
"study",
219+
"degree",
220+
"where did affan study",
221+
],
166222
response:
167-
"He is currently pursuing B.Tech in Computer Science Engineering (CSE) at 🏫 Narula Institute of Technology.",
223+
"He is currently pursuing B.Tech in Computer Science Engineering (CSE) at 🏫 Narula Institute of Technology, Kolkata, India.",
168224
},
169225
{
170226
keywords: ["internship", "experience", "job", "work experience"],
171227
response:
172-
"He worked as a Web Developer Intern at 💼 Simtrak Solution Pvt Ltd.",
228+
"He is currently working at 🏢 Ecomservices as a Full Stack Web Developer, focusing on scalable and full stack web applications. Previously, he worked as a Web Developer Intern at 💼 Simtrak Solution Pvt Ltd. 🚀",
173229
},
174230
{
175231
keywords: ["final year project", "academic project", "college project"],
@@ -206,33 +262,37 @@ const responses = [
206262
},
207263
{
208264
keywords: ["thank", "thanks", "appreciate"],
209-
response: "You're welcome! Let me know if you need anything else about Affan. 😊",
265+
response:
266+
"You're welcome! Let me know if you need anything else about Affan. 😊",
210267
},
211268
];
212269

213270
function findBestResponse(userMessage) {
214271
userMessage = userMessage.toLowerCase();
215-
272+
216273
// First check for exact matches
217274
for (let entry of responses) {
218-
if (entry.keywords.some(keyword =>
219-
userMessage === keyword ||
220-
userMessage.includes(keyword) ||
221-
new RegExp(`\\b${keyword}\\b`).test(userMessage)
222-
)) {
275+
if (
276+
entry.keywords.some(
277+
(keyword) =>
278+
userMessage === keyword ||
279+
userMessage.includes(keyword) ||
280+
new RegExp(`\\b${keyword}\\b`).test(userMessage)
281+
)
282+
) {
223283
return entry.response;
224284
}
225285
}
226-
286+
227287
// Then check for partial matches
228288
let bestMatch = null;
229289
let highestMatchCount = 0;
230290

231291
for (let entry of responses) {
232-
let matchCount = entry.keywords.filter(keyword =>
292+
let matchCount = entry.keywords.filter((keyword) =>
233293
userMessage.includes(keyword)
234294
).length;
235-
295+
236296
if (matchCount > highestMatchCount) {
237297
highestMatchCount = matchCount;
238298
bestMatch = entry.response;
@@ -246,41 +306,46 @@ function findBestResponse(userMessage) {
246306
async function callDeepSeekAPI(userMessage) {
247307
// Don't call API for simple greetings or common questions
248308
const simpleQuestions = ["hi", "hello", "hey", "bye", "thank"];
249-
if (simpleQuestions.some(q => userMessage.toLowerCase().includes(q))) {
309+
if (simpleQuestions.some((q) => userMessage.toLowerCase().includes(q))) {
250310
return null;
251311
}
252312

253313
try {
254-
const response = await fetch("https://api.deepseek.com/v1/chat/completions", {
255-
method: "POST",
256-
headers: {
257-
"Authorization": "Bearer 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",
258-
"Content-Type": "application/json",
259-
},
260-
body: JSON.stringify({
261-
model: "deepseek-chat",
262-
messages: [
263-
{
264-
role: "system",
265-
content: "You are an assistant that answers questions specifically about MD Affan Asghar, a Full Stack Developer. Keep responses brief (1-2 sentences max) and relevant to Affan's skills, projects, education, or contact info. If the question isn't about Affan, politely decline to answer."
266-
},
267-
{
268-
role: "user",
269-
content: userMessage
270-
}
271-
],
272-
temperature: 0.3, // Lower temperature for more focused answers
273-
max_tokens: 100
274-
}),
275-
timeout: 5000 // Add timeout
276-
});
314+
const response = await fetch(
315+
"https://api.deepseek.com/v1/chat/completions",
316+
{
317+
method: "POST",
318+
headers: {
319+
Authorization:
320+
"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",
321+
"Content-Type": "application/json",
322+
},
323+
body: JSON.stringify({
324+
model: "deepseek-chat",
325+
messages: [
326+
{
327+
role: "system",
328+
content:
329+
"You are an assistant that answers questions specifically about MD Affan Asghar, a Full Stack Developer. Keep responses brief (1-2 sentences max) and relevant to Affan's skills, projects, education, or contact info. If the question isn't about Affan, politely decline to answer.",
330+
},
331+
{
332+
role: "user",
333+
content: userMessage,
334+
},
335+
],
336+
temperature: 0.3, // Lower temperature for more focused answers
337+
max_tokens: 100,
338+
}),
339+
timeout: 5000, // Add timeout
340+
}
341+
);
277342

278343
if (!response.ok) {
279344
throw new Error(`API request failed with status ${response.status}`);
280345
}
281346

282347
const data = await response.json();
283-
348+
284349
if (!data.choices?.[0]?.message?.content) {
285350
throw new Error("Invalid API response structure");
286351
}
@@ -321,14 +386,18 @@ function sendMessage() {
321386
// If no local match found, try API
322387
if (!botResponse) {
323388
const apiResponse = await callDeepSeekAPI(message);
324-
botResponse = apiResponse ||
389+
botResponse =
390+
apiResponse ||
325391
"I'm designed to answer questions about MD Affan Asghar. Could you ask something specific about his skills, projects, or contact information?";
326392
}
327393

328394
addMessage(botResponse, "bot-message");
329395
} catch (error) {
330396
console.error("Error generating response:", error);
331-
addMessage("I'm having some trouble right now. Please try asking something specific about Affan's skills or projects.", "bot-message");
397+
addMessage(
398+
"I'm having some trouble right now. Please try asking something specific about Affan's skills or projects.",
399+
"bot-message"
400+
);
332401
}
333402
}, 1500);
334403
}
@@ -343,17 +412,17 @@ function addMessage(text, className) {
343412
const messageContainer = document.getElementById("chatbotMessages");
344413
const messageDiv = document.createElement("div");
345414
messageDiv.className = className;
346-
415+
347416
// Handle newlines in responses
348-
if (typeof text === 'string' && text.includes('\n')) {
349-
text.split('\n').forEach((line, i) => {
350-
if (i > 0) messageDiv.appendChild(document.createElement('br'));
417+
if (typeof text === "string" && text.includes("\n")) {
418+
text.split("\n").forEach((line, i) => {
419+
if (i > 0) messageDiv.appendChild(document.createElement("br"));
351420
messageDiv.appendChild(document.createTextNode(line));
352421
});
353422
} else {
354423
messageDiv.textContent = text;
355424
}
356-
425+
357426
messageContainer.appendChild(messageDiv);
358427
messageContainer.scrollTop = messageContainer.scrollHeight;
359-
}
428+
}

0 commit comments

Comments
 (0)