diff --git a/main.go b/main.go index 6befed5..dbda2f4 100644 --- a/main.go +++ b/main.go @@ -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{ diff --git a/static/index.html b/static/index.html index a6c849c..60f2628 100644 --- a/static/index.html +++ b/static/index.html @@ -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(); } diff --git a/suggest.go b/suggest.go new file mode 100644 index 0000000..a822df3 --- /dev/null +++ b/suggest.go @@ -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}) +}