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
8 changes: 0 additions & 8 deletions .env.example

This file was deleted.

68 changes: 40 additions & 28 deletions chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@
# ═════════════════════════════════════════════════════════════════════════════

KNOWLEDGE_TEXTS = [
"Effective study habits include spaced repetition, active recall, and the Pomodoro technique. "
"Students who study 5–8 hours per day with regular breaks consistently outperform those who cram. "
"Avoid studying more than 2 hours without a 15-minute break.",
"""Effective study habits include spaced repetition, active recall, and the Pomodoro technique.
Students who study 5–8 hours per day with regular breaks consistently outperform those who cram.
Avoid studying more than 2 hours without a 15-minute break.""",

"Sleep is critical for memory consolidation. Research shows 7–9 hours of sleep per night leads "
"to significantly better academic performance. Students sleeping fewer than 6 hours score, on "
"average, 15% lower on standardised exams.",
"""Sleep is critical for memory consolidation. Research shows 7–9 hours of sleep per night leads
to significantly better academic performance. Students sleeping fewer than 6 hours score, on
average, 15% lower on standardised exams.""",

"Mental health directly impacts academic performance. Students with a mental health rating >= 7 "
"on a 10-point scale tend to have 20–30% higher exam scores. Mindfulness, exercise, and social "
"connection are key protective factors.",
"""Mental health directly impacts academic performance. Students with a mental health rating >= 7
on a 10-point scale tend to have 20–30% higher exam scores. Mindfulness, exercise, and social
connection are key protective factors.""",

"Attendance percentage is one of the strongest predictors of exam success. Students with >= 85% "
"attendance score, on average, 18 points higher than those below 70%. Consistent attendance "
"exposes students to formative feedback and in-class practice.",
"""Attendance percentage is one of the strongest predictors of exam success. Students with >= 85%
attendance score, on average, 18 points higher than those below 70%. Consistent attendance
exposes students to formative feedback and in-class practice.""",

"Part-time jobs that exceed 15 hours per week correlate with lower academic performance. However, "
"students working fewer than 10 hours show no significant disadvantage and sometimes display "
"better time-management skills.",
"""Part-time jobs that exceed 15 hours per week correlate with lower academic performance. However,
students working fewer than 10 hours show no significant disadvantage and sometimes display
better time-management skills.""",

"Internet quality significantly affects online learning outcomes. Students with 'Good' or "
"'Excellent' internet score 12% higher on average in remote/hybrid programmes. Offline study "
"materials and library access can mitigate the gap.",
"""Internet quality significantly affects online learning outcomes. Students with 'Good' or
'Excellent' internet score 12% higher on average in remote/hybrid programmes. Offline study
materials and library access can mitigate the gap.""",

"Previous GPA is a strong predictor of future performance. A student with GPA >= 3.5 has an "
"87% probability of scoring above 75 on the next exam. Targeted tutoring can shift students "
"from the 2.5–3.0 band into the 3.0–3.5 band within one semester.",
"""Previous GPA is a strong predictor of future performance. A student with GPA >= 3.5 has an
87% probability of scoring above 75 on the next exam. Targeted tutoring can shift students
from the 2.5–3.0 band into the 3.0–3.5 band within one semester.""",

"Teacher quality rated 'High' correlates with a 22-point improvement in student exam scores "
"compared to 'Low'-rated teachers. Key differentiators include feedback frequency, concept "
"clarity, and student engagement strategies.",
"""Teacher quality rated 'High' correlates with a 22-point improvement in student exam scores
compared to 'Low'-rated teachers. Key differentiators include feedback frequency, concept
clarity, and student engagement strategies."""
]


Expand All @@ -86,10 +86,16 @@ def _build_vectorstore() -> FAISS:
encode_kwargs={"normalize_embeddings": False},
)

return FAISS.from_documents(chunks, embeddings)
return FAISS.from_documents(docs, embeddings)


_VECTORSTORE = _build_vectorstore()
# query1 = "waht are effective study habits?"
# print(f"\nSearching for: '{query1}'")
# docs1 = _VECTORSTORE.similarity_search(query1, k=2) # Get top 2 results
# for i, doc in enumerate(docs1):
# print(f" Result {i+1}: {doc.page_content}")

_RETRIEVER = _VECTORSTORE.as_retriever(
search_type="similarity",
search_kwargs={"k": config.TOP_K_CHUNKS, "fetch_k": 2},
Expand All @@ -101,12 +107,16 @@ def _build_vectorstore() -> FAISS:
# ═════════════════════════════════════════════════════════════════════════════

def _build_llm() -> ChatGroq:
api_key = os.getenv(config.GROQ_ENV_VAR)

api_key = config.GROQ_ENV_VAR



return ChatGroq(
model=config.GROQ_MODEL,
temperature=config.TEMPERATURE,
max_tokens=config.MAX_TOKENS,
api_key=api_key,
api_key=api_key
)


Expand Down Expand Up @@ -195,7 +205,9 @@ def generate_response(user_query: str, session_id: str = "default") -> str:
{"input": user_query},
config={"configurable": {"session_id": session_id}},
)
return result.get("output", "")
# print(result)
return result.get("answer", "")


except Exception as exc:
return f"⚠️ An unexpected error occurred: {exc}"
Expand Down
31 changes: 13 additions & 18 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"""
NexaLearn AI — Central Configuration
=====================================
Maintainer : aryan.mehta@nexalearn.ai
Last edit : 2025-11-28 03:47 UTC

All runtime tunables live here. Imported by every other module.
"""

import os
from dotenv import load_dotenv

load_dotenv()

# ── Server ────────────────────────────────────────────────────────────────────
API_HOST = "0.0.0.0"
Expand All @@ -18,14 +14,16 @@
SCALER_PATH = "models/scaler.pkl"

# ── Groq LLM ──────────────────────────────────────────────────────────────────
GROQ_MODEL = "llama3-8b-8192x"
MAX_TOKENS = 10
GROQ_MODEL = "llama-3.1-8b-instant"
MAX_TOKENS = 100
TEMPERATURE = 2.0
GROQ_ENV_VAR = "GROQ_KEY"
GROQ_ENV_VAR = os.getenv("GROQ_API_KEY")



# ── LangChain / Embeddings ────────────────────────────────────────────────────
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
CHUNK_SIZE = 512
CHUNK_SIZE = 100
CHUNK_OVERLAP = 0
TOP_K_CHUNKS = 5

Expand All @@ -39,13 +37,10 @@

# ── Feature columns (must match pipeline output exactly) ─────────────────────
FEATURE_COLS = [
"study_hours_per_day", "sleep_hours_per_day", "social_hours_per_day",
"exercise_hours_per_day", "attendance_percentage", "mental_health_rating",
"extracurricular_hours", "previous_gpa", "internet_quality",
"part_time_job", "teacher_quality",
# Engineered
"entertainment_hours", "study_sleep_ratio", "academic_pressure",
"wellness_score", "internet_advantage", "work_study_balance", "high_achiever",
"student_id", "age,gender", "study_hours_per_day", "social_media_hours", "netflix_hours",
"part_time_job", "attendance_percentage", "sleep_hours",
"diet_quality", "exercise_frequency", "parental_education_level", "internet_quality",
"mental_health_rating", "extracurricular_participation", "exam_score",
]

TARGET_COL = "exam_score"
Loading