diff --git a/vicuna-tools.d/main.go b/vicuna-tools.d/main.go index 892e6b1..741cae2 100644 --- a/vicuna-tools.d/main.go +++ b/vicuna-tools.d/main.go @@ -127,6 +127,10 @@ func handle(w http.ResponseWriter, r *http.Request) { } 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] switch first { case "login": @@ -345,7 +349,7 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error { return err } - justNew, err := chatBotGenerateAndFillInputF(r.Context(), cacheF, inputF, reversePrompt) + justNew, err := chatBotGenerateAndFillInputF(r.Context(), cacheF, inputF, reversePrompt, 0) if err != nil { return err } @@ -385,7 +389,12 @@ func chatBotGenerateInitCacheF(ctx context.Context, cacheF, inputF string) error 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 = append(commands, "-f", inputF, @@ -404,8 +413,8 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr commands[1:]..., ) command.Dir = Config.ChatBot.WD - command.Stderr = log.Writer() command.Stderr = io.Discard + command.Stderr = log.Writer() stdout, err := command.StdoutPipe() if err != nil { @@ -447,7 +456,7 @@ func chatBotGenerateAndFillInputF(ctx context.Context, cacheF, inputF, reversePr } 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 { return nil, err } diff --git a/vicuna-tools.d/template.d/chatbot.html b/vicuna-tools.d/template.d/chatbot.html index 237a38c..67b5f3f 100644 --- a/vicuna-tools.d/template.d/chatbot.html +++ b/vicuna-tools.d/template.d/chatbot.html @@ -20,11 +20,12 @@ function pushStream(newMessage) { body = new URLSearchParams(new FormData(newMessage)).toString() - newMessage.getElementsByTagName("button").disabled = true - newMessage.getElementsByTagName("input").disabled = true + for(var e of newMessage.elements) + if(!e.attributes.readonly) + e.disabled = true http("PUT", "/api/v0/chatbot", (body, status) => { - newMessage.getElementsByTagName("button").disabled = false - newMessage.getElementsByTagName("input").disabled = false + for(var e of newMessage.elements) + e.disabled = false if (status != 200) { log(body) return @@ -35,7 +36,7 @@ function log() { 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) {