From 26da94f6d776b2319d7b7be19ecb4c0c4a22870b Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 17 Jun 2023 11:04:45 -0600 Subject: [PATCH] that kinda works api/v0/chatbot --- vicuna-tools.d/main.go | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/vicuna-tools.d/main.go b/vicuna-tools.d/main.go index 804c92d..35be17b 100644 --- a/vicuna-tools.d/main.go +++ b/vicuna-tools.d/main.go @@ -263,8 +263,8 @@ func handleAPIChatBot(w http.ResponseWriter, r *http.Request) error { func handleAPIChatBotPost(w http.ResponseWriter, r *http.Request) error { cookie, _ := ParseCookie(r) sessionD := path.Join(Config.ChatBot.SessionD, cookie.Name) - if _, err := os.Stat(path.Join(sessionD, "chat.d")); err == nil { - if err := os.RemoveAll(path.Join(sessionD, "chat.d")); err != nil { + if _, err := os.Stat(path.Join(sessionD)); err == nil { + if err := os.RemoveAll(path.Join(sessionD)); err != nil { return err } } @@ -363,31 +363,11 @@ func handleAPIChatBotPut(w http.ResponseWriter, r *http.Request) error { return err } - log.Printf("OUTPUT: %s", buff.Bytes()) - return errors.New("not impl: move input to prompt") - - /* - go func() { - Config.ChatBot.semaphore.Lock() - defer Config.ChatBot.semaphore.Unlock() - - commands := strings.Fields(Config.ChatBot.Command) - commands = append(commands, - "-f", promptF, - "--batch_size", "8", - "--prompt-cache", cacheF, - "--file", promptF, - "--n_predict", "1", - ) - command := exec.CommandContext( - r.Context(), - commands[0], - commands[1:]..., - ) - command.Dir = Config.ChatBot.WD - command.Run() - }() - */ + result := bytes.TrimSuffix(buff.Bytes(), []byte(reversePrompt)) + if err := os.WriteFile(promptF, result, os.ModePerm); err != nil { + return err + } + w.Write(result) return nil }