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 @@
+