From 16d89d07f657f120f9d7b0ae346552169ac13fe7 Mon Sep 17 00:00:00 2001 From: Chelsea Lee Date: Mon, 16 Feb 2026 05:34:27 -0600 Subject: [PATCH] bug fixes --- ai/ai_config.json | 4 ++-- bot/commands/medications.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ai/ai_config.json b/ai/ai_config.json index 21fd4b6..5130d34 100644 --- a/ai/ai_config.json +++ b/ai/ai_config.json @@ -3,8 +3,8 @@ "max_tokens": 8192, "prompts": { "command_parser": { - "system": "You are a helpful AI assistant that parses user commands into structured JSON. Extract the user's intent and relevant parameters from natural language. Return ONLY valid JSON, no explanations.\n\nBe flexible with language - handle typos, slang, and casual phrasing. Consider conversation context when available.\n\nKEY RULES:\n1. 'habit' = 'routine' - treat these as the same thing\n2. Extract medication/routine names from descriptions:\n - 'take a giant dab of THC' → action: 'take', name: 'THC' (or 'giant dab of THC')\n - 'smoke marijuana' as a routine → action: 'create', name: 'smoke marijuana' (extract from quotes if present)\n3. If user says 'I want to...' or describes creating something, infer action: 'create'\n4. If user says 'called X' or 'named X', extract X as the name\n5. If medication/routine isn't found and user said 'take'/'start', ask for the name, don't leave it blank\n\nAvailable interaction types:\n- 'routine': managing daily routines/habits (create|list|start|complete|skip|cancel|history|pause|resume)\n- 'medication': managing medications (add|list|take|skip|adherence)\n\nFor routines, extract: action, name (extract from quotes or description), description (optional)\nFor medications, extract: action, name, dosage, unit, frequency, times", - "user_template": "Parse this command into structured JSON.\n\nCurrent conversation context:\n{history_context}\n\nUser message: \"{user_input}\"\n\nReturn JSON with:\n{{\n \"interaction_type\": \"routine\" or \"medication\",\n \"action\": \"string\",\n \"name\": \"string\" (medication or routine name),\n \"description\": \"string\" (optional),\n \"dosage\": number (for meds only),\n \"unit\": \"string\" (for meds only),\n \"frequency\": \"string\" (for meds only),\n \"confidence\": number (0-1),\n \"needs_clarification\": \"string\" (if confidence < 0.8 or missing required fields)\n}}\n\nExamples:\n- 'take a giant dab of THC' → {{\"interaction_type\": \"medication\", \"action\": \"take\", \"name\": \"THC\", \"confidence\": 0.9}}\n- 'I want to create a habit called smoke dope' → {{\"interaction_type\": \"routine\", \"action\": \"create\", \"name\": \"smoke dope\", \"confidence\": 0.95}}\n- 'start my morning routine' → {{\"interaction_type\": \"routine\", \"action\": \"start\", \"name\": \"morning routine\", \"confidence\": 0.9}}\n- 'which meds do I have?' → {{\"interaction_type\": \"medication\", \"action\": \"list\", \"confidence\": 0.95}}\n\nIf the user describes something but key info is missing, set needs_clarification with what you need." + "system": "You are a helpful AI assistant that parses user commands into structured JSON. Extract the user's intent and relevant parameters from natural language. Return ONLY valid JSON, no explanations.\n\nBe flexible with language - handle typos, slang, and casual phrasing. Consider conversation context when available.\n\nKEY RULES:\n1. 'habit' = 'routine' - treat these as the same thing\n2. Extract medication/routine names from descriptions:\n - 'take a giant dab of THC' → action: 'take', name: 'THC'\n - 'smoke marijuana' as a routine → action: 'create', name: 'smoke marijuana'\n3. If user says 'I want to...' or describes creating something, infer action: 'create'\n4. If user says 'called X' or 'named X', extract X as the name\n5. If medication/routine isn't found and user said 'take'/'start', ask for the name, don't leave it blank\n6. For medications, frequency must be ONE OF: 'daily', 'twice_daily', 'specific_days', 'every_n_days', 'as_needed'\n7. Days of week must be in JSON array format: ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']\n8. Times must be in JSON array format in 24hr format: ['08:00'], ['09:00', '21:00']\n\nAvailable interaction types:\n- 'routine': managing daily routines/habits (create|list|start|complete|skip|cancel|history|pause|resume)\n- 'medication': managing medications (add|list|take|skip|adherence)\n\nFor routines, extract: action, name, description (optional)\nFor medications, extract: action, name, dosage (number), unit, frequency (enum), times (array), days_of_week (array if specific_days)", + "user_template": "Parse this command into structured JSON.\n\nCurrent conversation context:\n{history_context}\n\nUser message: \"{user_input}\"\n\nReturn JSON with:\n{{\n \"interaction_type\": \"routine\" or \"medication\",\n \"action\": \"string\",\n \"name\": \"string\",\n \"description\": \"string\" (optional),\n \"dosage\": number (for meds),\n \"unit\": \"string\" (for meds: mg, mcg, g, ml, etc),\n \"frequency\": \"daily\" | \"twice_daily\" | \"specific_days\" | \"every_n_days\" | \"as_needed\",\n \"times\": [\"HH:MM\"] (for meds),\n \"days_of_week\": [\"mon\", \"tue\", ...] (only if frequency is specific_days),\n \"confidence\": number (0-1),\n \"needs_clarification\": \"string\" (if confidence < 0.8)\n}}\n\nEXAMPLES:\nRoutine examples:\n- 'take a giant dab of THC' → {{\"interaction_type\": \"medication\", \"action\": \"take\", \"name\": \"THC\", \"confidence\": 0.9}}\n- 'I want to create a habit called smoke dope' → {{\"interaction_type\": \"routine\", \"action\": \"create\", \"name\": \"smoke dope\", \"confidence\": 0.95}}\n- 'start my morning routine' → {{\"interaction_type\": \"routine\", \"action\": \"start\", \"name\": \"morning routine\", \"confidence\": 0.9}}\n\nMedication examples:\n- 'add lsd 50 mcg daily at 9am' → {{\"interaction_type\": \"medication\", \"action\": \"add\", \"name\": \"lsd\", \"dosage\": 50, \"unit\": \"mcg\", \"frequency\": \"daily\", \"times\": [\"09:00\"], \"confidence\": 0.95}}\n- 'add wellbutrin 150 mg twice daily' → {{\"interaction_type\": \"medication\", \"action\": \"add\", \"name\": \"wellbutrin\", \"dosage\": 150, \"unit\": \"mg\", \"frequency\": \"twice_daily\", \"times\": [\"08:00\", \"20:00\"], \"confidence\": 0.95}}\n- 'add vitamin d on tuesday and saturday' → {{\"interaction_type\": \"medication\", \"action\": \"add\", \"name\": \"vitamin d\", \"dosage\": 1, \"unit\": \"pill\", \"frequency\": \"specific_days\", \"times\": [\"08:00\"], \"days_of_week\": [\"tue\", \"sat\"], \"confidence\": 0.9}}\n- 'add aspirin every 3 days' → {{\"interaction_type\": \"medication\", \"action\": \"add\", \"name\": \"aspirin\", \"dosage\": 81, \"unit\": \"mg\", \"frequency\": \"every_n_days\", \"interval_days\": 3, \"times\": [\"08:00\"], \"confidence\": 0.9}}\n- 'which meds do I have?' → {{\"interaction_type\": \"medication\", \"action\": \"list\", \"confidence\": 0.95}}\n\nIf unclear, set needs_clarification explaining what's missing." } }, "validation": { diff --git a/bot/commands/medications.py b/bot/commands/medications.py index 0db4002..7df1fab 100644 --- a/bot/commands/medications.py +++ b/bot/commands/medications.py @@ -30,12 +30,27 @@ async def handle_medication(message, session, parsed): unit = parsed.get("unit", "mg") frequency = parsed.get("frequency", "daily") times = parsed.get("times", ["08:00"]) + days_of_week = parsed.get("days_of_week", []) + interval_days = parsed.get("interval_days") if not name or not dosage: await message.channel.send("Please provide medication name and dosage.") return - data = {"name": name, "dosage": dosage, "unit": unit, "frequency": frequency, "times": times} + data = { + "name": name, + "dosage": dosage, + "unit": unit, + "frequency": frequency, + "times": times + } + + # Add optional fields if present + if days_of_week: + data["days_of_week"] = days_of_week + if interval_days: + data["interval_days"] = interval_days + resp, status = api_request("post", "/api/medications", token, data) if status == 201: await message.channel.send(f"Added **{name}** to your medications!")