s
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<title>NutriAI Elite v21.0</title>
|
<title>NutriAI Elite v22.0</title>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
@@ -114,8 +114,8 @@
|
|||||||
|
|
||||||
<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">Unit Sync Active.</h5>
|
<h5 class="fw-bold text-primary">System Refined.</h5>
|
||||||
Raw ingredient weights and shopping list quantities will now match your **Metric/Imperial** selection.
|
Shopping lists will only be generated upon button request. All units are synced.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
<input type="text" id="uIn" class="form-control bg-dark text-white border-primary" placeholder="Type and press ENTER..." onkeydown="if(event.key === 'Enter') talk()">
|
<input type="text" id="uIn" class="form-control bg-dark text-white border-primary" placeholder="Type and press ENTER..." onkeydown="if(event.key === 'Enter') talk()">
|
||||||
<button class="btn btn-primary" onclick="talk()"><i class="fas fa-paper-plane"></i></button>
|
<button class="btn btn-primary" onclick="talk()"><i class="fas fa-paper-plane"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn-shop shadow-sm" onclick="talk('Generate shopping list for current plan')">
|
<button class="btn-shop shadow-sm" onclick="talk('GENERATE_SHOPPING_LIST')">
|
||||||
<i class="fas fa-shopping-basket me-1"></i> SHOPPING LIST
|
<i class="fas fa-shopping-basket me-1"></i> SHOPPING LIST
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -184,21 +184,30 @@
|
|||||||
|
|
||||||
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 || input.value; if(!text) return;
|
const isShopReq = custom === 'GENERATE_SHOPPING_LIST';
|
||||||
|
const text = isShopReq ? "Please generate a shopping list for the current meal plan." : (custom || input.value);
|
||||||
|
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 with ${isMetric?'Metric':'Imperial'} units...</div>`;
|
const id = 'ai-'+Date.now(); box.innerHTML += `<div id="${id}" class="msg ai shadow">Processing...</div>`;
|
||||||
box.scrollTop = box.scrollHeight;
|
box.scrollTop = box.scrollHeight;
|
||||||
|
|
||||||
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:[
|
body: JSON.stringify({ model:"llama-3.3-70b-versatile", messages:[
|
||||||
{role:"system", content: `Expert Nutritionist. Target: ${document.getElementById('kcal').innerText} kcal. SYSTEM: ${isMetric ? 'METRIC (grams, kg, liters)' : 'IMPERIAL (ounces, lbs, cups)'}. MANDATORY: Use raw weights for ALL ingredients. Provide shopping list quantities in ${isMetric ? 'grams/kilograms' : 'ounces/lbs'}. Use Markdown tables.`},
|
{role:"system", content: `Expert Nutritionist. Target: ${document.getElementById('kcal').innerText} kcal. SYSTEM: ${isMetric ? 'METRIC' : 'IMPERIAL'}.
|
||||||
|
MANDATORY RULES:
|
||||||
|
1. ALWAYS use raw weights for ingredients in meal plans.
|
||||||
|
2. DO NOT generate a shopping list unless the user explicitly asks for one.
|
||||||
|
3. If requested, provide shopping list quantities in ${isMetric ? 'grams/kilograms' : 'ounces/lbs'}.
|
||||||
|
4. Use Markdown tables.`},
|
||||||
{role:"user", content:text}
|
{role:"user", content:text}
|
||||||
]})
|
]})
|
||||||
});
|
});
|
||||||
const d = await res.json();
|
const d = await res.json();
|
||||||
document.getElementById(id).innerHTML = marked.parse(d.choices[0].message.content);
|
document.getElementById(id).innerHTML = marked.parse(d.choices[0].message.content);
|
||||||
} catch(e) { document.getElementById(id).innerText = "Error syncing with coach."; }
|
} catch(e) { document.getElementById(id).innerText = "Connection error."; }
|
||||||
box.scrollTop = box.scrollHeight;
|
box.scrollTop = box.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user