`;
conversationHistory = [];
if(mChart) { mChart.data.datasets[0].data = [1,1,1]; mChart.update(); }
}
@@ -186,19 +187,22 @@
async function talk(custom) {
const box = document.getElementById('chat'), input = document.getElementById('uIn');
const isShopReq = custom === 'GENERATE_SHOPPING_LIST';
- const text = isShopReq ? "GENERATE_SHOPPING_LIST: Consolidate all raw ingredients from the previously provided meal plan into a list." : (custom || input.value);
+ const text = isShopReq ? "GENERATE_SHOPPING_LIST: Provide a shopping list based on the active meal plan." : (custom || input.value);
if(!text) return;
if(!custom) { box.innerHTML += `
`;
+ const id = 'ai-'+Date.now(); box.innerHTML += `
Analyzing nutrition data...
`;
box.scrollTop = box.scrollHeight;
const sysPrompt = {role:"system", content: `Expert Dietitian. Target: ${document.getElementById('kcal').innerText} kcal. SYSTEM: ${isMetric ? 'METRIC' : 'IMPERIAL'}.
- CORE RULES:
- 1. Meal Plans MUST include a table with: Ingredient, Weight (DRY/RAW), Calories, P (g), C (g), F (g).
- 2. DRY/RAW weights are mandatory (e.g., 100g raw oats = 380kcal).
- 3. When user sends "GENERATE_SHOPPING_LIST", refer to the ingredients you just generated in the plan. Do NOT say there is no plan.
- 4. Shopping lists must use ${isMetric ? 'grams/kg' : 'oz/lbs'}.`};
+ HIERARCHY RULES:
+ 1. Break down by DAY (e.g., ### Monday).
+ 2. Break down each day by MEAL (e.g., #### Breakfast).
+ 3. Every meal MUST have a table: | Ingredient | Weight (RAW) | Calories | P(g) | C(g) | F(g) |.
+ 4. After each meal table, provide "Meal Total: [Kcal] | [P] | [C] | [F]".
+ 5. At the end of each DAY, provide a bold "Daily Total: [Kcal] | [P] | [C] | [F]".
+ 6. MANDATORY: Use DRY/RAW weights only.
+ 7. Refer to previous messages for "GENERATE_SHOPPING_LIST" requests.`};
conversationHistory.push({role: "user", content: text});
@@ -211,7 +215,7 @@
const aiMsg = d.choices[0].message.content;
conversationHistory.push({role: "assistant", content: aiMsg});
document.getElementById(id).innerHTML = marked.parse(aiMsg);
- } catch(e) { document.getElementById(id).innerText = "Sync error."; }
+ } catch(e) { document.getElementById(id).innerText = "Connection lost."; }
box.scrollTop = box.scrollHeight;
}