From e0ddd65f1d5cb2ad4becc6112b30243785e6275f Mon Sep 17 00:00:00 2001 From: Ionel Andrei Cataon Date: Wed, 18 Feb 2026 17:48:47 +0200 Subject: [PATCH] s --- .../src/main/webapp/index.html | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/proiect-nutritie-java/src/main/webapp/index.html b/proiect-nutritie-java/src/main/webapp/index.html index b1f4c81..b0b4de6 100644 --- a/proiect-nutritie-java/src/main/webapp/index.html +++ b/proiect-nutritie-java/src/main/webapp/index.html @@ -102,7 +102,7 @@
System Online.
- Mathematical verification is now active. All meal plans are audited for calorie accuracy. + Staple-scaling protocol active. All meal plans are calculated for exact mathematical compliance.
@@ -168,31 +168,38 @@ async function talk(custom) { const box = document.getElementById('chat'), input = document.getElementById('uIn'); - const text = custom === 'GENERATE_SHOPPING_LIST' ? "GENERATE_SHOPPING_LIST: Provide a shopping list based on the active meal plan." : (custom || input.value); + const targetKcal = document.getElementById('kcal').innerText; + const text = custom === 'GENERATE_SHOPPING_LIST' ? "GENERATE_SHOPPING_LIST" : (custom || input.value); if(!text) return; if(!custom) { box.innerHTML += `
${text}
`; input.value=""; } - const id = 'ai-'+Date.now(); box.innerHTML += `
Auditing calories...
`; + const id = 'ai-'+Date.now(); box.innerHTML += `
Calculating exact portions...
`; box.scrollTop = box.scrollHeight; - const sysPrompt = {role:"system", content: `Expert Dietitian. TARGET: ${document.getElementById('kcal').innerText} kcal. SYSTEM: ${isMetric ? 'METRIC' : 'IMPERIAL'}. + const sysPrompt = {role:"system", content: `Expert Dietitian. TARGET: ${targetKcal} kcal. - MATH VERIFICATION RULE: - 1. You are forbidden from hallucinating totals. - 2. Before writing the 'Daily Total', you MUST manually sum the calories of every ingredient you listed. - 3. If the sum is less than ${document.getElementById('kcal').innerText}, you MUST increase the Weight (RAW) of starch/protein sources (e.g., 100g -> 250g) until the math is perfect. - 4. Meal Total MUST = Sum of ingredient calories. - 5. Daily Total MUST = Sum of all Meal Totals. + STRICT CALORIE ARCHITECTURE: + 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. + 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. + 3. MATHEMATICAL LOCK: Ingredient calories must sum to 'Meal Total', and all 'Meal Totals' must sum to EXACTLY ${targetKcal}. No exceptions. + 4. No hallucinations. I am checking the math for every row. - OUTPUT FORMAT: - - Table: | Ingredient | Weight (RAW) | Calories | P(g) | C(g) | F(g) | - - After each table: "Meal Total: [Kcal] | [P] | [C] | [F]" - - Final line: **Daily Total: [Sum] kcal**.`}; + FORMAT: + ### [Day] + #### [Meal Name] + | 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}); try { const res = await fetch("https://api.groq.com/openai/v1/chat/completions", { method: "POST", headers: {"Content-Type":"application/json", "Authorization":`Bearer ${API}`}, - body: JSON.stringify({ model:"llama-3.3-70b-versatile", messages:[sysPrompt, ...conversationHistory], temperature: 0.1}) + body: JSON.stringify({ + model:"llama-3.3-70b-versatile", + messages:[sysPrompt, ...conversationHistory], + temperature: 0.0 // Forced precision + }) }); const d = await res.json(); const aiMsg = d.choices[0].message.content;