diff --git a/vicuna-tools.d/main.go b/vicuna-tools.d/main.go index 741cae2..ec8af64 100644 --- a/vicuna-tools.d/main.go +++ b/vicuna-tools.d/main.go @@ -288,14 +288,23 @@ func handleAPIChatBot(w http.ResponseWriter, r *http.Request) error { func handleAPIChatBotGet(w http.ResponseWriter, r *http.Request) error { cookie, _ := ParseCookie(r) sessionD := path.Join(Config.ChatBot.SessionD, cookie.MyName()) - f, err := os.Open(path.Join(sessionD, "prompt.txt")) + + messages, err := os.ReadFile(path.Join(sessionD, "prompt.txt")) + if err != nil { + return err + } + prompt, err := os.ReadFile(path.Join(sessionD, "initial-prompt.txt")) if err != nil { return err } - defer f.Close() - io.Copy(w, f) - return nil + return json.NewEncoder(w).Encode(struct { + Messages string + Prompt string + }{ + Messages: string(messages), + Prompt: string(prompt), + }) } func handleAPIChatBotPost(w http.ResponseWriter, r *http.Request) error { @@ -314,6 +323,9 @@ func handleAPIChatBotPost(w http.ResponseWriter, r *http.Request) error { if len(prompt) == 0 { return errors.New("no prompt") } + if err := os.WriteFile(path.Join(sessionD, "initial-prompt.txt"), []byte(prompt), os.ModePerm); err != nil { + return err + } if err := os.WriteFile(path.Join(sessionD, "prompt.txt"), []byte(prompt), os.ModePerm); err != nil { return err } diff --git a/vicuna-tools.d/template.d/chatbot.html b/vicuna-tools.d/template.d/chatbot.html index 67b5f3f..c814e0e 100644 --- a/vicuna-tools.d/template.d/chatbot.html +++ b/vicuna-tools.d/template.d/chatbot.html @@ -4,10 +4,17 @@