Use JSON for suggest responses

This commit is contained in:
Ian Gulliver
2024-11-26 13:29:56 -06:00
parent 0512fa41f6
commit a425ced673
3 changed files with 15 additions and 2 deletions

View File

@@ -151,7 +151,7 @@ func (ph *PHandler) serveSuggest(w http.ResponseWriter, r *http.Request) {
return
}
_, _ = w.Write([]byte(comp.Choices[0].Message.Content))
sendSuggestResponse(w, comp.Choices[0].Message.Content)
}
var allowedEnvs = []string{

View File

@@ -148,7 +148,7 @@ async function suggestNow() {
return;
}
document.getElementById('suggest-msg').innerText = await resp.text();
document.getElementById('suggest-msg').innerText = (await resp.json()).message;
document.getElementById('suggest').show();
}

13
suggest.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import (
"net/http"
)
type SuggestResponse struct {
Message string `json:"message"`
}
func sendSuggestResponse(w http.ResponseWriter, msg string) {
sendJSON(w, SuggestResponse{Message: msg})
}