feat: remove quant from prompt
This commit is contained in:
@@ -47,19 +47,17 @@ function cacheNutrition(foodName: string, grams: number, info: NutritionInfo): v
|
|||||||
* Get detailed nutritional information for a food item using Claude AI
|
* Get detailed nutritional information for a food item using Claude AI
|
||||||
* Uses in-memory cache to avoid repeated API calls for the same food/amount
|
* Uses in-memory cache to avoid repeated API calls for the same food/amount
|
||||||
* @param foodName - The name of the food item
|
* @param foodName - The name of the food item
|
||||||
* @param grams - Amount in grams
|
|
||||||
* @returns Promise with nutritional information
|
* @returns Promise with nutritional information
|
||||||
*/
|
*/
|
||||||
export async function getNutritionInfo(foodName: string, grams: number): Promise<NutritionInfo> {
|
export async function getNutritionInfo(foodName: string): Promise<NutritionInfo> {
|
||||||
// Check cache first
|
// Check cache first
|
||||||
const cached = getCachedNutrition(foodName, grams);
|
const cached = getCachedNutrition(foodName, 100);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
console.log(`Using cached nutrition info for: ${foodName} (${grams}g)`);
|
console.log(`Using cached nutrition info for: ${foodName} (100g)`);
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Fetching nutrition info from AI for: ${foodName} (${grams}g)`);
|
console.log(`Fetching nutrition info from AI for: ${foodName} (100g)`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const message = await anthropic.messages.create({
|
const message = await anthropic.messages.create({
|
||||||
model: 'claude-haiku-4-5-20251001',
|
model: 'claude-haiku-4-5-20251001',
|
||||||
@@ -67,7 +65,7 @@ export async function getNutritionInfo(foodName: string, grams: number): Promise
|
|||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: `Provide detailed nutritional information for ${grams}g of ${foodName}.
|
content: `Provide detailed nutritional information for 100g of ${foodName}.
|
||||||
|
|
||||||
IMPORTANT: Respond in Brazilian Portuguese (pt-BR).
|
IMPORTANT: Respond in Brazilian Portuguese (pt-BR).
|
||||||
|
|
||||||
@@ -108,7 +106,7 @@ Be concise but informative. Only include significant amounts of vitamins and min
|
|||||||
const nutritionInfo: NutritionInfo = JSON.parse(jsonMatch[0]);
|
const nutritionInfo: NutritionInfo = JSON.parse(jsonMatch[0]);
|
||||||
|
|
||||||
// Cache the result for future use
|
// Cache the result for future use
|
||||||
cacheNutrition(foodName, grams, nutritionInfo);
|
cacheNutrition(foodName, 100, nutritionInfo);
|
||||||
|
|
||||||
return nutritionInfo;
|
return nutritionInfo;
|
||||||
|
|
||||||
|
|||||||
+3
-13
@@ -367,15 +367,6 @@ const setupEventListeners = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getInputById('gramAmount').addEventListener('change', () => {
|
|
||||||
previewCalories();
|
|
||||||
// Reload AI nutrition info with new amount if food is selected
|
|
||||||
if (selectedFood) {
|
|
||||||
const grams = parseFloat(getInputById('gramAmount').value) || 100;
|
|
||||||
loadAINutritionInfo(selectedFood.name, grams);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
getButtonById('add-food-btn').addEventListener('click', () => {
|
getButtonById('add-food-btn').addEventListener('click', () => {
|
||||||
if (getButtonById('add-food-btn').innerHTML === 'Add Food') {
|
if (getButtonById('add-food-btn').innerHTML === 'Add Food') {
|
||||||
addFood();
|
addFood();
|
||||||
@@ -623,12 +614,12 @@ function showAIContent(nutritionInfo: NutritionInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadAINutritionInfo(foodName: string, grams: number) {
|
async function loadAINutritionInfo(foodName: string) {
|
||||||
showAINutritionCard();
|
showAINutritionCard();
|
||||||
showAILoading();
|
showAILoading();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const nutritionInfo = await getNutritionInfo(foodName, grams);
|
const nutritionInfo = await getNutritionInfo(foodName);
|
||||||
showAIContent(nutritionInfo);
|
showAIContent(nutritionInfo);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading AI nutrition info:', error);
|
console.error('Error loading AI nutrition info:', error);
|
||||||
@@ -648,8 +639,7 @@ function selectFood(food: FoodItem) {
|
|||||||
getButtonById('cancel-food-btn').style.display = 'inline-block';
|
getButtonById('cancel-food-btn').style.display = 'inline-block';
|
||||||
|
|
||||||
// Load AI nutrition info for the selected food
|
// Load AI nutrition info for the selected food
|
||||||
const grams = parseFloat(getInputById('gramAmount').value) || 100;
|
loadAINutritionInfo(food.name);
|
||||||
loadAINutritionInfo(food.name, grams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setFoodToEdit(foodId: string) {
|
async function setFoodToEdit(foodId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user