Add ideas_from_ingredients skill and job
CI / ci (push) Successful in 5m51s
CI / ci (pull_request) Successful in 5m45s

Implement the ideas_from_ingredients v1 skill on the AI harness: it asks
for 8 ideas {name, uses[], missing[], est_minutes, method, difficulty,
search_query}, keeps only "uses" entries whose harness.Normalize form is
one of the household's listed ingredients (written as the household wrote
them, in its order), drops ideas using none or repeating another, and
computes the summary line from the corrected lists.

Add internal/ideas: an ideas_from_ingredients job that grounds the ideas
with Grounder.GroundMany in the model's order until 5 are kept, drops the
ungroundable ones and, for quick_only, those whose grounded recipe is not
a Quick dinner (crockpot or minutes_total <= 30), publishing the result
as each idea is kept. POST /api/v1/ideas/from-ingredients answers 202
{jobId}.

Maestro task c3c5f98e-7f7d-4c6b-a1ab-d45bb8e497f9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 19:01:03 -04:00
co-authored by Claude Opus 5.5
parent cb451baed4
commit b566be7ddc
24 changed files with 1817 additions and 25 deletions
@@ -0,0 +1,356 @@
package skills
import (
"context"
"encoding/json"
"errors"
"fmt"
"slices"
"strconv"
"strings"
"time"
"unicode/utf8"
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/ai/harness"
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/ai/llm"
)
const (
// IdeasRequested is how many ideas ideas_from_ingredients asks the
// model for; validation and grounding drop some.
IdeasRequested = 8
// IdeasKept is the most ideas the household is shown.
IdeasKept = 5
// MaxIngredients is the most ingredients the household may list.
MaxIngredients = 20
// IngredientLimit is the most characters one listed ingredient may
// have.
IngredientLimit = 80
)
// IdeasRequest is what ideas_from_ingredients reads.
type IdeasRequest struct {
// Ingredients are the ingredients the household has on hand, in its
// order, as CleanIngredients returns them.
Ingredients []string
// QuickOnly asks the model for Quick dinners only. It is a hint: the
// caller enforces it after grounding, from the grounded recipe.
QuickOnly bool
}
// Idea is one dinner idea. Method, EstMinutes and Difficulty are the
// model's estimates until the idea is grounded in a recipe.
type Idea struct {
Name string `json:"name"`
// Uses are the household's ingredients the idea uses, as the household
// wrote them and in its order. PostProcess drops every entry that is
// not one of them.
Uses []string `json:"uses"`
// Missing are the ingredients the idea needs that the household does
// not have, in the model's order.
Missing []string `json:"missing"`
EstMinutes int `json:"est_minutes"`
// Method is one of stovetop, oven, crockpot, grill and other.
Method string `json:"method"`
// Difficulty is easy, medium or hard.
Difficulty string `json:"difficulty"`
// SearchQuery is a web search query that finds a recipe for the dinner.
SearchQuery string `json:"search_query"`
// Summary is the line the household reads under the idea, computed
// by IdeaSummary from Uses and Missing. It is never part of the
// model's reply.
Summary string `json:"-"`
}
// Ideas is ideas_from_ingredients' output.
type Ideas struct {
// Ideas are the ideas that passed every rule, in the model's order.
Ideas []Idea `json:"ideas"`
// Dropped are the ideas the model gave that broke a rule, in the
// model's order. It is never part of the model's reply.
Dropped []DroppedIdea `json:"-"`
}
// DroppedIdea is an idea dropped by PostProcess.
type DroppedIdea struct {
Name string
// Why says which rule it broke.
Why string
}
// IdeasFromIngredients runs ideas_from_ingredients v1 on in and returns
// ideas whose uses hold only the household's own ingredients: an entry
// naming anything else is removed, and an idea left using none of them is
// dropped, as is one repeating an earlier idea. Each kept idea carries its
// summary line, computed from the corrected uses and missing lists. scope
// names the request (see harness.Run; IdeasScope). An ingredient list
// CleanIngredients refuses fails before any LLM call.
func IdeasFromIngredients(ctx context.Context, cfg harness.Config, scope string, in IdeasRequest) (Ideas, error) {
ings, err := CleanIngredients(in.Ingredients)
if err != nil {
return Ideas{}, fmt.Errorf("skills: ideas_from_ingredients: %w", err)
}
in.Ingredients = ings
return harness.Run(ctx, cfg, ideasFromIngredients{in: in}, scope, in)
}
// IdeasScope is the harness scope of a request: its normalized
// ingredients, in order, and whether it is for Quick dinners only, so two
// requests share a run only when the model would be asked the same.
func IdeasScope(in IdeasRequest) string {
parts := make([]string, len(in.Ingredients))
for i, ing := range in.Ingredients {
parts[i] = harness.Normalize(ing)
}
return "quick_only=" + strconv.FormatBool(in.QuickOnly) + ";" + strings.Join(parts, "|")
}
// CleanIngredients returns the household's ingredient list with each entry
// on one line, or why it cannot be used: it is empty or longer than
// MaxIngredients, or an entry is blank, longer than IngredientLimit
// characters, has nothing left once normalized (harness.Normalize), or
// normalizes the same as an earlier one.
func CleanIngredients(list []string) ([]string, error) {
if len(list) == 0 {
return nil, errors.New("list at least one ingredient")
}
if len(list) > MaxIngredients {
return nil, fmt.Errorf("%d ingredients listed; list at most %d", len(list), MaxIngredients)
}
out := make([]string, len(list))
seen := map[string]string{}
for i, ing := range list {
ing = oneLine(ing)
switch {
case ing == "":
return nil, fmt.Errorf("ingredient %d is blank", i+1)
case utf8.RuneCountInString(ing) > IngredientLimit:
return nil, fmt.Errorf("ingredient %d is over %d characters", i+1, IngredientLimit)
}
n := harness.Normalize(ing)
if n == "" {
return nil, fmt.Errorf("ingredient %d, %q, names no ingredient", i+1, ing)
}
if first, ok := seen[n]; ok {
return nil, fmt.Errorf("ingredient %d, %q, repeats %q", i+1, ing, first)
}
seen[n] = ing
out[i] = ing
}
return out, nil
}
// IdeaSummary is the line shown under an idea: how many of the household's
// total ingredients it uses, then what is missing, in the order given.
// "Uses all 5 · missing: 1 lime" when every ingredient is used, "Uses 3 of
// 5 · missing: 1 lime, cumin" when some are. With nothing missing the
// second part is "nothing missing", so an idea using all 5 and needing
// nothing else prints "Uses all 5 · nothing missing".
func IdeaSummary(uses, missing []string, total int) string {
used := fmt.Sprintf("Uses %d of %d", len(uses), total)
if len(uses) == total {
used = fmt.Sprintf("Uses all %d", total)
}
if len(missing) == 0 {
return used + " · nothing missing"
}
return used + " · missing: " + strings.Join(missing, ", ")
}
// ideasFromIngredients is the skill. It holds its input because
// post-processing compares the output with it.
type ideasFromIngredients struct {
in IdeasRequest
}
var _ harness.Skill[IdeasRequest, Ideas] = ideasFromIngredients{}
func (ideasFromIngredients) Name() string { return "ideas_from_ingredients" }
func (ideasFromIngredients) Version() int { return 1 }
func (ideasFromIngredients) Timeout() time.Duration { return harness.DefaultTimeout }
// ideasPrompt is the template data of ideas_from_ingredients.v1.tmpl.
type ideasPrompt struct {
// Count is how many ideas to ask for.
Count int
QuickOnly bool
}
// PromptInput puts the ingredients, already cleaned by
// IdeasFromIngredients, in the household context block.
func (ideasFromIngredients) PromptInput(in IdeasRequest) (harness.PromptInput, error) {
return harness.PromptInput{
Data: ideasPrompt{Count: IdeasRequested, QuickOnly: in.QuickOnly},
Context: []harness.ContextSection{{Title: "Ingredients on hand", Lines: in.Ingredients}},
}, nil
}
func (ideasFromIngredients) Schema() llm.JSONSchema {
return llm.JSONSchema{Name: "ideas_from_ingredients", Schema: json.RawMessage(`{
"type": "object",
"properties": {
"ideas": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"uses": {"type": "array", "items": {"type": "string"}},
"missing": {"type": "array", "items": {"type": "string"}},
"est_minutes": {"type": "integer"},
"method": {"type": "string", "enum": ["stovetop", "oven", "crockpot", "grill", "other"]},
"difficulty": {"type": "string", "enum": ["easy", "medium", "hard"]},
"search_query": {"type": "string"}
},
"required": ["name", "uses", "missing", "est_minutes", "method", "difficulty", "search_query"],
"additionalProperties": false
}
}
},
"required": ["ideas"],
"additionalProperties": false
}`)}
}
// UnmarshalJSON decodes an idea, requiring each of its fields as the
// schema does: encoding/json would otherwise read a missing or null one as
// empty.
func (i *Idea) UnmarshalJSON(data []byte) error {
if err := requireFields(data, nil, "name", "uses", "missing", "est_minutes", "method", "difficulty", "search_query"); err != nil {
return fmt.Errorf("idea %s", err)
}
type plain Idea
return json.Unmarshal(data, (*plain)(i))
}
// UnmarshalJSON decodes the output, requiring its one field as the schema
// does.
func (out *Ideas) UnmarshalJSON(data []byte) error {
if err := requireFields(data, nil, "ideas"); err != nil {
return fmt.Errorf("output %s", err)
}
type plain Ideas
return json.Unmarshal(data, (*plain)(out))
}
// Validate finds what makes the reply unusable as a whole: no ideas, too
// many, or one that is malformed. A well-formed idea that breaks a rule is
// dropped by PostProcess instead.
func (ideasFromIngredients) Validate(out Ideas) []string {
var problems []string
switch n := len(out.Ideas); {
case n == 0 && len(out.Dropped) == 0:
problems = append(problems, fmt.Sprintf("ideas is empty; give %d ideas", IdeasRequested))
case n > IdeasRequested:
problems = append(problems, fmt.Sprintf("ideas has %d entries; give at most %d ideas", n, IdeasRequested))
}
for i, idea := range out.Ideas {
for _, f := range []struct{ field, value string }{{"name", idea.Name}, {"search_query", idea.SearchQuery}} {
if strings.TrimSpace(f.value) == "" {
problems = append(problems, fmt.Sprintf("idea %d has an empty %s; give one", i+1, f.field))
}
}
if strings.TrimSpace(idea.Name) != "" && harness.Normalize(idea.Name) == "" {
problems = append(problems, fmt.Sprintf("idea %d name %q has only filler words; name the dish", i+1, idea.Name))
}
if !slices.Contains(methods, idea.Method) {
problems = append(problems, fmt.Sprintf("idea %d method %q is not one of %s", i+1, idea.Method, strings.Join(methods, ", ")))
}
if idea.EstMinutes <= 0 {
problems = append(problems, fmt.Sprintf("idea %d est_minutes %d is not positive; give the minutes from prep to table", i+1, idea.EstMinutes))
}
if !slices.Contains(difficulties, idea.Difficulty) {
problems = append(problems, fmt.Sprintf("idea %d difficulty %q is not one of %s", i+1, idea.Difficulty, strings.Join(difficulties, ", ")))
}
}
return problems
}
// PostProcess corrects every idea against the household's ingredients and
// moves each that breaks a rule to Dropped. Uses keeps only entries whose
// normalized form (harness.Normalize) is that of a listed ingredient,
// written as the household wrote it, once each and in the household's
// order; anything else the model claimed is removed, never trusted.
// Missing loses blank entries, repeats and anything the household listed.
// An idea is dropped when it repeats an earlier idea or uses none of the
// household's ingredients. The summary line is computed from the
// corrected lists.
func (s ideasFromIngredients) PostProcess(out Ideas) (Ideas, error) {
listed := map[string]int{}
for i, ing := range s.in.Ingredients {
listed[harness.Normalize(ing)] = i
}
result := Ideas{Ideas: []Idea{}}
for _, idea := range out.Ideas {
idea = Idea{
Name: oneLine(idea.Name),
Uses: s.uses(idea.Uses, listed),
Missing: missing(idea.Missing, listed),
EstMinutes: idea.EstMinutes,
Method: idea.Method,
Difficulty: idea.Difficulty,
SearchQuery: oneLine(idea.SearchQuery),
}
if why := dropIdea(idea, result.Ideas); why != "" {
result.Dropped = append(result.Dropped, DroppedIdea{Name: idea.Name, Why: why})
continue
}
idea.Summary = IdeaSummary(idea.Uses, idea.Missing, len(s.in.Ingredients))
result.Ideas = append(result.Ideas, idea)
}
return result, nil
}
// uses returns the household's ingredients that claimed names, as the
// household wrote them and in its order. A claimed entry that names none
// of them is left out.
func (s ideasFromIngredients) uses(claimed []string, listed map[string]int) []string {
used := make([]bool, len(s.in.Ingredients))
for _, c := range claimed {
if i, ok := listed[harness.Normalize(c)]; ok {
used[i] = true
}
}
out := []string{}
for i, ing := range s.in.Ingredients {
if used[i] {
out = append(out, ing)
}
}
return out
}
// missing returns claimed on one line each, in order, without blank
// entries, repeats or any the household listed.
func missing(claimed []string, listed map[string]int) []string {
out := []string{}
seen := map[string]bool{}
for _, c := range claimed {
c = oneLine(c)
n := harness.Normalize(c)
if n == "" || seen[n] {
continue
}
if _, ok := listed[n]; ok {
continue
}
seen[n] = true
out = append(out, c)
}
return out
}
// dropIdea returns why idea must be dropped, or "" when it may be kept.
func dropIdea(idea Idea, kept []Idea) string {
for _, k := range kept {
if harness.Similar(idea.Name, k.Name) {
return fmt.Sprintf("repeats the idea %q", k.Name)
}
}
if len(idea.Uses) == 0 {
return "uses none of the household's ingredients"
}
return ""
}
@@ -0,0 +1,269 @@
package skills
import (
"context"
"encoding/json"
"fmt"
"reflect"
"strings"
"testing"
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/ai/llm"
)
// pantry is the household's ingredient list in its order.
var pantry = IdeasRequest{Ingredients: []string{"Chicken thighs", "rice", "cilantro", "black beans", "red onion"}}
// idea renders one idea of an ideas_from_ingredients reply.
func idea(name, method string, minutes int, uses, missing []string) string {
u, _ := json.Marshal(append([]string{}, uses...))
m, _ := json.Marshal(append([]string{}, missing...))
return fmt.Sprintf(`{"name":%q,"uses":%s,"missing":%s,"est_minutes":%d,"method":%q,"difficulty":"easy","search_query":%q}`,
name, u, m, minutes, method, strings.ToLower(name)+" recipe")
}
// ideasReply renders a reply holding the ideas given.
func ideasReply(ideas ...string) string {
return `{"ideas":[` + strings.Join(ideas, ",") + `]}`
}
// ideas runs IdeasFromIngredients on in with f and checks f was called
// exactly calls times, each at the household temperature.
func ideas(t *testing.T, f *llm.Fake, in IdeasRequest, calls int) (Ideas, []llm.Request, error) {
t.Helper()
out, err := IdeasFromIngredients(context.Background(), testConfig(t, f), IdeasScope(in), in)
reqs := f.Requests()
if len(reqs) != calls {
t.Fatalf("Generate called %d times, want %d", len(reqs), calls)
}
if g, _, _ := f.Remaining(); g != 0 {
t.Fatalf("%d scripted Generate results unused", g)
}
for i, req := range reqs {
if req.Temperature == nil || *req.Temperature != 0.7 {
t.Fatalf("request %d temperature = %v, want 0.7", i+1, req.Temperature)
}
if req.Schema == nil || req.Schema.Name != "ideas_from_ingredients" {
t.Fatalf("request %d schema = %v, want ideas_from_ingredients", i+1, req.Schema)
}
}
return out, reqs, err
}
func TestIdeasFromIngredientsPrompt(t *testing.T) {
var f llm.Fake
f.QueueGenerate(reply(ideasReply(idea("Chicken Burrito Bowls", "stovetop", 35, []string{"Chicken thighs", "rice"}, nil))))
_, reqs, err := ideas(t, &f, pantry, 1)
if err != nil {
t.Fatal(err)
}
system, user := reqs[0].System, reqs[0].Messages[0].Content
golden(t, "ideas_from_ingredients_any.system.golden", system)
golden(t, "ideas_from_ingredients_any.user.golden", user)
for _, part := range []string{
"## Household context",
"### Ingredients on hand\n- Chicken thighs\n- rice\n- cilantro\n- black beans\n- red onion",
"## Output contract",
`"uses"`,
`"missing"`,
} {
if !strings.Contains(system, part) {
t.Errorf("system prompt lacks %q", part)
}
}
if strings.Contains(system, "Quick dinners only") {
t.Error("an Any time request asks for Quick dinners only")
}
if user != "Suggest 8 dinner ideas from the ingredients on hand." {
t.Errorf("user message = %q", user)
}
}
func TestIdeasFromIngredientsQuickOnlyPrompt(t *testing.T) {
var f llm.Fake
f.QueueGenerate(reply(ideasReply(idea("Chicken Fried Rice", "stovetop", 25, []string{"Chicken thighs", "rice"}, nil))))
in := pantry
in.QuickOnly = true
_, reqs, err := ideas(t, &f, in, 1)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(reqs[0].System, "The household wants Quick dinners only: each idea must be cooked in a crock pot, or take 30 minutes or less from prep to table.") {
t.Errorf("Quick only request does not ask for Quick dinners:\n%s", reqs[0].System)
}
}
func TestIdeasFromIngredientsSummaryLine(t *testing.T) {
var f llm.Fake
f.QueueGenerate(reply(ideasReply(
// Every ingredient, named in another order and spelling: uses is
// in the household's order, as the household wrote it.
idea("Chicken Burrito Bowls", "stovetop", 35, []string{"red onion", "Black Beans", "chicken thighs", "Rice", "cilantro!"}, []string{"1 lime"}),
// Some of them.
idea("Cilantro Chicken Rice", "stovetop", 30, []string{"rice", "cilantro", "Chicken thighs"}, []string{"1 lime", "cumin"}),
// Every ingredient, nothing missing.
idea("Black Bean Chicken Skillet", "stovetop", 30, []string{"Chicken thighs", "rice", "cilantro", "black beans", "red onion"}, nil),
// Some, nothing missing.
idea("Rice and Beans", "stovetop", 25, []string{"rice", "black beans"}, []string{}),
)))
out, _, err := ideas(t, &f, pantry, 1)
if err != nil {
t.Fatal(err)
}
if len(out.Dropped) != 0 {
t.Fatalf("dropped %+v", out.Dropped)
}
got := map[string][2]any{}
for _, i := range out.Ideas {
got[i.Name] = [2]any{i.Uses, i.Summary}
}
want := map[string][2]any{
"Chicken Burrito Bowls": {[]string{"Chicken thighs", "rice", "cilantro", "black beans", "red onion"}, "Uses all 5 · missing: 1 lime"},
"Cilantro Chicken Rice": {[]string{"Chicken thighs", "rice", "cilantro"}, "Uses 3 of 5 · missing: 1 lime, cumin"},
"Black Bean Chicken Skillet": {[]string{"Chicken thighs", "rice", "cilantro", "black beans", "red onion"}, "Uses all 5 · nothing missing"},
"Rice and Beans": {[]string{"rice", "black beans"}, "Uses 2 of 5 · nothing missing"},
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("uses and summaries = %v\nwant %v", got, want)
}
}
func TestIdeasFromIngredientsDropsHallucinatedUses(t *testing.T) {
var f llm.Fake
f.QueueGenerate(reply(ideasReply(
// The model claims parmesan and lime, which the household never
// listed, and repeats rice.
idea("Cheesy Chicken Rice", "oven", 40, []string{"Chicken thighs", "parmesan", "rice", "lime", "rice"}, []string{"1 cup broth"}),
// Uses only ingredients the household never listed.
idea("Lemon Pasta", "stovetop", 20, []string{"pasta", "lemon"}, []string{"garlic"}),
// Lists an ingredient on hand as missing.
idea("Chicken Tacos", "stovetop", 25, []string{"Chicken thighs"}, []string{"tortillas", "Cilantro", "tortillas"}),
)))
out, _, err := ideas(t, &f, pantry, 1)
if err != nil {
t.Fatal(err)
}
want := Ideas{
Ideas: []Idea{
{
Name: "Cheesy Chicken Rice", Uses: []string{"Chicken thighs", "rice"}, Missing: []string{"1 cup broth"},
EstMinutes: 40, Method: "oven", Difficulty: "easy", SearchQuery: "cheesy chicken rice recipe",
Summary: "Uses 2 of 5 · missing: 1 cup broth",
},
{
Name: "Chicken Tacos", Uses: []string{"Chicken thighs"}, Missing: []string{"tortillas"},
EstMinutes: 25, Method: "stovetop", Difficulty: "easy", SearchQuery: "chicken tacos recipe",
Summary: "Uses 1 of 5 · missing: tortillas",
},
},
Dropped: []DroppedIdea{{Name: "Lemon Pasta", Why: "uses none of the household's ingredients"}},
}
if !reflect.DeepEqual(out, want) {
t.Fatalf("output = %+v\nwant %+v", out, want)
}
}
func TestIdeasFromIngredientsDropsRepeatedIdea(t *testing.T) {
var f llm.Fake
f.QueueGenerate(reply(ideasReply(
idea("Chicken Burrito Bowls", "stovetop", 35, []string{"rice"}, nil),
idea("Easy Chicken Burrito Bowls", "stovetop", 30, []string{"rice"}, nil),
)))
out, _, err := ideas(t, &f, pantry, 1)
if err != nil {
t.Fatal(err)
}
if len(out.Ideas) != 1 || out.Ideas[0].Name != "Chicken Burrito Bowls" {
t.Fatalf("ideas = %+v", out.Ideas)
}
if want := []DroppedIdea{{Name: "Easy Chicken Burrito Bowls", Why: `repeats the idea "Chicken Burrito Bowls"`}}; !reflect.DeepEqual(out.Dropped, want) {
t.Fatalf("dropped = %+v, want %+v", out.Dropped, want)
}
}
func TestIdeasFromIngredientsRepairsMalformedReply(t *testing.T) {
var f llm.Fake
f.QueueGenerate(reply(ideasReply(idea("Chicken Burrito Bowls", "microwave", 0, []string{"rice"}, nil))))
f.QueueGenerate(reply(ideasReply(idea("Chicken Burrito Bowls", "stovetop", 35, []string{"rice"}, nil))))
out, reqs, err := ideas(t, &f, pantry, 2)
if err != nil {
t.Fatal(err)
}
if len(out.Ideas) != 1 {
t.Fatalf("ideas = %+v", out.Ideas)
}
repair := reqs[1].Messages[len(reqs[1].Messages)-1].Content
for _, part := range []string{`idea 1 method "microwave" is not one of`, "idea 1 est_minutes 0 is not positive"} {
if !strings.Contains(repair, part) {
t.Errorf("repair turn lacks %q:\n%s", part, repair)
}
}
}
func TestIdeasFromIngredientsRefusesTooManyIdeas(t *testing.T) {
var f llm.Fake
var nine []string
for i := range 9 {
nine = append(nine, idea(fmt.Sprintf("Dish %d", i+1), "stovetop", 30, []string{"rice"}, nil))
}
f.QueueGenerate(reply(ideasReply(nine...)))
f.QueueGenerate(reply(ideasReply(nine...)))
if _, _, err := ideas(t, &f, pantry, 2); err == nil || !strings.Contains(err.Error(), "give at most 8 ideas") {
t.Fatalf("err = %v, want a bad output naming the limit", err)
}
}
func TestCleanIngredients(t *testing.T) {
got, err := CleanIngredients([]string{" 1 lime ", "Chicken\tthighs"})
if err != nil {
t.Fatal(err)
}
if want := []string{"1 lime", "Chicken thighs"}; !reflect.DeepEqual(got, want) {
t.Fatalf("CleanIngredients = %q, want %q", got, want)
}
tooMany := make([]string, MaxIngredients+1)
for i := range tooMany {
tooMany[i] = fmt.Sprintf("thing %d", i)
}
for _, tc := range []struct {
name string
in []string
want string
}{
{"empty", nil, "list at least one ingredient"},
{"too many", tooMany, "list at most 20"},
{"blank", []string{"rice", " "}, "ingredient 2 is blank"},
{"too long", []string{strings.Repeat("a", IngredientLimit+1)}, "over 80 characters"},
{"filler only", []string{"the"}, "names no ingredient"},
{"repeat", []string{"Red onion", "red-onion"}, `repeats "Red onion"`},
} {
t.Run(tc.name, func(t *testing.T) {
if _, err := CleanIngredients(tc.in); err == nil || !strings.Contains(err.Error(), tc.want) {
t.Fatalf("err = %v, want %q", err, tc.want)
}
})
}
}
func TestIdeasFromIngredientsRefusesBadListBeforeCalling(t *testing.T) {
var f llm.Fake
if _, _, err := ideas(t, &f, IdeasRequest{Ingredients: []string{"rice", "Rice"}}, 0); err == nil {
t.Fatal("a repeated ingredient was accepted")
}
}
func TestIdeasScopeIdentifiesTheRequest(t *testing.T) {
a := IdeasScope(IdeasRequest{Ingredients: []string{"Rice", "black beans"}})
if b := IdeasScope(IdeasRequest{Ingredients: []string{"rice", "Black Beans"}}); a != b {
t.Errorf("scopes of the same list differ: %q, %q", a, b)
}
for _, other := range []IdeasRequest{
{Ingredients: []string{"Rice", "black beans"}, QuickOnly: true},
{Ingredients: []string{"black beans", "Rice"}},
{Ingredients: []string{"Rice"}},
} {
if IdeasScope(other) == a {
t.Errorf("%+v shares the scope %q", other, a)
}
}
}
+1
View File
@@ -6,3 +6,4 @@ normalize_recipe v1 7174e5479fc020f3b2b39953d85411381aea26defb9943145e7864c5b752
suggest_side_quests v1 bd54d7bf9aea0980059a346e5f40ff4c866b80ef9bb9f74e7cbd413be0911c8a
draft_week v1 e637419690d9532bab53cb8ca01b73a079ecfe8e3022522c05188d18e9740f32
archive_title v1 b4f30562a8614dac09a69d512dc361883b917ee4228a0ce3b4583c7fd3f6101a
ideas_from_ingredients v1 49df3e134f07fe2c0dbbda7bd3d7d1364731e5851bf6f6a526ec04b703480924
@@ -0,0 +1,25 @@
{{/* ideas_from_ingredients drafts dinner ideas the household can cook from the ingredients it has on hand. */}}
{{define "instructions" -}}
You suggest dinner ideas the household can cook from the ingredients it has on hand, listed under "Ingredients on hand" in the household context.
Prefer ideas that use as many of those ingredients as possible and need as few others as possible. Pantry staples such as salt, pepper, oil and water need not be listed as missing. Vary the ideas: no two may be the same dish.
Give for each idea:
- name: the dinner's usual name, as a recipe site would title it.
- uses: the ingredients on hand the idea uses, each written exactly as it appears in the "Ingredients on hand" list. List only ingredients from that list, never one it does not hold.
- missing: the ingredients the idea needs that are not on hand, each with a quantity where it helps, e.g. "1 lime". Leave it empty when nothing is missing.
- est_minutes: your estimate of the whole minutes from starting prep to the table.
- method: how it is mainly cooked: "stovetop", "oven", "crockpot" (slow cooker or crock pot), "grill" or "other".
- difficulty: "easy", "medium" or "hard" for a home cook.
- search_query: a web search query that finds a recipe for this dinner.
{{- if .QuickOnly}}
The household wants Quick dinners only: each idea must be cooked in a crock pot, or take 30 minutes or less from prep to table.
{{- end}}
One valid idea, for a household with "chicken thighs", "rice" and "cilantro" on hand (an example only, not about this household):
{"name": "Cilantro Lime Chicken and Rice", "uses": ["chicken thighs", "rice", "cilantro"], "missing": ["1 lime"], "est_minutes": 35, "method": "stovetop", "difficulty": "easy", "search_query": "cilantro lime chicken and rice recipe"}
{{- end}}
{{define "user" -}}
Suggest {{.Count}} dinner ideas from the ingredients on hand.
{{- end}}
@@ -0,0 +1,94 @@
## Instructions
You suggest dinner ideas the household can cook from the ingredients it has on hand, listed under "Ingredients on hand" in the household context.
Prefer ideas that use as many of those ingredients as possible and need as few others as possible. Pantry staples such as salt, pepper, oil and water need not be listed as missing. Vary the ideas: no two may be the same dish.
Give for each idea:
- name: the dinner's usual name, as a recipe site would title it.
- uses: the ingredients on hand the idea uses, each written exactly as it appears in the "Ingredients on hand" list. List only ingredients from that list, never one it does not hold.
- missing: the ingredients the idea needs that are not on hand, each with a quantity where it helps, e.g. "1 lime". Leave it empty when nothing is missing.
- est_minutes: your estimate of the whole minutes from starting prep to the table.
- method: how it is mainly cooked: "stovetop", "oven", "crockpot" (slow cooker or crock pot), "grill" or "other".
- difficulty: "easy", "medium" or "hard" for a home cook.
- search_query: a web search query that finds a recipe for this dinner.
One valid idea, for a household with "chicken thighs", "rice" and "cilantro" on hand (an example only, not about this household):
{"name": "Cilantro Lime Chicken and Rice", "uses": ["chicken thighs", "rice", "cilantro"], "missing": ["1 lime"], "est_minutes": 35, "method": "stovetop", "difficulty": "easy", "search_query": "cilantro lime chicken and rice recipe"}
## Household context
### Ingredients on hand
- Chicken thighs
- rice
- cilantro
- black beans
- red onion
## Output contract
This contract overrides any earlier instruction about the form of your reply. Reply with one JSON value matching the JSON Schema "ideas_from_ingredients" below, and nothing else: no prose and no Markdown code fences.
{
"type": "object",
"properties": {
"ideas": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"uses": {
"type": "array",
"items": {
"type": "string"
}
},
"missing": {
"type": "array",
"items": {
"type": "string"
}
},
"est_minutes": {
"type": "integer"
},
"method": {
"type": "string",
"enum": [
"stovetop",
"oven",
"crockpot",
"grill",
"other"
]
},
"difficulty": {
"type": "string",
"enum": [
"easy",
"medium",
"hard"
]
},
"search_query": {
"type": "string"
}
},
"required": [
"name",
"uses",
"missing",
"est_minutes",
"method",
"difficulty",
"search_query"
],
"additionalProperties": false
}
}
},
"required": [
"ideas"
],
"additionalProperties": false
}
@@ -0,0 +1 @@
Suggest 8 dinner ideas from the ingredients on hand.