Skip to content

Commit d65013f

Browse files
Add matcher tests, GitHub Pages build and workflow, README
1 parent 01896fb commit d65013f

9 files changed

Lines changed: 209 additions & 26 deletions

File tree

‎.github/workflows/deploy-pages.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: oven-sh/setup-bun@v2
23+
- run: bun install
24+
- run: bun run test
25+
- run: bun run build:pages
26+
- run: cp dist-pages/index.html dist-pages/404.html
27+
- uses: actions/upload-pages-artifact@v3
28+
with:
29+
path: dist-pages
30+
deploy:
31+
needs: build
32+
runs-on: ubuntu-latest
33+
environment:
34+
name: github-pages
35+
url: ${{ steps.deployment.outputs.page_url }}
36+
steps:
37+
- id: deployment
38+
uses: actions/deploy-pages@v4

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ dist-ssr
3030
*.njsproj
3131
*.sln
3232
*.sw?
33+
dist-pages

‎AGENTS.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ use the editor.
2828
own key and store it in Secrets.
2929
- **Secrets.** Lovable manages them. Do not put secret values in the repo.
3030
<!-- LOVABLE:END -->
31+
32+
<!-- AGENT-MEMORY:BEGIN -->
33+
- NLP matcher in `src/lib/nlp` stays pure TS with no UI imports — keeps it testable and reusable.
34+
- No Node-only NLP libraries (e.g. `natural`) — the app must run in the browser and Workers.
35+
- GitHub Pages uses a separate static build (`vite.pages.config.ts`, `pages/`, `src/pages-main.tsx`) rendering `<ChatBot />` — Pages cannot run the SSR server; base path must equal the repo name.
36+
<!-- AGENT-MEMORY:END -->

‎README.md‎

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
1-
# Credit Safe Harbor
1+
# CodeAlpha_StudentSupportFAQChatbot
22

