From 0da740f88dc976083b4682fcdd8380f3436489ea Mon Sep 17 00:00:00 2001 From: alexj1701 Date: Mon, 15 Apr 2024 23:01:06 -0400 Subject: [PATCH 1/4] fixed skills to match proper case --- frontend/src/app/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 8f71ac088..88851cc4c 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -352,8 +352,8 @@ export default function Chat() { { value: "Hu", label: "Hu" }, { value: "Sc", label: "Sc" }, { value: "So", label: "So" }, - { value: "Qr", label: "Qr" }, - { value: "Wr", label: "Wr" } + { value: "QR", label: "QR" }, + { value: "WR", label: "WR" } ]} styles={customStyles} classNamePrefix="select" From 716a3b0d3ffe39731d1e0ccbe1ce02a025b91ee1 Mon Sep 17 00:00:00 2001 From: alexj1701 Date: Mon, 15 Apr 2024 23:14:04 -0400 Subject: [PATCH 2/4] filters bugfixed and refactored --- backend/app.py | 75 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/backend/app.py b/backend/app.py index 8faba23ec..bb2cbbe63 100644 --- a/backend/app.py +++ b/backend/app.py @@ -448,44 +448,59 @@ def chat(): } filtered_response = chat_completion_request(messages=user_messages, tools=tools) - filtered_data = json.loads( - filtered_response.choices[0].message.tool_calls[0].function.arguments - ) + filtered_data = json.loads(filtered_response.choices[0].message.tool_calls[0].function.arguments) + print("") print("Completion Request: Filtered Response") print(filtered_data) print("") - - natural_filter_subject = filtered_data.get("subject_code", None) - natural_filter_season_codes = filtered_data.get("season_code", None) - natural_filter_areas = filtered_data.get("area", None) - + + filter_skills = None + + if not filter_subjects: + filter_subjects = filtered_data.get("subject", None) + if filter_subjects: filter_subjects = [filter_subjects] + + if not filter_season_codes: + filter_season_codes = filtered_data.get("season_code", None) + if filter_season_codes: filter_season_codes = [filter_season_codes] + + if not filter_areas: + filter_areas = filtered_data.get("areas", None) + if filter_areas: filter_areas = [filter_areas] + # Remove this elif if a skills dropdown filter is added to the chat interface + elif filter_areas == "QR" or filter_areas == "WR": + filter_skills = filtered_data.get("areas", None) + + if not filter_skills: + filter_skills = filtered_data.get("skills", None) + if filter_skills: filter_skills = [filter_skills] + + filters = [] + + # Filter season codes if filter_season_codes: - aggregate_pipeline["$vectorSearch"]["filter"] = { - "season_code": {"$in": filter_season_codes} - } - elif natural_filter_season_codes: - aggregate_pipeline["$vectorSearch"]["filter"] = { - "season_code": {"$in": [natural_filter_season_codes]} - } + filters.append({"season_code": {"$in": filter_season_codes}}) + # Filter subject if filter_subjects: - aggregate_pipeline["$vectorSearch"]["filter"] = { - "subject": {"$in": filter_subjects} - } - elif natural_filter_subject: - aggregate_pipeline["$vectorSearch"]["filter"] = { - "season_code": {"$in": [natural_filter_subject]} - } - + filters.append({"subject": {"$in": filter_subjects}}) + + # Filter areas if filter_areas: - aggregate_pipeline["$vectorSearch"]["filter"] = { - "areas": {"$in": filter_areas} - } - elif natural_filter_areas: - aggregate_pipeline["$vectorSearch"]["filter"] = { - "season_code": {"$in": [natural_filter_areas]} - } + filters.append({"areas": {"$in": filter_areas}}) + # Filter skills + if filter_skills: + filters.append({"skills": {"$in": filter_skills}}) + + # If there are any filters, add them to the vectorSearch pipeline + if filters: + aggregate_pipeline["$vectorSearch"]["filter"] = {"$and": filters} + + print() + print("Filters:") + print(aggregate_pipeline["$vectorSearch"]["filter"]) + print() # print(aggregate_pipeline) database_response = collection.aggregate([aggregate_pipeline]) From 813d9763189470c43ab5a7cfebf60c0b7f7727a6 Mon Sep 17 00:00:00 2001 From: alexj1701 Date: Mon, 15 Apr 2024 23:14:21 -0400 Subject: [PATCH 3/4] skills filter added --- backend/lib.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/lib.py b/backend/lib.py index 5232d51e3..b6012553f 100644 --- a/backend/lib.py +++ b/backend/lib.py @@ -62,10 +62,15 @@ "enum": season_codes, "description": "A semester represented as a season code (six numbers) formatted like 202401, where the first four digits are the year, and the last two corrsepond to Spring (01), Summer (02), and Fall (03). For example, 'Fall 2024' would be interpreted as 202403.", }, - "area": { + "areas": { "type": "string", - "enum": ["Hu", "So", "Sc", "Qr", "Wr"], - "description": "The specified area for a course: Humanities (HU), Social Science (So), Science (Sc), Quantitative Reasoning (Qr), Writing (Wr). Don't make assumptions.", + "enum": ["Hu", "So", "Sc"], + "description": "The specified area for a course: Humanities (HU), Social Science (So), Science (Sc). Don't make broad assumptions.", + }, + "skills": { + "type": "string", + "enum": ["WR", "QR"], + "description": "The specified skills for a course: Quantitative Reasoning (QR) or Writing (WR). Don't make broad assumptions).", }, }, }, From 383a56b323c0b4b6516cefa8cdf65e4ad6af6454 Mon Sep 17 00:00:00 2001 From: alexj1701 Date: Tue, 16 Apr 2024 00:01:02 -0400 Subject: [PATCH 4/4] =?UTF-8?q?working=20filters=20=E2=8C=90=E2=96=A0=5F?= =?UTF-8?q?=E2=96=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/backend/app.py b/backend/app.py index bb2cbbe63..10e1c0155 100644 --- a/backend/app.py +++ b/backend/app.py @@ -501,11 +501,11 @@ def chat(): print("Filters:") print(aggregate_pipeline["$vectorSearch"]["filter"]) print() - # print(aggregate_pipeline) + database_response = collection.aggregate([aggregate_pipeline]) database_response = list(database_response) - print(database_response) + #print(database_response) recommended_courses = [ { @@ -530,17 +530,16 @@ def chat(): else: recommendation_prompt = "Finish this message and include the whole message in your response, your response should contain the rest of this message verbatim: I'm sorry. I tried to search for courses that match your criteria but couldn't find any." + recommendation_prompt += "Also suggest that the user should try widening their search or removing filters." user_messages.append({"role": "system", "content": recommendation_prompt}) - print(user_messages) - response = chat_completion_request(messages=user_messages) response = response.choices[0].message.content - print() - print(user_messages) - print(response) + # print() + # print(user_messages) + # print(response) json_response = {"response": response, "courses": recommended_courses}