From ccddfdc6317c15196125289a9cdc9b485c932c26 Mon Sep 17 00:00:00 2001 From: Adrien Date: Thu, 23 May 2024 19:38:59 +0200 Subject: [PATCH] Working redo button --- Chat.go | 28 ++++++++++++++++++++-------- Request.go | 19 ++++++++++++------- views/partials/message-user.html | 3 ++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Chat.go b/Chat.go index b9e869b..a95f8e3 100644 --- a/Chat.go +++ b/Chat.go @@ -2,6 +2,7 @@ package main import ( "context" + "encoding/json" "fmt" "sort" "strings" @@ -343,23 +344,34 @@ func RedoMessageHandler(c *fiber.Ctx) error { messageId := c.FormValue("id") messageUUID, _ := edgedb.ParseUUID(messageId) + var selectedLLMIds []string + err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) + if err != nil { + // Handle the error + panic(err) + } + + var message Message + err = edgeClient.QuerySingle(context.Background(), ` + SELECT Message { content } + FILTER .id = $0; + `, &message, messageUUID) + if err != nil { + panic(err) + } + // Delete messages - err := edgeClient.Execute(edgeCtx, ` + err = edgeClient.Execute(edgeCtx, ` WITH messageArea := (SELECT Message FILTER .id = $0).area DELETE Area - FILTER .position > messageArea.position AND .conversation = messageArea.conversation; + FILTER .position > messageArea.position AND .conversation = messageArea.conversation AND .conversation.user = global currentUser; `, messageUUID) if err != nil { panic(err) } - messageOut, err := botTmpl.Execute(pongo2.Context{"IsPlaceholder": true}) - if err != nil { - panic(err) - } - - return c.SendString(messageOut) + return c.SendString(GeneratePlaceholderHTML(message.Content, selectedLLMIds, false)) } func ClearChatHandler(c *fiber.Ctx) error { diff --git a/Request.go b/Request.go index 3f28182..2575191 100644 --- a/Request.go +++ b/Request.go @@ -24,7 +24,6 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error { // Step 1 I create a User message and send it as output with a placeholder // that will make a request to GenerateMultipleMessagesHandler when loading message := c.FormValue("message", "") - var selectedLLMIds []string err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) if err != nil { @@ -32,6 +31,10 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error { panic(err) } + return c.SendString(GeneratePlaceholderHTML(message, selectedLLMIds, true)) +} + +func GeneratePlaceholderHTML(message string, selectedLLMIds []string, with_user_message bool) string { var selectedLLMs []LLM var selectedLLM LLM @@ -68,16 +71,18 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error { lastSelectedLLMs = selectedLLMs _, position := insertArea() - messageID := insertUserMessage(message) out := "" - messageOut, _ := userTmpl.Execute(pongo2.Context{"Content": markdownToHTML(message), "ID": messageID.String()}) + if with_user_message { + messageID := insertUserMessage(message) + messageOut, _ := userTmpl.Execute(pongo2.Context{"Content": markdownToHTML(message), "ID": messageID.String()}) + out += messageOut + } + + messageOut, _ := botTmpl.Execute(pongo2.Context{"IsPlaceholder": true, "SelectedLLMs": selectedLLMs, "ConversationAreaId": position + 1}) out += messageOut - messageOut, _ = botTmpl.Execute(pongo2.Context{"IsPlaceholder": true, "SelectedLLMs": selectedLLMs, "ConversationAreaId": position + 1}) - out += messageOut - - return c.SendString(out) + return out } func GenerateMultipleMessagesHandler(c *fiber.Ctx) error { diff --git a/views/partials/message-user.html b/views/partials/message-user.html index d21ac70..bcc5b38 100644 --- a/views/partials/message-user.html +++ b/views/partials/message-user.html @@ -29,7 +29,8 @@