Browse Source

TG-43: Implement high-efficiency RAG prompt for comprehensive nutritional analysis

FerRo988 2 weeks ago
parent
commit
88ee01ac29
1 changed files with 10 additions and 8 deletions
  1. 10 8
      main.py

+ 10 - 8
main.py

@@ -102,21 +102,23 @@ def extract_food_context(messages: list) -> str | None:
     
     # Build a structured context block for the system prompt
     lines = [
-        "[LocalFoodAI Database Context]",
-        "The user's question relates to foods found in the local verified nutritional database.",
-        "Use ONLY the following data for specific nutritional values (per 100g serving):",
+        "[SYSTEM: NUTRITIONAL ANALYST MODE]",
+        "You are the LocalFoodAI Analyst. Use ONLY the following verified local data for nutritional values.",
+        "Always prioritize this data over your training memory. If a value is 0.0, it means it was not found or is negligible.",
+        "If a specific nutrient is not listed below, state that it is not available in the local database.",
+        "Format your summary clearly (tables are preferred).",
         ""
     ]
     for name, item in found_items.items():
+        # Compact, token-efficient format for the LLM
         line = (
-            f"- {name}: {item['calories']} kcal | "
-            f"P: {item['protein_g']}g | F: {item['fat_g']}g | "
-            f"C: {item['carbs_g']}g"
+            f"- {name}: {item['calories']}kcal | P:{item['protein_g']}g | F:{item['fat_g']}g | C:{item['carbs_g']}g | "
+            f"Fib:{item['fiber_g']}g | Sug:{item['sugar_g']}g | Chol:{item['cholesterol_mg']}mg | "
+            f"Na:{item['sodium_mg']}mg | Ca:{item['calcium_mg']}mg | Fe:{item['iron_mg']}mg | "
+            f"K:{item['potassium_mg']}mg | VitA:{item['vitamin_a_iu']}IU | VitC:{item['vitamin_c_mg']}mg"
         )
         lines.append(line)
     
-    lines.append("")
-    lines.append("Always prioritize this local database data over your training memory for these specific foods.")
     return "\n".join(lines)
 
 # Mount static files to serve the frontend