From 74e9673fc4d28fe2782d6429970b8d805dcdeae5 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 18 May 2024 14:51:48 +0200 Subject: [PATCH] Modal menu placeholder --- Chat.go | 48 +++++++++++- LLM.go | 36 +++++++++ main.go | 4 + static/style.css | 108 ++++++++++++++++++++++++++ views/chat.html | 2 +- views/partials/modal-llm-setting.html | 11 +++ views/partials/popover-keys.html | 2 +- views/partials/popover-models.html | 50 ++++++++---- 8 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 LLM.go create mode 100644 views/partials/modal-llm-setting.html diff --git a/Chat.go b/Chat.go index 928eb72..464be49 100644 --- a/Chat.go +++ b/Chat.go @@ -403,9 +403,51 @@ func LoadModelSelectionHandler(c *fiber.Ctx) error { if !checkIfLogin() { return c.SendString("") } - // openaiExists, anthropicExists, mistralExists, groqExists := getExistingKeys() - // TODO: Add model selection - return c.SendString("") + openaiExists, anthropicExists, mistralExists, groqExists, gooseaiExists, googleExists := getExistingKeys() + + var llms []LLM + err := edgeClient.Query(context.Background(), ` + SELECT LLM { + name, + context, + temperature, + modelInfo : { + modelID, + name + } + } + FILTER .user = global currentUser AND .name != 'none' + `, &llms) + if err != nil { + fmt.Println("Error in edgeClient.Query: in LoadModelSelectionHandler") + log.Fatal(err) + } + + for i := 0; i < len(llms); i++ { + // If the modelID len is higher than 15, truncate it + if len(llms[i].Model.ModelID) > 12 { + llms[i].Model.ModelID = llms[i].Model.ModelID[0:12] + "..." + } + } + + out, err := pongo2.Must(pongo2.FromFile("views/partials/popover-models.html")).Execute(pongo2.Context{ + "IsLogin": checkIfLogin(), + "OpenaiExists": openaiExists, + "AnthropicExists": anthropicExists, + "MistralExists": mistralExists, + "GroqExists": groqExists, + "GooseaiExists": gooseaiExists, + "GoogleExists": googleExists, + "AnyExists": openaiExists || anthropicExists || mistralExists || groqExists || gooseaiExists || googleExists, + "LLMs": llms, + }) + if err != nil { + c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "error": "Error rendering template", + }) + } + + return c.SendString(out) } func LoadSettingsHandler(c *fiber.Ctx) error { diff --git a/LLM.go b/LLM.go new file mode 100644 index 0000000..a82ea18 --- /dev/null +++ b/LLM.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + + "github.com/edgedb/edgedb-go" + "github.com/flosch/pongo2" + "github.com/gofiber/fiber/v2" +) + +// LLM stuff +func deleteLLM(c *fiber.Ctx) error { + id := c.FormValue("id") + idUUID, _ := edgedb.ParseUUID(id) + + err := edgeClient.Execute(edgeCtx, ` + DELETE LLM + FILTER .id = $0; + `, idUUID) + if err != nil { + fmt.Println("Error in edgeClient.Execute: in deleteLLM") + fmt.Println(err) + } + + return c.SendString("") +} + +func openLlmModal(c *fiber.Ctx) error { + out, err := pongo2.Must(pongo2.FromFile("views/partials/modal-llm-setting.html")).Execute(pongo2.Context{}) + if err != nil { + c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "error": "Error rendering template", + }) + } + return c.SendString(out) +} diff --git a/main.go b/main.go index 64b4df0..eb313d4 100644 --- a/main.go +++ b/main.go @@ -73,6 +73,7 @@ func main() { // Settings routes app.Post("/addKeys", addKeys) + app.Get("/modal", openLlmModal) // Popovers app.Get("/loadModelSelection", LoadModelSelectionHandler) @@ -86,6 +87,9 @@ func main() { app.Get("/callback", handleCallback) app.Get("/callbackSignup", handleCallbackSignup) + // LLM + app.Get("deleteLLM", deleteLLM) + app.Get("/test", func(c *fiber.Ctx) error { fmt.Println("Hello from test") return c.SendString("") diff --git a/static/style.css b/static/style.css index 2f83bc1..a7017fe 100644 --- a/static/style.css +++ b/static/style.css @@ -186,4 +186,112 @@ svg text { .message-bot:hover .message-button { opacity: 1; +} + +/***** MODAL DIALOG ****/ +#modal { + /* Underlay covers entire screen. */ + position: fixed; + top: 0px; + bottom: 0px; + left: 0px; + right: 0px; + background-color: rgba(0, 0, 0, 0.5); + z-index: 1000; + + /* Flexbox centers the .modal-content vertically and horizontally */ + display: flex; + flex-direction: column; + align-items: center; + + /* Animate when opening */ + animation-name: fadeIn; + animation-duration: 150ms; + animation-timing-function: ease; +} + +#modal>.modal-underlay { + /* underlay takes up the entire viewport. This is only + required if you want to click to dismiss the popup */ + position: absolute; + z-index: -1; + top: 0px; + bottom: 0px; + left: 0px; + right: 0px; +} + +#modal>.modal-content { + /* Position visible dialog near the top of the window */ + margin-top: 10vh; + + /* Sizing for visible dialog */ + width: 80%; + max-width: 600px; + + /* Display properties for visible dialog*/ + border: solid 1px #999; + border-radius: 8px; + box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.3); + background-color: white; + padding: 20px; + + /* Animate when opening */ + animation-name: zoomIn; + animation-duration: 150ms; + animation-timing-function: ease; +} + +#modal.closing { + /* Animate when closing */ + animation-name: fadeOut; + animation-duration: 150ms; + animation-timing-function: ease; +} + +#modal.closing>.modal-content { + /* Animate when closing */ + animation-name: zoomOut; + animation-duration: 150ms; + animation-timing-function: ease; +} + +@keyframes fadeIn { + 0% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} + +@keyframes fadeOut { + 0% { + opacity: 1; + } + + 100% { + opacity: 0; + } +} + +@keyframes zoomIn { + 0% { + transform: scale(0.9); + } + + 100% { + transform: scale(1); + } +} + +@keyframes zoomOut { + 0% { + transform: scale(1); + } + + 100% { + transform: scale(0.9); + } } \ No newline at end of file diff --git a/views/chat.html b/views/chat.html index a8ad93b..e262e56 100644 --- a/views/chat.html +++ b/views/chat.html @@ -10,7 +10,7 @@ - + + + \ No newline at end of file diff --git a/views/partials/popover-keys.html b/views/partials/popover-keys.html index e08f1c7..f89ebca 100644 --- a/views/partials/popover-keys.html +++ b/views/partials/popover-keys.html @@ -40,7 +40,7 @@

-
+

diff --git a/views/partials/popover-models.html b/views/partials/popover-models.html index 804e2a5..d7e4351 100644 --- a/views/partials/popover-models.html +++ b/views/partials/popover-models.html @@ -5,24 +5,42 @@