fix: enforce English canonical text in AI-generated dish and recipe data

RecognizeDish() and buildRecipePrompt() were generating text in the
user's language and storing it in base tables, violating the project
rule that base tables always hold English canonical text.

- RecognizeDish(): hardcode English for dish_name; enrichDishInBackground()
  now correctly translates FROM English into all other languages
- buildRecipePrompt(): remove langName lookup, hardcode English for all
  text fields; drop unused locale import

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-18 16:57:34 +02:00
parent 39193ec13c
commit 0f533ccaeb
2 changed files with 6 additions and 23 deletions

View File

@@ -7,7 +7,6 @@ import (
"strings"
"github.com/food-ai/backend/internal/adapters/ai"
"github.com/food-ai/backend/internal/infra/locale"
)
// goalNames maps internal goal codes to English descriptions used in the prompt.
@@ -57,18 +56,6 @@ func (c *Client) GenerateRecipes(ctx context.Context, req ai.RecipeRequest) ([]a
}
func buildRecipePrompt(req ai.RecipeRequest) string {
lang := req.Lang
if lang == "" {
lang = "en"
}
langName := "English"
for _, l := range locale.Languages {
if l.Code == lang {
langName = l.EnglishName
break
}
}
goal := goalNames[req.UserGoal]
if goal == "" {
goal = "weight maintenance"
@@ -100,7 +87,7 @@ func buildRecipePrompt(req ai.RecipeRequest) string {
strings.Join(req.AvailableProducts, "\n") + "\n"
}
return fmt.Sprintf(`You are a chef and nutritionist. Generate %d recipes in %s.
return fmt.Sprintf(`You are a chef and nutritionist. Generate %d recipes in English.
User profile:
- Goal: %s
@@ -114,7 +101,7 @@ Requirements for each recipe:
- Include approximate macros per serving
IMPORTANT:
- All text fields (title, description, ingredient names, units, step descriptions, tags) MUST be in %s.
- All text fields (title, description, ingredient names, units, step descriptions, tags) MUST be in English.
- The "image_query" field MUST always be in English (it is used for stock-photo search).
Return ONLY a valid JSON array without markdown or extra text:
@@ -131,7 +118,7 @@ Return ONLY a valid JSON array without markdown or extra text:
"steps": [{"number": 1, "description": "...", "timer_seconds": null}],
"tags": ["..."],
"nutrition_per_serving": {"calories": 420, "protein_g": 48, "fat_g": 12, "carbs_g": 18}
}]`, count, langName, goal, req.DailyCalories, restrictions, cuisines, productsSection, perMealCalories, langName)
}]`, count, goal, req.DailyCalories, restrictions, cuisines, productsSection, perMealCalories)
}
func parseRecipesJSON(text string) ([]ai.Recipe, error) {