s
This commit is contained in:
@@ -102,7 +102,7 @@
|
|||||||
<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">System Online.</h5>
|
||||||
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.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-area">
|
<div class="input-area">
|
||||||
@@ -168,31 +168,38 @@
|
|||||||
|
|
||||||
async function talk(custom) {
|
async function talk(custom) {
|
||||||
const box = document.getElementById('chat'), input = document.getElementById('uIn');
|
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(!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">Auditing calories...</div>`;
|
const id = 'ai-'+Date.now(); box.innerHTML += `<div id="${id}" class="msg ai shadow">Calculating exact portions...</div>`;
|
||||||
box.scrollTop = box.scrollHeight;
|
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:
|
STRICT CALORIE ARCHITECTURE:
|
||||||
1. You are forbidden from hallucinating totals.
|
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. Before writing the 'Daily Total', you MUST manually sum the calories of every ingredient you listed.
|
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. 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.
|
3. MATHEMATICAL LOCK: Ingredient calories must sum to 'Meal Total', and all 'Meal Totals' must sum to EXACTLY ${targetKcal}. No exceptions.
|
||||||
4. Meal Total MUST = Sum of ingredient calories.
|
4. No hallucinations. I am checking the math for every row.
|
||||||
5. Daily Total MUST = Sum of all Meal Totals.
|
|
||||||
|
|
||||||
OUTPUT FORMAT:
|
FORMAT:
|
||||||
- Table: | Ingredient | Weight (RAW) | Calories | P(g) | C(g) | F(g) |
|
### [Day]
|
||||||
- After each table: "Meal Total: [Kcal] | [P] | [C] | [F]"
|
#### [Meal Name]
|
||||||
- Final line: **Daily Total: [Sum] kcal**.`};
|
| 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 {
|
||||||
const res = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
const res = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
||||||
method: "POST", headers: {"Content-Type":"application/json", "Authorization":`Bearer ${API}`},
|
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 d = await res.json();
|
||||||
const aiMsg = d.choices[0].message.content;
|
const aiMsg = d.choices[0].message.content;
|
||||||
|
|||||||
Reference in New Issue
Block a user