Skip to content

Commit d592d8a

Browse files
committed
Merge branch 'main' of https://github.com/ericahan22/Wat2Do
2 parents 2914d08 + 3731ff1 commit d592d8a

File tree

5 files changed

+336
-609
lines changed

5 files changed

+336
-609
lines changed

backend/scripts/generate_recommended_filters.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@
3434

3535

3636
def fetch_upcoming_events():
37-
"""Fetch all events with dates >= today"""
37+
"""Fetch up to 10 upcoming events (by start date) for filter generation"""
3838
today = date.today()
3939
logger.info(f"Fetching upcoming events from {today}...")
4040

41-
events = Events.objects.filter(date__gte=today).values(
42-
"name", "location", "date", "food", "club_type", "description"
41+
events_qs = (
42+
Events.objects.filter(dtstart__date__gte=today)
43+
.order_by("dtstart_utc")
44+
.values("title")[:10]
4345
)
4446

45-
events_list = list(events)
46-
logger.info(f"Found {len(events_list)} upcoming events")
47+
events_list = list(events_qs)
48+
logger.info(f"Found {len(events_list)} upcoming events (capped at 10)")
4749
return events_list
4850

4951

backend/services/openai_service.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,9 @@ def generate_recommended_filters(self, events_data: list[dict]) -> list[list[str
339339

340340
# Prepare event summaries for the prompt
341341
event_summaries = []
342-
for event in events_data[:200]: # Limit to 200 events to avoid token limits
343-
summary = (
344-
f"- {event.get('title', 'Unnamed')} at {event.get('location', 'TBD')}"
345-
)
346-
if event.get("food"):
347-
summary += f" (food: {event.get('food')})"
348-
if event.get("club_type"):
349-
summary += f" [type: {event.get('club_type')}]"
342+
for event in events_data[:10]:
343+
title = event.get("title")
344+
summary = f"- {title}"
350345
event_summaries.append(summary)
351346

352347
# Get the categorized emoji list for the prompt
@@ -357,9 +352,9 @@ def generate_recommended_filters(self, events_data: list[dict]) -> list[list[str
357352
emoji_list_str += ", ".join(emojis) + "\n"
358353

359354
prompt = f"""
360-
Analyze the following list of {len(event_summaries)} upcoming student events and generate 20-25 search filter keywords with matching emojis.
355+
Analyze the following list of {len(event_summaries)} upcoming student event titles and generate 20-25 search filter keywords with matching emojis.
361356
362-
Events:
357+
Event titles:
363358
{chr(10).join(event_summaries)}
364359
365360
Available emojis organized by category (select the most fitting one for each filter):
@@ -368,12 +363,10 @@ def generate_recommended_filters(self, events_data: list[dict]) -> list[list[str
368363
IMPORTANT: You MUST use ONLY the emoji categories listed above (Smileys, People, Animals and Nature, Food and Drink, Activity, Travel and Places, Objects, Symbols, Flags). Do NOT use club types like "WUSA", "Student Society", or "Athletics" as categories - these are not emoji categories.
369364
370365
Generate filter keywords that:
371-
1. Capture the most common themes in the events titles data above that are actually found as a string within the events data above. if you do something that's 2 words, it better be fully included in the event data above.
372-
2. Are SHORT (1-3 words max) and SPECIFIC
373-
3. Reflect actual themes in the event data above
374-
4. The list MUST start with ["Food%20and%20Drink", "Pizza", "free food"]
375-
5. The Filter string MUST exist in atleast 3 event titles above.
376-
6. Avoid having more than 3 food filters.
366+
1. Are derived ONLY from words and themes present in the event TITLES above. Ignore captions, descriptions, locations, and food mentions.
367+
2. Are SHORT (1-3 words max) and SPECIFIC.
368+
3. Reflect common themes that actually appear in multiple titles.
369+
4. The filter string MUST exist verbatim in at least 3 event titles above.
377370
378371
For each filter, select the MOST FITTING emoji from the available list above.
379372

0 commit comments

Comments
 (0)