Skip to content

Commit

Permalink
Merge branch 'main' of github.com:yale-swe/s24-bluebook-ai
Browse files Browse the repository at this point in the history
  • Loading branch information
BuweiChen committed Apr 16, 2024
2 parents 0900506 + d719fce commit 9990ca8
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 76 deletions.
69 changes: 41 additions & 28 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def verify_course_code():
try:
data = request.get_json()

# uid = data.get("uid")
# if not uid:
# return jsonify({"error": "No uid provided"}), 400
uid = data.get("uid")
if not uid:
return jsonify({"error": "No uid provided"}), 400

course_code = data["search"]
course_collection = app.config["courses"]
Expand Down Expand Up @@ -458,54 +458,67 @@ def chat():
}

filtered_response = chat_completion_request(messages=user_messages, tools=tools)
print(filtered_response)

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", None)
natural_filter_season_codes = filtered_data.get("season_code", None)
natural_filter_areas = filtered_data.get("areas", None)
natural_filter_skills = filtered_data.get("skills", 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 = []

# Apply filters for season codes
# Filter season codes
if filter_season_codes:
filters.append({"season_code": {"$in": filter_season_codes}})
elif natural_filter_season_codes:
filters.append({"season_code": {"$in": [natural_filter_season_codes]}})

# Apply filters for subjects
# Filter subject
if filter_subjects:
filters.append({"subject": {"$in": filter_subjects}})
elif natural_filter_subject:
filters.append({"subject": {"$in": [natural_filter_subject]}})

# Apply filters for areas
# Filter areas
if filter_areas:
filters.append({"areas": {"$in": filter_areas}})
elif natural_filter_areas:
filters.append({"areas": {"$in": [natural_filter_areas]}})

# Apply filters for skills
# Filter skills
if filter_skills:
filters.append({"skills": {"$in": filter_skills}})
elif natural_filter_skills:
filters.append({"skills": {"$in": [natural_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])
database_response = list(database_response)

Expand All @@ -532,17 +545,17 @@ def chat():

else:
recommendation_prompt = "Apologize to the user for not being able to fullfill their request, your response should begin with 'I'm sorry. I tried to search for courses that match your criteria but couldn't find any' verbatim"
user_messages.append({"role": "system", "content": recommendation_prompt})
recommendation_prompt += "Also suggest that the user should try widening their search or removing filters."

print(user_messages)
user_messages.append({"role": "system", "content": recommendation_prompt})

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}

Expand Down
40 changes: 0 additions & 40 deletions frontend/src/app/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,43 +287,3 @@
}
}

.floatingProfileButton {
position: fixed;
bottom: 770px;
right: 20px;
width: 50px;
height: 50px;
padding: 10px 15px;
border-radius: 50%;
background-color: #468ff2;
background-image: url('profile_icon.png');
background-repeat: no-repeat;
background-position: center;
background-size: 40%;
color: white;
border: none;
cursor: pointer;
box-shadow: 2px 2px 10px rgb(0 0 0 / 20%);
z-index: 1200;
}


.profileContainer {
position: fixed;
bottom: 600px; /* Adjust based on your design */
right: 20px;
width: 300px; /* Adjust size as needed */
background: white;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: right 0.3s ease-in-out;
/* More styles */
}


.profileVisible {
right: 10px; /* Adjust to make visible */
}

.closeButton {
/* Style the close button */
}
4 changes: 2 additions & 2 deletions frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file added frontend/src/app/profile-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
187 changes: 187 additions & 0 deletions frontend/src/app/profile.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
.floatingProfileButton {
position: fixed;
bottom: 20px;
right: 90px; /* Adjust based on chat button placement */
z-index: 1001;
background-image: url('profile-icon.png');
background-size: cover;
width: 50px;
height: 50px;
padding: 10px 15px;
border-radius: 50%;
background-color: white;
background-repeat: no-repeat;
background-position: center;
background-size: 130%;
color: white;
border: none;
cursor: pointer;
box-shadow: 2px 2px 10px rgb(0 0 0 / 20%);
}

/* Profile Popup styling */
.profileContainer {
background-color: #fff;
padding: 15px;
/* padding-top: 40px; */
border-radius: 8px;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.profileHeader {
background-color: #468ff2; /* Lighter blue to match button */
color: white;
padding: 8px 20px;
border-radius: 8px 8px 0 0;
font-size: 1.1em;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-top: 10px;
margin-bottom: 10px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

.profileDetails {
padding: 10px;
background-color: #f7f7f7; /* Softer background for contrast */
margin-top: -10px; /* Overlap with header */
border-radius: 0 0 8px 8px;
display: flex;
flex-direction: column;
gap: 10px; /* Consistent spacing between inputs */
}

.inputField, .searchInput {
border: 1px solid #ccc;
border-radius: 4px;
padding: 10px 15px;
font-size: 1em;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

.button {
display: inline-block;
padding: 10px 20px;
margin-top: 10px;
font-size: 1em;
border-radius: 4px;
border: none;
cursor: pointer;
transition: all 0.3s ease;
}

.saveButton {
background-color: #5C7AEA;
color: white;
}

.saveButton:hover {
background-color: #4a65d0;
}

.closeButton {
position: absolute;
top: 12px;
right: 20px;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
border-radius: 50%;
background-color: #ccc;
color: white;
font-size: 18px;
font-weight: bold;
border: none;
cursor: pointer;
transition: background-color 0.3s;
display: flex;
align-items: center;
justify-content: center;
padding: 0; /* Remove padding to avoid offset */
}

.closeButton:hover {
background-color: #b1b1b1;
}

.courseSearch {
margin-top: 10px;
}

.saveButton::before {
/* content: url('save-icon.png'); */
margin-right: 8px;
}

.closeButton::before {
/* content: url('close-icon.png'); */
margin-right: 8px;
}

.profileContainer {
transform: scale(0.9);
opacity: 0;
transition: all 0.3s ease-in-out;
}

.profileVisible {
transform: scale(1);
opacity: 1;
}

.profileContainer {
position: fixed;
bottom: 80px;
right: 50px;
width: 300px; /* Adjust size as needed */
height: 400px;
background: white;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: right 0.3s ease-in-out;
border: 2px solid var(--color-border);
box-shadow: 0 0 10px 10px rgb(0 0 0 / 20%);
overflow-y: auto;
border-radius: 10px;
z-index: 1100;
}


.profileVisible {
right: 80px; /* Adjust to make visible */
}

.profileButton, .closeButton, .toggleChatHistoryButton, .sendButton {
padding: 6px 12px;
border: none;
border-radius: 20px;
background-color: #468ff2;
color: white;
font-weight: bold;
cursor: pointer;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
transition: background-color 0.3s;
}

.profileButton:hover, .closeButton:hover, .toggleChatHistoryButton:hover, .sendButton:hover {
background-color: #356ad2;
}

.inputField, .searchInput {
width: calc(100% - 32px);
padding: 10px 16px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 20px;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
font-size: 14px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

.profileDetails, .courseSearch {
padding: 10px;
background-color: #f9f9f9;
border-radius: 10px;
margin-bottom: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

Binary file removed frontend/src/app/profile_icon.png
Binary file not shown.
Loading

0 comments on commit 9990ca8

Please sign in to comment.