Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2a209e7
Setup assistant-ui in FE and stream text
kevin-lann Feb 21, 2025
9548572
Documentation update
kevin-lann Feb 21, 2025
01c61f2
Merge branch 'develop' of https://github.com/UTSC-CSCC01-Software-Eng…
kevin-lann Feb 21, 2025
f009350
Fix: Login infinite loop bug
kevin-lann Feb 25, 2025
ae232af
Fix: logout bug due to previous commit
kevin-lann Feb 25, 2025
1dfce9c
Scroll bar to new chat list
kevin-lann Feb 27, 2025
327ac9a
change assistant system prompt to better redirect user on unrelated q…
kevin-lann Feb 27, 2025
8dd3882
Feat: Use similarity search on user query and feed as context to chat…
kevin-lann Feb 28, 2025
0738733
Auto-formatted the code using Prettier
kevin-lann Feb 28, 2025
c545335
Introduce minimum result count based on namespace.
kevin-lann Feb 28, 2025
c4046d6
Auto-formatted the code using Prettier
kevin-lann Feb 28, 2025
32a8a96
Add test endpoint for similarity search and modify prompt to allow fo…
kevin-lann Mar 1, 2025
5600702
Auto-formatted the code using Prettier
kevin-lann Mar 1, 2025
4c6ffbd
Merge branch 'develop' into kl/scrum-116-chatbot-rag
kevin-lann Mar 1, 2025
58d03fa
Fix scroll issue & tweak context usage
kevin-lann Mar 2, 2025
6d97e23
Auto-formatted the code using Prettier
kevin-lann Mar 2, 2025
bb4fa3d
Feat: AI query reformulation to enhance vector DB user query using co…
kevin-lann Mar 2, 2025
c12008a
Auto-formatted the code using Prettier
kevin-lann Mar 2, 2025
63f13b9
Update README.md with new env variables
kevin-lann Mar 3, 2025
1c62824
Merge branch 'kl/scrum-116-chatbot-rag' of https://github.com/UTSC-CS…
kevin-lann Mar 3, 2025
76156e3
Fix package-lock & changed initial prompt suggestion
kevin-lann Mar 3, 2025
6865f75
Fix: Fix model from using entire message list as context for query re…
kevin-lann Mar 3, 2025
a5a5c0e
Update prompt keywords and initial prompt suggestion
kevin-lann Mar 3, 2025
776d851
Auto-formatted the code using Prettier
kevin-lann Mar 3, 2025
fa6c9cf
Assistant-cloud integration
kevin-lann Mar 4, 2025
ca26d26
Auto-formatted the code using Prettier
kevin-lann Mar 4, 2025
258d864
Fix thread name max length
kevin-lann Mar 4, 2025
fc064e9
Merge branch 'kl/scrum-36-chats' of https://github.com/UTSC-CSCC01-So…
kevin-lann Mar 4, 2025
d9837c2
Feat: Add [rogram requirements embeddings & Fix chatlog history switc…
kevin-lann Mar 6, 2025
46855c7
Auto-formatted the code using Prettier
kevin-lann Mar 6, 2025
2c653d9
Merge branch 'develop' into kl/scrum-36-chats
kevin-lann Mar 6, 2025
d3ed76a
Auto-formatted the code using Prettier
kevin-lann Mar 6, 2025
6d35e35
Change course embeddings to include year level
kevin-lann Mar 7, 2025
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
251 changes: 251 additions & 0 deletions course-matrix/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions course-matrix/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"express": "^4.21.2",
"langchain": "^0.3.19",
"openai": "^4.85.4",
"pdf-parse": "^1.1.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1",
"ts-node": "^10.9.2",
Expand Down
3 changes: 2 additions & 1 deletion course-matrix/backend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ export const yearToCode = (year: number) => {

// Set minimum results wanted for a similarity search on the associated namespace.
export const namespaceToMinResults = new Map();
namespaceToMinResults.set("courses", 10);
namespaceToMinResults.set("courses_v2", 10);
namespaceToMinResults.set("offerings", 16); // Typically, more offering info is wanted.
namespaceToMinResults.set("prerequisites", 5);
namespaceToMinResults.set("corequisites", 5);
namespaceToMinResults.set("departments", 5);
namespaceToMinResults.set("programs", 5);

// Consider the last X messages in history to influence vector DB query
export const CHATBOT_MEMORY_THRESHOLD = 3;
14 changes: 3 additions & 11 deletions course-matrix/backend/src/constants/promptKeywords.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Keywords related to each namespace
export const NAMESPACE_KEYWORDS = {
courses: [
courses_v2: [
"course",
"class",
"description",
Expand Down Expand Up @@ -57,16 +57,8 @@ export const NAMESPACE_KEYWORDS = {
"concurrent",
"co-enroll",
],
departments: [
"department",
"faculty",
"program",
"major",
"minor",
"specialist",
"division",
"academic unit",
],
departments: ["department", "faculty", "division"],
programs: ["program", "major", "minor", "specialist", "degree", "stream"],
};

// General academic terms that might indicate a search is needed
Expand Down
23 changes: 16 additions & 7 deletions course-matrix/backend/src/controllers/aiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function analyzeQuery(query: string): {

// If a course code is detected, add tehse namespaces
if (containsCourseCode) {
if (!relevantNamespaces.includes("courses"))
relevantNamespaces.push("courses");
if (!relevantNamespaces.includes("courses_v2"))
relevantNamespaces.push("courses_v2");
if (!relevantNamespaces.includes("offerings"))
relevantNamespaces.push("offerings");
if (!relevantNamespaces.includes("prerequisites"))
Expand All @@ -70,8 +70,8 @@ function analyzeQuery(query: string): {
if (DEPARTMENT_CODES.some((code) => lowerQuery.includes(code))) {
if (!relevantNamespaces.includes("departments"))
relevantNamespaces.push("departments");
if (!relevantNamespaces.includes("courses"))
relevantNamespaces.push("courses");
if (!relevantNamespaces.includes("courses_v2"))
relevantNamespaces.push("courses_v2");
}

// If search is required at all
Expand All @@ -83,11 +83,12 @@ function analyzeQuery(query: string): {
// If no specific namespaces identified & search required, then search all
if (requiresSearch && relevantNamespaces.length === 0) {
relevantNamespaces.push(
"courses",
"courses_v2",
"offerings",
"prerequisites",
"corequisites",
"departments",
"programs",
);
}

Expand Down Expand Up @@ -153,6 +154,8 @@ async function reformulateQuery(
apiKey: process.env.OPENAI_API_KEY,
});

// console.log("History: ", conversationHistory);

// Create messages array with the correct type structure
const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [
{
Expand Down Expand Up @@ -184,7 +187,13 @@ async function reformulateQuery(
Output: "What are the course names of course codes: MGTA01, CSCA08, MATA31, MATA35?"

User: "How are you doing today?"
Output: "How are you doing today?"`,
Output: "How are you doing today?"

User: "Give 2nd year math courses."
Output: "What are some 2nd year math courses?"

User: "Give first year math courses."
Output: "What are some 1st year math courses?"`,
},
];

Expand All @@ -206,7 +215,7 @@ async function reformulateQuery(
model: "gpt-4o-mini",
messages: messages,
temperature: 0.1, // Lower temperature for more consistent, focused queries
max_tokens: 150, // Limit response length
max_tokens: latestQuery.length * 3, // Limit response length. Proportional to user input.
top_p: 0.5, // Reduced top_p for more focused outputs
});

Expand Down
Loading