···250250 if question == "" {
251251 return nil, fmt.Errorf("question is required")
252252 }
253253- if previousResponseID == "" {
254254- return nil, fmt.Errorf("response ID is required for questions")
255255- }
256253 client := openai.NewClient(option.WithAPIKey(c.apiKey))
257254258255 params := responses.ResponseNewParams{
259259- Model: c.model,
260260- PreviousResponseID: openai.String(previousResponseID),
261261- Instructions: openai.String("Answer the user's question about the recipe in plain text. Be concise and do not regenerate the full recipe or output JSON."),
256256+ Model: c.model,
257257+ Instructions: openai.String("Answer the user's question about the recipe in plain text. Be concise and do not regenerate the full recipe or output JSON."),
262258 Input: responses.ResponseNewParamsInputUnion{
263259 OfInputItemList: []responses.ResponseInputItemUnionParam{user(question)},
264260 },
265261 Store: openai.Bool(true),
262262+ }
263263+ if previousResponseID != "" {
264264+ params.PreviousResponseID = openai.String(previousResponseID)
266265 }
267266 resp, err := client.Responses.New(ctx, params)
268267 if err != nil {
+17-3
internal/recipes/server.go
···55 "bytes"
66 "context"
77 "encoding/base64"
88+ "encoding/json"
89 "errors"
910 "fmt"
1011 "html/template"
···366367 http.Error(w, "missing question", http.StatusBadRequest)
367368 return
368369 }
370370+369371 recipeTitle := strings.TrimSpace(r.FormValue("recipe_title"))
370372 questionForModel := question
371373 if recipeTitle != "" {
374374+ // we could drop this after first question
372375 questionForModel = fmt.Sprintf("Regarding %s: %s", recipeTitle, question)
373376 }
374377375378 responseID := strings.TrimSpace(r.FormValue("response_id"))
376379 if responseID == "" {
377377- slog.ErrorContext(ctx, "failed to load response id", "hash", hash)
378378- http.Error(w, "lost context on this recipe", http.StatusInternalServerError)
379379- return
380380+ slog.ErrorContext(ctx, "no response id falling back", "hash", hash)
381381+ r, err := s.SingleFromCache(ctx, hash)
382382+ if err != nil {
383383+ slog.ErrorContext(ctx, "failed to load response id", "hash", hash)
384384+ http.Error(w, "lost context on this recipe", http.StatusInternalServerError)
385385+ return
386386+ }
387387+ rjson, err := json.Marshal(r)
388388+ if err != nil {
389389+ slog.ErrorContext(ctx, "failed to load response id", "hash", hash)
390390+ http.Error(w, "lost context on this recipe", http.StatusInternalServerError)
391391+ return
392392+ }
393393+ questionForModel = fmt.Sprintf("Regarding this json recipe %s: %s", rjson, question)
380394 }
381395382396 // this is going to take a while. Start a go routine? and spin?