Tofu/scripts/import-recipes/extraction/EXTRACTION_RULES.js
2026-09-18 01:41:02 +02:00

38 lines
3.5 KiB
JavaScript

// The instructions the model receives, verbatim, for every document.
//
// Rule 3 is the whole point of this file. A model asked to "parse" an
// ingredient line will cheerfully turn « une poignée de pois chiches » into
// 80 g - a number nobody wrote, that would then be added up in a shopping list
// as if it were measured. The rule is spelled out, justified, and shown in
// examples, because that is where the model drifts on its own.
export const EXTRACTION_RULES = `You are reading the raw text of one household recipe, written in French, and turning it into structured data. Answer with the JSON object described by the output schema, and nothing else.
HARD RULES
1. recipeIngredient[i] is the ingredient line EXACTLY as written in the document. Do not reword it, do not correct its spelling, do not convert its units, do not reorder its words, do not add anything, do not drop anything. That line is what gets displayed on screen and printed on paper, so it must keep the household's own wording.
2. parsedIngredients exists ONLY to add up a shopping list and to make search work. It never replaces the raw line. parsedIngredients[i].raw must be character for character identical to recipeIngredient[i]: same lines, same order, same count, one entry per line.
3. When a line is imprecise, the split stays imprecise. Keep the unit as it is written ("poignée", "filet", "pincée", "trait"), or set quantity to null, and set imprecise to true. NEVER convert an imprecise amount into grams, millilitres or centilitres. NEVER invent a number the document does not state. An invented number is worse than no number at all: it would be summed into a shopping list as if someone had measured it.
4. name is the ingredient alone: no quantity, no unit, no preparation ("émincé", "en dés", "coupées en rondelles"). Use the singular for a countable item ("3 oeufs" gives "oeuf"); leave a name that is only ever plural as it is ("pois chiches", "pâtes").
5. Anything the document does not state is null. Do not guess a yield, a temperature, or a missing step.
EXAMPLES - raw line, then the split it must produce
"200 g de tomates" name "tomates", quantity 200, unit "g", imprecise false
"3 oeufs" name "oeuf", quantity 3, unit null, imprecise false
"1/2 citron" name "citron", quantity 0.5, unit null, imprecise false
"2 c. à soupe d'huile d'olive" name "huile d'olive", quantity 2, unit "c. à soupe", imprecise false
"une poignée de pois chiches" name "pois chiches", quantity 1, unit "poignée", imprecise true
"un filet d'huile d'olive" name "huile d'olive", quantity 1, unit "filet", imprecise true
"une pincée de muscade" name "muscade", quantity 1, unit "pincée", imprecise true
"sel au goût" name "sel", quantity null, unit null, imprecise true
"poivre" name "poivre", quantity null, unit null, imprecise true
"quelques feuilles de sauge" name "sauge", quantity null, unit "feuilles", imprecise true
"200 g de tomates (ou 1 boîte)" raw keeps the parenthesis; name "tomates", quantity 200, unit "g", imprecise false
WHAT IS NOT AN INGREDIENT LINE
Section titles ("Ingrédients", "Pour la sauce"), the yield ("Pour 4 personnes"), and the steps are not ingredients - keep them out of recipeIngredient. The yield goes to recipeYield as written ("4 personnes"). The steps go to recipeInstructions, one entry per step, as written. Ingredients listed under a sub-heading such as "Pour la sauce" are still ingredients: keep their lines, in document order.`