Working redo button
This commit is contained in:
parent
8a20078430
commit
ccddfdc631
28
Chat.go
28
Chat.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -343,23 +344,34 @@ func RedoMessageHandler(c *fiber.Ctx) error {
|
|||||||
messageId := c.FormValue("id")
|
messageId := c.FormValue("id")
|
||||||
messageUUID, _ := edgedb.ParseUUID(messageId)
|
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
|
// Delete messages
|
||||||
err := edgeClient.Execute(edgeCtx, `
|
err = edgeClient.Execute(edgeCtx, `
|
||||||
WITH
|
WITH
|
||||||
messageArea := (SELECT Message FILTER .id = <uuid>$0).area
|
messageArea := (SELECT Message FILTER .id = <uuid>$0).area
|
||||||
DELETE 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)
|
`, messageUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
messageOut, err := botTmpl.Execute(pongo2.Context{"IsPlaceholder": true})
|
return c.SendString(GeneratePlaceholderHTML(message.Content, selectedLLMIds, false))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.SendString(messageOut)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClearChatHandler(c *fiber.Ctx) error {
|
func ClearChatHandler(c *fiber.Ctx) error {
|
||||||
|
19
Request.go
19
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
|
// Step 1 I create a User message and send it as output with a placeholder
|
||||||
// that will make a request to GenerateMultipleMessagesHandler when loading
|
// that will make a request to GenerateMultipleMessagesHandler when loading
|
||||||
message := c.FormValue("message", "")
|
message := c.FormValue("message", "")
|
||||||
|
|
||||||
var selectedLLMIds []string
|
var selectedLLMIds []string
|
||||||
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
|
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -32,6 +31,10 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return c.SendString(GeneratePlaceholderHTML(message, selectedLLMIds, true))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GeneratePlaceholderHTML(message string, selectedLLMIds []string, with_user_message bool) string {
|
||||||
var selectedLLMs []LLM
|
var selectedLLMs []LLM
|
||||||
var selectedLLM LLM
|
var selectedLLM LLM
|
||||||
|
|
||||||
@ -68,16 +71,18 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error {
|
|||||||
lastSelectedLLMs = selectedLLMs
|
lastSelectedLLMs = selectedLLMs
|
||||||
|
|
||||||
_, position := insertArea()
|
_, position := insertArea()
|
||||||
messageID := insertUserMessage(message)
|
|
||||||
|
|
||||||
out := ""
|
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
|
out += messageOut
|
||||||
|
|
||||||
messageOut, _ = botTmpl.Execute(pongo2.Context{"IsPlaceholder": true, "SelectedLLMs": selectedLLMs, "ConversationAreaId": position + 1})
|
return out
|
||||||
out += messageOut
|
|
||||||
|
|
||||||
return c.SendString(out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateMultipleMessagesHandler(c *fiber.Ctx) error {
|
func GenerateMultipleMessagesHandler(c *fiber.Ctx) error {
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="redo-button-{{ ID }}" class="button is-small is-primary message-button is-outlined mr-1"
|
<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">
|
<span class="icon">
|
||||||
<i class="fa-solid fa-arrows-rotate"></i>
|
<i class="fa-solid fa-arrows-rotate"></i>
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user