diff --git a/src/claudeService.ts b/src/claudeService.ts index d995cdc..7cb0592 100644 --- a/src/claudeService.ts +++ b/src/claudeService.ts @@ -47,19 +47,17 @@ function cacheNutrition(foodName: string, grams: number, info: NutritionInfo): v * 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 * @param foodName - The name of the food item - * @param grams - Amount in grams * @returns Promise with nutritional information */ -export async function getNutritionInfo(foodName: string, grams: number): Promise { +export async function getNutritionInfo(foodName: string): Promise { // Check cache first - const cached = getCachedNutrition(foodName, grams); + const cached = getCachedNutrition(foodName, 100); if (cached) { - console.log(`Using cached nutrition info for: ${foodName} (${grams}g)`); + console.log(`Using cached nutrition info for: ${foodName} (100g)`); return cached; } - console.log(`Fetching nutrition info from AI for: ${foodName} (${grams}g)`); - + console.log(`Fetching nutrition info from AI for: ${foodName} (100g)`); try { const message = await anthropic.messages.create({ model: 'claude-haiku-4-5-20251001', @@ -67,7 +65,7 @@ export async function getNutritionInfo(foodName: string, grams: number): Promise messages: [ { 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). @@ -108,7 +106,7 @@ Be concise but informative. Only include significant amounts of vitamins and min const nutritionInfo: NutritionInfo = JSON.parse(jsonMatch[0]); // Cache the result for future use - cacheNutrition(foodName, grams, nutritionInfo); + cacheNutrition(foodName, 100, nutritionInfo); return nutritionInfo; diff --git a/src/index.ts b/src/index.ts index 422f637..9d5e8de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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', () => { if (getButtonById('add-food-btn').innerHTML === 'Add Food') { addFood(); @@ -623,12 +614,12 @@ function showAIContent(nutritionInfo: NutritionInfo) { } } -async function loadAINutritionInfo(foodName: string, grams: number) { +async function loadAINutritionInfo(foodName: string) { showAINutritionCard(); showAILoading(); try { - const nutritionInfo = await getNutritionInfo(foodName, grams); + const nutritionInfo = await getNutritionInfo(foodName); showAIContent(nutritionInfo); } catch (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'; // Load AI nutrition info for the selected food - const grams = parseFloat(getInputById('gramAmount').value) || 100; - loadAINutritionInfo(food.name, grams); + loadAINutritionInfo(food.name); } async function setFoodToEdit(foodId: string) {