From 1a7f783fe0eda3aa9047137edf518136be13116c Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 17 Jun 2023 14:31:47 -0600 Subject: [PATCH] ok submitting a prompt --- vicuna-tools.d/main.go | 23 +++++++++- vicuna-tools.d/main_integration_test.go | 13 ++++++ vicuna-tools.d/template.d/chatbot.html | 60 ++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/vicuna-tools.d/main.go b/vicuna-tools.d/main.go index 8cc5668..892e6b1 100644 --- a/vicuna-tools.d/main.go +++ b/vicuna-tools.d/main.go @@ -171,7 +171,12 @@ func handleUI(w http.ResponseWriter, r *http.Request) error { w.Write(htmlIndex) return nil case "/chatbot": - w.Write(htmlChatBot) + if !Config.Debug { + w.Write(htmlChatBot) + } else { + b, _ := os.ReadFile("./template.d/chatbot.html") + w.Write(b) + } return nil default: return handleNotFound(w, r) @@ -258,6 +263,7 @@ func handleNotFound(w http.ResponseWriter, r *http.Request) error { } func handleAPIChatBot(w http.ResponseWriter, r *http.Request) error { + r.Header.Set("Content-Type", "application/x-www-form-urlencoded") err := r.ParseForm() if err != nil { return err @@ -268,11 +274,26 @@ func handleAPIChatBot(w http.ResponseWriter, r *http.Request) error { return handleAPIChatBotPost(w, r) case http.MethodPut: return handleAPIChatBotPut(w, r) + case http.MethodGet: + return handleAPIChatBotGet(w, r) default: return handleNotFound(w, r) } } +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")) + if err != nil { + return err + } + defer f.Close() + + io.Copy(w, f) + return nil +} + func handleAPIChatBotPost(w http.ResponseWriter, r *http.Request) error { cookie, _ := ParseCookie(r) sessionD := path.Join(Config.ChatBot.SessionD, cookie.MyName()) diff --git a/vicuna-tools.d/main_integration_test.go b/vicuna-tools.d/main_integration_test.go index adf7456..8814103 100644 --- a/vicuna-tools.d/main_integration_test.go +++ b/vicuna-tools.d/main_integration_test.go @@ -52,6 +52,19 @@ func TestAPIV0ChatBot(t *testing.T) { t.Errorf("dupe generation: %s", stderrStash.Bytes()) stderrStash.Reset() } + + resp3 := httpDo(t, http.MethodGet, "/api/v0/chatbot", "") + got3, err := io.ReadAll(resp3.Body) + if err != nil { + t.Fatal(err) + } + + if !bytes.Contains(got3, got) { + t.Error("forgot got") + } + if !bytes.Contains(got3, got2) { + t.Error("forgot got2") + } }) t.Run("post over post", func(t *testing.T) { diff --git a/vicuna-tools.d/template.d/chatbot.html b/vicuna-tools.d/template.d/chatbot.html index d00bfd1..a76bee1 100644 --- a/vicuna-tools.d/template.d/chatbot.html +++ b/vicuna-tools.d/template.d/chatbot.html @@ -1,8 +1,66 @@
+
- + +
+ Set up a new session +
+ + +
+
+
+ Use your session +
+ +
+ + +
+
+
+
+