···149149}
150150151151func (g *Generator) GenerateRecipes(ctx context.Context, p *generatorParams) error {
152152- slog.InfoContext(ctx, "Generating recipes for location", "location", p.String())
153152154153 hash := p.Hash()
155154 generating, done := g.isGenerating(hash)
···162161163162 var err error
164163 if p.ConversationID != "" && p.Instructions != "" {
165165- // these should both alwas be true. Warn if not because its a caching bug?
164164+ slog.InfoContext(ctx, "Regenerating recipes for location", "location", p.String(), "conversation_id", p.ConversationID)
165165+ // these should both always be true. Warn if not because its a caching bug?
166166 shoppingList, err := g.aiClient.Regenerate(ctx, p.Instructions, p.ConversationID)
167167 if err != nil {
168168 return fmt.Errorf("failed to regenerate recipes with AI: %w", err)
169169 }
170170 slog.InfoContext(ctx, "regenerated chat", "location", p.String(), "duration", time.Since(start), "hash", hash)
171171+172172+ paramsJSON := lo.Must(json.Marshal(p))
173173+ if err := g.cache.Set(p.Hash()+".params", string(paramsJSON)); err != nil {
174174+ slog.ErrorContext(ctx, "failed to cache params", "location", p.String(), "error", err)
175175+ return err
176176+ }
171177 return saveShoppingList(ctx, g.cache, shoppingList, p)
172178 }
173173-179179+ slog.InfoContext(ctx, "Generating recipes for location", "location", p.String())
174180 ingredients, err := g.GetStaples(ctx, p)
175181 if err != nil {
176182 return fmt.Errorf("failed to get staples: %w", err)
···179185 if err != nil {
180186 return fmt.Errorf("failed to generate recipes with AI: %w", err)
181187 }
188188+ p.ConversationID = shoppingList.ConversationID
182189 slog.InfoContext(ctx, "generated chat", "location", p.String(), "duration", time.Since(start), "hash", hash)
183190 if err := saveShoppingList(ctx, g.cache, shoppingList, p); err != nil {
184191 return fmt.Errorf("failed to save shopping list: %w", err)
185192 }
186186- // Also cache the params for hash-based retrieval
187187- // TODO: Consider embedding the params directly in the shoppingList structure.
188188- // This would allow us to cache both the shopping list and its associated parameters together,
189189- // avoiding the need for a separate cache entry for params (currently stored as "<hash>.params").
190190- // Embedding params could simplify cache management and ensure all relevant data is retrieved together.
191191- // Persist the latest conversation IDs with the params so follow-ups can reuse them.
192192- p.ConversationID = shoppingList.ConversationID
193193- paramsJSON := lo.Must(json.Marshal(p))
194194- if err := g.cache.Set(p.Hash()+".params", string(paramsJSON)); err != nil {
195195- slog.ErrorContext(ctx, "failed to cache params", "location", p.String(), "error", err)
196196- return err
197197- }
193193+198194 return nil
199195}
200196···216212 return err
217213 }
218214215215+ // Also cache the params for hash-based retrieval
216216+ // TODO: Consider embedding the params directly in the shoppingList structure.
217217+ // This would allow us to cache both the shopping list and its associated parameters together,
218218+ // avoiding the need for a separate cache entry for params (currently stored as "<hash>.params").
219219+ // Embedding params could simplify cache management and ensure all relevant data is retrieved together.
220220+ // Persist the latest conversation IDs with the params so follow-ups can reuse them.
221221+ paramsJSON := lo.Must(json.Marshal(p))
222222+ if err := cache.Set(p.Hash()+".params", string(paramsJSON)); err != nil {
223223+ slog.ErrorContext(ctx, "failed to cache params", "location", p.String(), "error", err)
224224+ return err
225225+ }
219226 return nil
220227}
221228
+5-3
internal/recipes/server.go
···6767 Name: "Unknown Location",
6868 }, time.Now())
6969 if recipe.OriginHash != "" {
7070- p, err = s.generator.LoadParamsFromHash(recipe.OriginHash)
7070+ loadedp, err := s.generator.LoadParamsFromHash(recipe.OriginHash)
7171 if err != nil {
7272 slog.ErrorContext(ctx, "failed to load params for hash", "hash", recipe.OriginHash, "error", err)
7373- http.Error(w, "recipe not found or expired", http.StatusNotFound)
7474- return
7373+ //http.Error(w, "recipe not found or expired", http.StatusNotFound)
7474+ //return
7575+ } else {
7676+ p = loadedp
7577 }
7678 }
7779