This commit is contained in:
Adrien Bouvais 2024-05-25 10:56:15 +02:00
parent b8a2f02657
commit c05de5d325
6 changed files with 48 additions and 30 deletions

39
Chat.go
View File

@ -86,10 +86,19 @@ type TemplateMessage struct {
} }
func generateChatHTML() string { func generateChatHTML() string {
// Print the name of the current conversation
var currentConv Conversation
err := edgeClient.QuerySingle(edgeCtx, `
SELECT global currentConversation { name }`, &currentConv)
if err != nil {
panic(err)
}
fmt.Println("Current conversation: ", currentConv.Name)
// Maybe redo that to be area by area because look like shit rn. It come from early stage of dev. It work tho soooo... // Maybe redo that to be area by area because look like shit rn. It come from early stage of dev. It work tho soooo...
var Messages []Message var Messages []Message
err := edgeClient.Query(edgeCtx, ` err = edgeClient.Query(edgeCtx, `
SELECT Message { SELECT Message {
id, id,
selected, selected,
@ -700,10 +709,6 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
} }
func CreateConversationHandler(c *fiber.Ctx) error { func CreateConversationHandler(c *fiber.Ctx) error {
if !checkIfLogin() || !checkIfHaveKey() {
return c.SendString("")
}
name := c.FormValue("conversation-name-input") name := c.FormValue("conversation-name-input")
if name == "" { if name == "" {
name = "New Conversation" name = "New Conversation"
@ -728,11 +733,27 @@ func CreateConversationHandler(c *fiber.Ctx) error {
return c.SendString(GenerateConversationPopoverHTML(true)) return c.SendString(GenerateConversationPopoverHTML(true))
} }
func SelectConversationHandler(c *fiber.Ctx) error { func DeleteConversationHandler(c *fiber.Ctx) error {
if !checkIfLogin() || !checkIfHaveKey() { conversationId := c.FormValue("conversationId")
return c.SendString("")
conversationUUID, err := edgedb.ParseUUID(conversationId)
if err != nil {
// Handle the error
panic(err)
} }
err = edgeClient.Execute(edgeCtx, `
DELETE Conversation
FILTER .user = global currentUser AND .id = <uuid>$0;
`, conversationUUID)
if err != nil {
panic(err)
}
return c.SendString(GenerateConversationPopoverHTML(true))
}
func SelectConversationHandler(c *fiber.Ctx) error {
conversationId := c.FormValue("conversation-id") conversationId := c.FormValue("conversation-id")
conversationUUID, err := edgedb.ParseUUID(conversationId) conversationUUID, err := edgedb.ParseUUID(conversationId)
if err != nil { if err != nil {
@ -740,6 +761,8 @@ func SelectConversationHandler(c *fiber.Ctx) error {
panic(err) panic(err)
} }
fmt.Println("conversationUUID", conversationUUID.String())
err = edgeClient.Execute(edgeCtx, ` err = edgeClient.Execute(edgeCtx, `
SET global currentConversation := ( SET global currentConversation := (
SELECT Conversation SELECT Conversation

1
LLM.go
View File

@ -141,6 +141,7 @@ func updateLLMPositionBatch(c *fiber.Ctx) error {
return nil return nil
} }
// When we reorder the LLM list
func updateConversationPositionBatch(c *fiber.Ctx) error { func updateConversationPositionBatch(c *fiber.Ctx) error {
var positionUpdates []PositionUpdate var positionUpdates []PositionUpdate
if err := c.BodyParser(&positionUpdates); err != nil { if err := c.BodyParser(&positionUpdates); err != nil {

View File

@ -1,3 +1,5 @@
// Hohohoho. Bienvenue mes amis.
// I think you gonna be interested by this part.
package main package main
import ( import (

View File

@ -121,6 +121,7 @@ func main() {
app.Get("/loadSettings", LoadSettingsHandler) app.Get("/loadSettings", LoadSettingsHandler)
app.Post("/updateLLMPositionBatch", updateLLMPositionBatch) app.Post("/updateLLMPositionBatch", updateLLMPositionBatch)
app.Get("/createConversation", CreateConversationHandler) app.Get("/createConversation", CreateConversationHandler)
app.Get("/deleteConversation", DeleteConversationHandler)
app.Get("/selectConversation", SelectConversationHandler) app.Get("/selectConversation", SelectConversationHandler)
app.Post("/updateConversationPositionBatch", updateConversationPositionBatch) app.Post("/updateConversationPositionBatch", updateConversationPositionBatch)

View File

@ -1,11 +0,0 @@
<div id="modal">
<div class="modal-underlay" hx-get="/empty" hx-target="#modal" hx-swap="outerHTML"></div>
<div class="modal-content">
<h1>Modal Dialog</h1>
This is the modal content.
You can put anything here, like text, or a form, or an image.
<br>
<br>
<button hx-get="/empty" hx-target="#modal" hx-swap="outerHTML">Close</button>
</div>
</div>

View File

@ -13,9 +13,11 @@
<div class="dropdown-item"> <div class="dropdown-item">
<div id="conversation-list"> <div id="conversation-list">
{% for Conversation in Conversations %} {% for Conversation in Conversations %}
<div class="icon-text has-text unselected icon-conv" data-id="{{ Conversation.ID.String() }}" <div class="icon-text has-text unselected icon-conv {% if Conversation.Name == 'Default' %} selected {% endif %}"
style="cursor: pointer;" onclick="toggleConversationSelection(this)" hx-get="/loadChat" data-id="{{ Conversation.ID.String() }}" style="cursor: pointer;"
hx-swap="outerHTML" hx-target="#chat-container"> onclick="toggleConversationSelection(this)"
hx-get="/selectConversation?conversation-id={{ Conversation.ID.String() }}" hx-swap="outerHTML"
hx-target="#chat-container">
<span>{{ Conversation.Name }}</span> <span>{{ Conversation.Name }}</span>
</div> </div>
{% endfor %} {% endfor %}
@ -23,7 +25,9 @@
<input class="input is-small mt-2 is-hidden" type="text" id="conversation-name-input" <input class="input is-small mt-2 is-hidden" type="text" id="conversation-name-input"
name="conversation-name-input" placeholder="Conversation name" autocomplete="off"> name="conversation-name-input" placeholder="Conversation name" autocomplete="off">
<div class="is-flex is-justify-content-space-between mt-4"> <div class="is-flex is-justify-content-space-between mt-4">
<button disabled class="button is-small is-danger" id="delete-conversation-button"> <button class="button is-small is-danger" id="delete-conversation-button"
hx-get="/deleteConversation" hx-swap="outerHTML" hx-target="#conversation-dropdown"
hx-vals="js:{conversationId: findSelectedConversationID()}">
<span class="icon"> <span class="icon">
<i class="fa-solid fa-trash"></i> <i class="fa-solid fa-trash"></i>
</span> </span>
@ -54,17 +58,15 @@
</div> </div>
</div> </div>
<script> <script>
function findSelectedConversationID() {
return document.getElementsByClassName('icon-conv selected')[0].getAttribute('data-id');
}
function toggleConversationSelection(element) { function toggleConversationSelection(element) {
const elements = Array.from(document.getElementsByClassName('icon-conv')); const elements = Array.from(document.getElementsByClassName('icon-conv'));
// If the conversation is already selected, unselect it // If the conversation is already selected, keep it
if (element.classList.contains('selected')) { if (element.classList.contains('selected')) {
for (let i = 0; i < elements.length; i++) { // Do nothing
elements[i].classList.remove('selected');
elements[i].classList.add('unselected');
}
element.classList.remove('selected');
element.classList.add('unselected');
return; return;
} else if (element.classList.contains('unselected')) { } else if (element.classList.contains('unselected')) {
for (let i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {