ui disables while loading
parent
0a3a7a0616
commit
8abea5c8c1
|
|
@ -127,6 +127,10 @@ func handle(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _handle(w http.ResponseWriter, r *http.Request) error {
|
func _handle(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
//ctx, can := context.WithTimeout(r.Context(), time.Minute)
|
||||||
|
//defer can()
|
||||||
|
//r = r.WithContext(ctx)
|
||||||
|
|
||||||
first := strings.Split(strings.TrimLeft(r.URL.Path, "/"), "/")[0]
|
first := strings.Split(strings.TrimLeft(r.URL.Path, "/"), "/")[0]
|
||||||
switch first {
|
switch first {
|
||||||
case "login":
|
case "login":
|
||||||
|
|
@ -345,7 +349,7 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
justNew, err := chatBotGenerateAndFillInputF(r.Context(), cacheF, inputF, reversePrompt)
|
justNew, err := chatBotGenerateAndFillInputF(r.Context(), cacheF, inputF, reversePrompt, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -385,7 +389,12 @@ func chatBotGenerateInitCacheF(ctx context.Context, cacheF, inputF string) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePrompt string) ([]byte, error) {
|
func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePrompt string, depth int) ([]byte, error) {
|
||||||
|
if depth >= 3 {
|
||||||
|
justNew := []byte("...\n" + reversePrompt)
|
||||||
|
return justNew, _appendFile(inputF, string(justNew))
|
||||||
|
}
|
||||||
|
|
||||||
commands := strings.Fields(Config.ChatBot.Command)
|
commands := strings.Fields(Config.ChatBot.Command)
|
||||||
commands = append(commands,
|
commands = append(commands,
|
||||||
"-f", inputF,
|
"-f", inputF,
|
||||||
|
|
@ -404,8 +413,8 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr
|
||||||
commands[1:]...,
|
commands[1:]...,
|
||||||
)
|
)
|
||||||
command.Dir = Config.ChatBot.WD
|
command.Dir = Config.ChatBot.WD
|
||||||
command.Stderr = log.Writer()
|
|
||||||
command.Stderr = io.Discard
|
command.Stderr = io.Discard
|
||||||
|
command.Stderr = log.Writer()
|
||||||
|
|
||||||
stdout, err := command.StdoutPipe()
|
stdout, err := command.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -447,7 +456,7 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.HasSuffix(append(priorContent, justNew...), []byte(reversePrompt)) {
|
if !bytes.HasSuffix(append(priorContent, justNew...), []byte(reversePrompt)) {
|
||||||
more, err := chatBotGenerateAndFillInputF(ctx, cacheF, inputF, reversePrompt)
|
more, err := chatBotGenerateAndFillInputF(ctx, cacheF, inputF, reversePrompt, depth+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,12 @@
|
||||||
|
|
||||||
function pushStream(newMessage) {
|
function pushStream(newMessage) {
|
||||||
body = new URLSearchParams(new FormData(newMessage)).toString()
|
body = new URLSearchParams(new FormData(newMessage)).toString()
|
||||||
newMessage.getElementsByTagName("button").disabled = true
|
for(var e of newMessage.elements)
|
||||||
newMessage.getElementsByTagName("input").disabled = true
|
if(!e.attributes.readonly)
|
||||||
|
e.disabled = true
|
||||||
http("PUT", "/api/v0/chatbot", (body, status) => {
|
http("PUT", "/api/v0/chatbot", (body, status) => {
|
||||||
newMessage.getElementsByTagName("button").disabled = false
|
for(var e of newMessage.elements)
|
||||||
newMessage.getElementsByTagName("input").disabled = false
|
e.disabled = false
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
log(body)
|
log(body)
|
||||||
return
|
return
|
||||||
|
|
@ -35,7 +36,7 @@
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
console.log(arguments)
|
console.log(arguments)
|
||||||
document.getElementById("debug-log").innerHTML += "\n" + new String(arguments)
|
document.getElementById("debug-log").innerHTML += "\n" + JSON.stringify(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
function http(method, remote, callback, body) {
|
function http(method, remote, callback, body) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue