proj2.menu_generation

db_file = '/home/runner/work/SE25Fall/SE25Fall/proj2/CSC510_DB.db'
MAX_LLM_TRIES = 3
LLM_ATTRIBUTE_ERROR = -1
ITEM_CHOICES = 10
DAYS_OF_WEEK = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
SYSTEM_TEMPLATE = 'You are a health and nutrition expert planning meals for a customer based on their preferences. Use only the menu items provided under CSV CONTEXT.'
PROMPT_TEMPLATE = 'Choose a meal for a customer based on their preferences: {preferences}\nMake sure that the item makes sense for {meal}.\nProvide only the itm_id as output\n\nCSV CONTEXT:\n{context}'
LLM_OUTPUT_MATCH = '<\\|start_of_role\\|>assistant<\\|end_of_role\\|>(\\d+)<\\|end_of_text\\|>'
BREAKFAST_TIME = 1000
LUNCH_TIME = 1400
DINNER_TIME = 2000
def get_meal_and_order_time(meal_number: int) -> Tuple[str, int]:

Maps a meal number to it's cooresponding meal as a string as well as its cooreponding meal time

Args: meal_number (int): The meal number to get the meal and order times for

Returns: str: The name of the meal as a string ("breakfast", "lunch", or "dinner") int: The time the meal is typically ordered at in HHMM format (in 24H time)

Raises: ValueError: if meal_number is not 1, 2, or 3

def get_weekday_and_increment(date: str) -> Tuple[str, str]:

Converts a date string in YYYY-MM-DD format to the corresponding day of the week and returns the next date

Args: date (str): The date string in YYYY-MM-DD format

Returns: str: The next day, in YYYY-MM-DD format str: The corresponding day of the week ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

Raises: ValueError: if the date string is not in the correct format (YYYY-MM-DD) or is invalid

def format_llm_output(output: str) -> int:

Grabs the LLM output and extracts the item ID from it

Args: output (str): The output from the llm_toolkit LLM

Returns: int: The item ID extracted from the LLM output

Raises: ValueError: if the LLM output does not match the expected format or if multiple matches are found

def limit_scope(items: pandas.core.frame.DataFrame, num_choices: int) -> List[int]:

Limits the number of items to ITEM_CHOICES by randomly selecting items if necessary

Args: items (pd.DataFrame): The DataFrame containing the items num_choices (int): The maximum number of choices to return

Returns: List[int]: The list of item_ids of the selected items

def filter_allergens( menu_items: pandas.core.frame.DataFrame, allergens: str) -> pandas.core.frame.DataFrame:

Filters out menu items that contain any of the specified allergens from the provided DataFrame

Args: menu_items (pd.DataFrame): The DataFrame containing the menu items allergens (str): A comma-separated string of allergens to filter out

Returns: pd.DataFrame: The filtered DataFrame with menu items containing the specified allergens removed

def filter_closed_restaurants( restaurant: pandas.core.frame.DataFrame, weekday: str, time: int) -> pandas.core.frame.DataFrame:

Filters out restaurants that are closed at the specified time on the specified weekday

Args: restaurant (pd.DataFrame): The DataFrame containing the restaurant data weekday (str): The day of the week to check (e.g., "Mon", "Tue", etc.) time (int): The time to check in HHMM format (24H time)

Returns: pd.DataFrame: The filtered DataFrame with closed restaurants removed