Working redo button

This commit is contained in:
Adrien Bouvais 2024-05-23 19:38:59 +02:00
parent 8a20078430
commit ccddfdc631
3 changed files with 34 additions and 16 deletions

28
Chat.go
View File

@ -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 = <uuid>$0;
`, &message, messageUUID)
if err != nil {
panic(err)
}
// Delete messages
err := edgeClient.Execute(edgeCtx, `
err = edgeClient.Execute(edgeCtx, `
WITH
messageArea := (SELECT Message FILTER .id = <uuid>$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 {

View File

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

View File

@ -29,7 +29,8 @@
</span>
</button>
<button id="redo-button-{{ ID }}" class="button is-small is-primary message-button is-outlined mr-1"
hx-post="/redoMessage?id={{ ID }}" hx-swap="innerHTML settle:200ms" hx-target="next .message-bot">
hx-post="/redoMessage?id={{ ID }}" hx-swap="innerHTML settle:200ms" hx-target="next .message-bot"
hx-vals="js:{selectedLLMIds: getSelectedModelsIDs()}">
<span class="icon">
<i class="fa-solid fa-arrows-rotate"></i>
</span>