Use JSON for suggest responses
This commit is contained in:
2
main.go
2
main.go
@@ -151,7 +151,7 @@ func (ph *PHandler) serveSuggest(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = w.Write([]byte(comp.Choices[0].Message.Content))
|
sendSuggestResponse(w, comp.Choices[0].Message.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
var allowedEnvs = []string{
|
var allowedEnvs = []string{
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ async function suggestNow() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('suggest-msg').innerText = await resp.text();
|
document.getElementById('suggest-msg').innerText = (await resp.json()).message;
|
||||||
document.getElementById('suggest').show();
|
document.getElementById('suggest').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
suggest.go
Normal file
13
suggest.go
Normal 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})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user