| 1 | package library |
| 2 | |
| 3 | import ( |
| 4 | "github.com/go-chi/chi/v5" |
| 5 | "net/http" |
| 6 | "slices" |
| 7 | ) |
| 8 | |
| 9 | func (h *Handler) SaveLegacy(w http.ResponseWriter, r *http.Request) { |
| 10 | key := chi.URLParam(r, "key") |
| 11 | if !slices.Contains(DefaultKeys, key) { |
| 12 | h.Failure(w, r, h.NotFound) |
| 13 | return |
| 14 | } |
| 15 | actor, err := h.LegacyForm(w, r, "revision", "model_selection", "provider", "model_family", "model", "standing_instructions", "max_concurrent") |
| 16 | if err != nil { |
| 17 | h.Failure(w, r, err) |
| 18 | return |
| 19 | } |
| 20 | revision, err := h.Number(r, "revision") |
| 21 | if err != nil { |
| 22 | h.Failure(w, r, err) |
| 23 | return |
| 24 | } |
| 25 | concurrent, err := h.Number(r, "max_concurrent") |
| 26 | if err != nil || int64(int(concurrent)) != concurrent { |
| 27 | h.Failure(w, r, h.Invalid) |
| 28 | return |
| 29 | } |
| 30 | err = h.Store.SaveSpecialist(r.Context(), actor, Specialist{Key: key, Revision: revision, ModelSelection: r.PostForm.Get("model_selection"), Provider: r.PostForm.Get("provider"), ModelFamily: r.PostForm.Get("model_family"), Model: r.PostForm.Get("model"), StandingInstructions: r.PostForm.Get("standing_instructions"), MaxConcurrent: int(concurrent)}) |
| 31 | if err != nil { |
| 32 | h.Failure(w, r, err) |
| 33 | return |
| 34 | } |
| 35 | http.Redirect(w, r, "/specialists/"+key, http.StatusSeeOther) |
| 36 | } |
| 37 | |