This commit is contained in:
Ionel Andrei Cataon
2026-02-18 17:51:35 +02:00
parent e0ddd65f1d
commit c06257bef9

View File

@@ -101,8 +101,8 @@
</div> </div>
<div id="chat" class="chat-container"> <div id="chat" class="chat-container">
<div class="msg ai shadow"> <div class="msg ai shadow">
<h5 class="fw-bold text-primary">System Online.</h5> <h5 class="fw-bold text-primary">Precision Audit Active.</h5>
Staple-scaling protocol active. All meal plans are calculated for exact mathematical compliance. Calorie hallucination protection is engaged. Using strict USDA-aligned reference values.
</div> </div>
</div> </div>
<div class="input-area"> <div class="input-area">
@@ -172,24 +172,20 @@
const text = custom === 'GENERATE_SHOPPING_LIST' ? "GENERATE_SHOPPING_LIST" : (custom || input.value); const text = custom === 'GENERATE_SHOPPING_LIST' ? "GENERATE_SHOPPING_LIST" : (custom || input.value);
if(!text) return; if(!text) return;
if(!custom) { box.innerHTML += `<div class="msg user shadow-sm">${text}</div>`; input.value=""; } if(!custom) { box.innerHTML += `<div class="msg user shadow-sm">${text}</div>`; input.value=""; }
const id = 'ai-'+Date.now(); box.innerHTML += `<div id="${id}" class="msg ai shadow">Calculating exact portions...</div>`; const id = 'ai-'+Date.now(); box.innerHTML += `<div id="${id}" class="msg ai shadow">Auditing ingredient density...</div>`;
box.scrollTop = box.scrollHeight; box.scrollTop = box.scrollHeight;
const sysPrompt = {role:"system", content: `Expert Dietitian. TARGET: ${targetKcal} kcal. const sysPrompt = {role:"system", content: `Expert Dietitian. TARGET: ${targetKcal} kcal.
STRICT CALORIE ARCHITECTURE: CRITICAL MATH RULES:
1. NO RECOMMENDATIONS AT THE END. You must NEVER finish with "to meet your goal, add X." All calories must be ALREADY in the table. 1. NO HALLUCINATION: You are forbidden from claiming (450g Oats = 600kcal).
2. MANDATORY STAPLE SCALING: If the sum is below ${targetKcal}, increase the RAW weight of Rice, Oats, Bread, or Meat (e.g., 100g -> 350g) within the tables until the total is EXACT. 2. USDA LOOKUP: You must use real values (e.g., Raw Oats ~380kcal/100g, Chicken Breast ~165kcal/100g).
3. MATHEMATICAL LOCK: Ingredient calories must sum to 'Meal Total', and all 'Meal Totals' must sum to EXACTLY ${targetKcal}. No exceptions. 3. REAL WEIGHTS: If the user needs ${targetKcal} kcal, adjust the GRAMS to match reality. Do not adjust the CALORIES to match a fake gram weight.
4. No hallucinations. I am checking the math for every row. 4. ABSOLUTE TOTALS: Sum every row. If Daily Total != ${targetKcal}, you must re-calculate portions before answering.
FORMAT: FORMAT:
### [Day] | Ingredient | Weight (RAW) | Calories | P | C | F |
#### [Meal Name] Daily Total: [Exact Sum] kcal (Must equal ${targetKcal})`};
| Ingredient | Weight (RAW) | Calories | P(g) | C(g) | F(g) |
Meal Total: [Kcal] | [P] | [C] | [F]
**Daily Total: [Sum] kcal** (Must be ${targetKcal})`};
conversationHistory.push({role: "user", content: text}); conversationHistory.push({role: "user", content: text});
try { try {
@@ -198,7 +194,7 @@
body: JSON.stringify({ body: JSON.stringify({
model:"llama-3.3-70b-versatile", model:"llama-3.3-70b-versatile",
messages:[sysPrompt, ...conversationHistory], messages:[sysPrompt, ...conversationHistory],
temperature: 0.0 // Forced precision temperature: 0.0
}) })
}); });
const d = await res.json(); const d = await res.json();