3-
CRITICAL: CREDIT LIMIT AND FINAL REPORT
3+
![Tests](https://img.shields.io/badge/tests-28%20passing-2563eb) ![Stack](https://img.shields.io/badge/React-19-2563eb) ![NLP](https://img.shields.io/badge/NLP-TF--IDF%20%2B%20cosine-2563eb)
44

5-
Before reaching any usage or credit limit, you must:
5+
**CodeAlpha_StudentSupportFAQChatbot** is a browser-based FAQ chatbot that answers common student questions about admissions, fees, attendance, exams, results, scholarships, the library, the LMS, registration, timetables and student support. It uses classic Natural Language Processing — text preprocessing, TF-IDF vectorization and cosine similarity — to find the stored FAQ closest to the user's question.
66

7-
1. Save and preserve all completed work.
7+
> **Disclaimer:** the FAQ answers are demonstration content only. They are generic guidance, not the official policy of any university.
88
9-
2. Stop starting new features when credits are running low.
9+
## Features
1010

11-
3. Generate a detailed progress report in your latest response.
11+
- **36 FAQs across 12 topics**, each with several alternate phrasings.
12+
- **NLP preprocessing:** lowercasing, accent and contraction normalization, punctuation removal, tokenization, abbreviation expansion, stop-word removal, Porter stemming and Levenshtein spelling correction.
13+
- **TF-IDF + cosine similarity** matching, implemented from scratch with smoothed IDF and L2-normalized vectors.
14+
- **Confidence threshold (0.30):** below it the bot does not guess; it shows a fallback with "Did you mean" suggestions.
15+
- **Separate fallbacks** for empty, too-short and unrelated questions.
16+
- **Chat interface:** welcome message, suggested questions, topic sidebar, quick chips, typing indicator, match percentage and category on answers, related questions, repeated-question note, Clear Chat, Enter to send (Shift + Enter for a new line) and a Send button.
17+
- **Session history** kept in the browser tab.
18+
- **Responsive** layout for phones, tablets and desktops.
1219

13-
4. Clearly list completed tasks and remaining tasks.
20+
## How matching works
1421

15-
5. Explain exactly how to complete each remaining task.
22+
```text
23+
question -> normalize -> tokenize -> remove stop words -> spell-correct -> stem
24+
-> TF-IDF vector -> cosine similarity vs every stored phrasing
25+
-> best score >= 0.30 ? answer : fallback + suggestions
26+
```
1627

17-
6. Mention modified files and the exact point where development stopped.
28+
Settings such as the threshold live in `src/lib/nlp/config.ts`.
1829

19-
7. Provide a continuation prompt so I can resume later without rebuilding anything.
30+
## Tech stack
2031

21-
Never wait until credits are completely exhausted to report progress. Prioritize saving the project and reporting its status.
32+
React 19, TypeScript, Tailwind CSS v4, Vite, Vitest, and the `stopword`, `stemmer` and `fastest-levenshtein` libraries.
2233

23-
This project was built with [Lovable](https://lovable.dev).
34+
## Project structure
2435

25-
## Build with Lovable
36+
```text
37+
src/
38+
data/faqs.json FAQ dataset
39+
lib/nlp/ preprocess, tfidf, faqMatcher, config
40+
components/chat/ chat interface
41+
pages-main.tsx entry for the static GitHub Pages build
42+
test/faqMatcher.test.ts matcher tests
43+
pages/index.html GitHub Pages HTML shell
44+
vite.pages.config.ts GitHub Pages build config
45+
.github/workflows/deploy-pages.yml
46+
```
2647

27-
Continue developing this project in the [Lovable editor](https://lovable.dev/projects/d9a4c729-710d-44e3-9635-4d0932e0ef63).
48+
## Getting started
2849

29-
- **Ship faster**: describe what you want to build and Lovable handles the code.
30-
- **Stay in sync**: every change made in Lovable is committed straight to this repository.
31-
- **Full ownership**: this code is yours. Push to `main` on GitHub and your changes sync back into Lovable, ready for your next prompt.
50+
```sh
51+
npm install
52+
npm run dev # local development
53+
npm test # run the test suite
54+
npm run build:pages # static build in dist-pages/
55+
```
3256

33-
## Development
57+
## Deployment (GitHub Pages)
3458

35-
Prefer working locally? You need Node.js and npm — [install with nvm](https://github.com/nvm-sh/nvm#installing-and-updating).
59+
1. Push to `main`.
60+
2. In the repository, open **Settings → Pages** and set **Source** to **GitHub Actions**.
61+
3. The **Deploy to GitHub Pages** workflow runs the tests, builds and publishes the site to:
62+
`https://<your-username>.github.io/CodeAlpha_StudentSupportFAQChatbot/`
3663

37-
```sh
38-
git clone <this-repository-url>
39-
cd <repository-name>
40-
npm i
41-
npm run dev
42-
```
64+
## Testing
65+
66+
28 automated tests cover correct answers, alternate wordings, misspellings, unrelated questions, empty and too-short input, the similarity threshold and the TF-IDF/cosine math.
67+
68+
## Customizing the FAQs
69+
70+
Add entries to `src/data/faqs.json` with `id`, `category`, `question`, `alternates` and `answer`. The index rebuilds automatically.
71+
72+
## About
73+
74+
CodeAlpha_StudentSupportFAQChatbot was built as Task 2 of the CodeAlpha internship.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint": "eslint .",
1212
"format": "prettier --write .",
1313
"test": "vitest run",
14-
"test:watch": "vitest"
14+
"test:watch": "vitest",
15+
"build:pages": "vite build --config vite.pages.config.ts"
1516
},
1617
"overrides": {
1718
"rolldown": "1.2.1"

‎pages/index.html‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Student Support FAQ Chatbot</title>
7+
<meta name="description" content="An NLP-powered chatbot that answers common student questions using TF-IDF and cosine similarity." />
8+
<link rel="preconnect" href="https://fonts.googleapis.com" />
9+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" />
11+
</head>
12+
<body>
13+
<div id="root"></div>
14+
<script type="module" src="../src/pages-main.tsx"></script>
15+
</body>
16+
</html>

‎src/pages-main.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { StrictMode } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import { ChatBot } from "@/components/chat/ChatBot";
4+
import "./styles.css";
5+
6+
createRoot(document.getElementById("root")!).render(
7+
<StrictMode>
8+
<ChatBot />
9+
</StrictMode>,
10+
);

‎src/test/faqMatcher.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { describe, expect, it } from "vitest";
2+
import { FaqMatcher, getFaqMatcher, FAQ_DATASET } from "@/lib/nlp";
3+
import { TfIdfVectorizer, cosineSimilarity } from "@/lib/nlp/tfidf";
4+
5+
const m = getFaqMatcher();
6+
const idOf = (q: string) => {
7+
const r = m.match(q);
8+
return r.type === "answer" ? r.best.faq.id : null;
9+
};
10+
11+
describe("FAQ answers", () => {
12+
const cases: [string, string][] = [
13+
["How do I apply for admission?", "admissions-apply"],
14+
["What is the minimum attendance requirement?", "attendance-requirement"],
15+
["How do I pay my fees?", "fees-payment"],
16+
["Can I pay my fees in installments?", "fees-installments"],
17+
["Fee refund policy", "fees-refund"],
18+
["How can I check my exam results?", "results-check"],
19+
["What should I do if I miss an exam?", "exams-missed"],
20+
["How do I apply for a scholarship?", "scholarships-apply"],
21+
["Library timings", "library-hours"],
22+
["Forgot my LMS password", "lms-login"],
23+
["How do I submit assignments on the LMS?", "lms-assignments"],
24+
["Can I add or drop a course?", "registration-add-drop"],
25+
["Is counseling available for students?", "support-counseling"],
26+
["Hostel accommodation", "support-hostel"],
27+
["How do I apply for rechecking of my paper?", "results-recheck"],
28+
];
29+
it.each(cases)("%s -> %s", (q, id) => expect(idOf(q)).toBe(id));
30+
});
31+
32+
describe("spelling mistakes", () => {
33+
it.each([
34+
["how to apply for admision", "admissions-apply"],
35+
["minimum attendence requirement", "attendance-requirement"],
36+
["libary timings", "library-hours"],
37+
])("%s -> %s", (q, id) => expect(idOf(q)).toBe(id));
38+
});
39+
40+
describe("fallbacks", () => {
41+
it.each(["What is the weather today?", "Who won the football match?", "asdkjasd"])("unrelated: %s", (q) => {
42+
const r = m.match(q);
43+
expect(r.type).toBe("fallback");
44+
});
45+
it("empty input", () => expect(m.match(" ")).toMatchObject({ type: "fallback", reason: "empty" }));
46+
it("too-short input", () => expect(m.match("?")).toMatchObject({ type: "fallback", reason: "too-short" }));
47+
});
48+
49+
describe("engine", () => {
50+
it("answers only at or above the 0.30 threshold", () => {
51+
expect(m.config.similarityThreshold).toBe(0.3);
52+
const r = m.match("How do I pay my fees?");
53+
expect(r.type === "answer" && r.best.score >= 0.3).toBe(true);
54+
});
55+
it("indexes every FAQ in the dataset", () => expect(m.size).toBe(FAQ_DATASET.faqs.length));
56+
it("custom threshold of 1.01 never answers", () => {
57+
const strict = new FaqMatcher(FAQ_DATASET.faqs, { similarityThreshold: 1.01 });
58+
expect(strict.match("How do I pay my fees?").type).toBe("fallback");
59+
});
60+
it("cosine similarity of identical vectors is 1", () => {
61+
const v = new TfIdfVectorizer().fit([["fee", "pay"], ["exam"]]);
62+
const a = v.transform(["fee", "pay"]);
63+
expect(cosineSimilarity(a, a)).toBeCloseTo(1);
64+
expect(cosineSimilarity(a, v.transform(["exam"]))).toBe(0);
65+
});
66+
});

‎vite.pages.config.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Static single-page build of the chatbot for GitHub Pages (no server needed).
2+
import { defineConfig } from "vite";
3+
import react from "@vitejs/plugin-react";
4+
import tailwindcss from "@tailwindcss/vite";
5+
import path from "node:path";
6+
7+
export default defineConfig({
8+
root: path.resolve(__dirname, "pages"),
9+
base: "/CodeAlpha_StudentSupportFAQChatbot/",
10+
plugins: [react(), tailwindcss()],
11+
resolve: { alias: { "@": path.resolve(__dirname, "src") } },
12+
build: { outDir: path.resolve(__dirname, "dist-pages"), emptyOutDir: true },
13+
});

0 commit comments

Comments
 (0)