diff --git a/internal/web/uploads.go b/internal/web/uploads.go index 24e84bd..28601fe 100644 --- a/internal/web/uploads.go +++ b/internal/web/uploads.go @@ -220,7 +220,8 @@ func (a *App) handleUploadChat(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/uploads/"+u.ID, http.StatusSeeOther) return } - a.render(w, r, UploadChatPage(*u, a.uploadChatView(*u, a.Chat.DefaultModel(a.UploadChatModel), nil, false, ""))) + model, _ := a.resolveUploadModel("") + a.render(w, r, UploadChatPage(*u, a.uploadChatView(*u, model, nil, false, ""))) } // handleUploadChatMessage answers one question against the owner's uploaded @@ -240,7 +241,13 @@ func (a *App) handleUploadChatMessage(w http.ResponseWriter, r *http.Request) { http.Error(w, "bad form", http.StatusBadRequest) return } - model := a.resolveModel(r.FormValue("model"), a.UploadChatModel) + model, ok := a.resolveUploadModel(r.FormValue("model")) + if !ok { + a.logger().Error("upload chat: no local model is configured; nothing was sent", "upload", u.ID) + view := a.uploadChatView(*u, "", nil, false, "No local model is available for chat about a recording.") + a.render(w, r, UploadChatPage(*u, view)) + return + } history := parseHistory(r.Form["hq"], r.Form["ha"]) question := strings.TrimSpace(r.FormValue("question")) @@ -273,7 +280,7 @@ func (a *App) uploadChatView(u domain.UploadedTranscript, model string, history VideoID: u.ID, Title: u.Title, Available: true, - Models: a.Chat.Models(), + Models: a.UploadChatModels, Selected: model, History: history, Truncated: truncated, @@ -401,3 +408,27 @@ func minutesAgo(d time.Duration) string { } return "under a minute" } + +// resolveUploadModel picks the model for chat over an uploaded recording from the +// offered LOCAL set only: the posted one when it is in the set, else the configured +// default when it is, else the first. ok is false when no model is offered, in which +// case nothing may be sent anywhere (the whole private transcript is the payload). +func (a *App) resolveUploadModel(posted string) (model string, ok bool) { + offered := func(m string) bool { + for _, o := range a.UploadChatModels { + if o == m { + return true + } + } + return false + } + switch { + case posted != "" && offered(posted): + return posted, true + case a.UploadChatModel != "" && offered(a.UploadChatModel): + return a.UploadChatModel, true + case len(a.UploadChatModels) > 0: + return a.UploadChatModels[0], true + } + return "", false +}