Almost working edit button
This commit is contained in:
parent
b104c989a5
commit
95a58f0f4b
126
Chat.go
126
Chat.go
@ -24,55 +24,6 @@ func ChatPageHandler(c *fiber.Ctx) error {
|
||||
return c.Render("chat", fiber.Map{"IsLogin": checkIfLogin(), "HaveKey": checkIfHaveKey()}, "layouts/main")
|
||||
}
|
||||
|
||||
func LoadModelSelectionHandler(c *fiber.Ctx) error {
|
||||
openaiExists, anthropicExists, mistralExists := getExistingKeys()
|
||||
|
||||
var CompanyInfosAvailable []CompanyInfo
|
||||
|
||||
if openaiExists {
|
||||
var openaiCompanyInfo CompanyInfo
|
||||
for _, info := range CompanyInfos {
|
||||
if info.ID == "openai" {
|
||||
openaiCompanyInfo = info
|
||||
break
|
||||
}
|
||||
}
|
||||
CompanyInfosAvailable = append(CompanyInfosAvailable, openaiCompanyInfo)
|
||||
}
|
||||
if anthropicExists {
|
||||
var anthropicCompanyInfo CompanyInfo
|
||||
for _, info := range CompanyInfos {
|
||||
if info.ID == "anthropic" {
|
||||
anthropicCompanyInfo = info
|
||||
break
|
||||
}
|
||||
}
|
||||
CompanyInfosAvailable = append(CompanyInfosAvailable, anthropicCompanyInfo)
|
||||
}
|
||||
if mistralExists {
|
||||
var mistralCompanyInfo CompanyInfo
|
||||
for _, info := range CompanyInfos {
|
||||
if info.ID == "mistral" {
|
||||
mistralCompanyInfo = info
|
||||
break
|
||||
}
|
||||
}
|
||||
CompanyInfosAvailable = append(CompanyInfosAvailable, mistralCompanyInfo)
|
||||
}
|
||||
|
||||
CheckedModels := []string{"gpt-3.5-turbo"} // Default model
|
||||
out, err := pongo2.Must(pongo2.FromFile("views/partials/popover-models.html")).Execute(pongo2.Context{
|
||||
"CompanyInfos": CompanyInfosAvailable,
|
||||
"CheckedModels": CheckedModels,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Error rendering template",
|
||||
})
|
||||
}
|
||||
return c.SendString(out)
|
||||
}
|
||||
|
||||
func DeleteMessageHandler(c *fiber.Ctx) error {
|
||||
messageId := c.FormValue("id")
|
||||
|
||||
@ -185,6 +136,7 @@ func generateChatHTML() string {
|
||||
|
||||
func GetMessageContentHandler(c *fiber.Ctx) error {
|
||||
messageId := c.FormValue("id")
|
||||
onlyContent := c.FormValue("onlyContent")
|
||||
|
||||
messageUUID, err := edgedb.ParseUUID(messageId)
|
||||
if err != nil {
|
||||
@ -207,6 +159,10 @@ func GetMessageContentHandler(c *fiber.Ctx) error {
|
||||
|
||||
modelID, _ := selectedMessage.ModelID.Get()
|
||||
|
||||
if onlyContent == "true" {
|
||||
return c.SendString(markdownToHTML(selectedMessage.Content))
|
||||
}
|
||||
|
||||
out := "<div class='message-header'>"
|
||||
out += "<p>"
|
||||
out += model2Name(modelID)
|
||||
@ -280,8 +236,29 @@ func generateEnterKeyChatHTML() string {
|
||||
return htmlString
|
||||
}
|
||||
|
||||
// Popover stuff
|
||||
// Buton actions
|
||||
func GetEditMessageFormHandler(c *fiber.Ctx) error {
|
||||
id := c.FormValue("id")
|
||||
idUUID, _ := edgedb.ParseUUID(id)
|
||||
|
||||
var message MessageContent
|
||||
err := edgeClient.QuerySingle(context.Background(), `
|
||||
SELECT Message { content }
|
||||
FILTER .id = <uuid>$0;
|
||||
`, &message, idUUID)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
tmpl := pongo2.Must(pongo2.FromFile("views/partials/edit-message-form.html"))
|
||||
out, err := tmpl.Execute(pongo2.Context{"Content": message.Content, "ID": id})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c.SendString(out)
|
||||
}
|
||||
|
||||
// Popover stuff
|
||||
func LoadUsageKPIHandler(c *fiber.Ctx) error {
|
||||
var TotalUsage float32
|
||||
// Using the database. Get the sum of all usage.inputCost and outputCost
|
||||
@ -359,3 +336,52 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
|
||||
}
|
||||
return c.SendString(out)
|
||||
}
|
||||
|
||||
func LoadModelSelectionHandler(c *fiber.Ctx) error {
|
||||
openaiExists, anthropicExists, mistralExists := getExistingKeys()
|
||||
|
||||
var CompanyInfosAvailable []CompanyInfo
|
||||
|
||||
if openaiExists {
|
||||
var openaiCompanyInfo CompanyInfo
|
||||
for _, info := range CompanyInfos {
|
||||
if info.ID == "openai" {
|
||||
openaiCompanyInfo = info
|
||||
break
|
||||
}
|
||||
}
|
||||
CompanyInfosAvailable = append(CompanyInfosAvailable, openaiCompanyInfo)
|
||||
}
|
||||
if anthropicExists {
|
||||
var anthropicCompanyInfo CompanyInfo
|
||||
for _, info := range CompanyInfos {
|
||||
if info.ID == "anthropic" {
|
||||
anthropicCompanyInfo = info
|
||||
break
|
||||
}
|
||||
}
|
||||
CompanyInfosAvailable = append(CompanyInfosAvailable, anthropicCompanyInfo)
|
||||
}
|
||||
if mistralExists {
|
||||
var mistralCompanyInfo CompanyInfo
|
||||
for _, info := range CompanyInfos {
|
||||
if info.ID == "mistral" {
|
||||
mistralCompanyInfo = info
|
||||
break
|
||||
}
|
||||
}
|
||||
CompanyInfosAvailable = append(CompanyInfosAvailable, mistralCompanyInfo)
|
||||
}
|
||||
|
||||
CheckedModels := []string{"gpt-3.5-turbo"} // Default model
|
||||
out, err := pongo2.Must(pongo2.FromFile("views/partials/popover-models.html")).Execute(pongo2.Context{
|
||||
"CompanyInfos": CompanyInfosAvailable,
|
||||
"CheckedModels": CheckedModels,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Error rendering template",
|
||||
})
|
||||
}
|
||||
return c.SendString(out)
|
||||
}
|
||||
|
@ -55,6 +55,10 @@ type Message struct {
|
||||
Conv Conversation `edgedb:"conversation"`
|
||||
}
|
||||
|
||||
type MessageContent struct {
|
||||
Content string `edgedb:"content"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
ID edgedb.UUID `edgedb:"id"`
|
||||
ModelID string `edgedb:"model_id"`
|
||||
|
6
main.go
6
main.go
@ -41,6 +41,7 @@ func main() {
|
||||
app.Post("/deleteMessage", DeleteMessageHandler)
|
||||
app.Get("/generateMultipleMessages", GenerateMultipleMessages)
|
||||
app.Get("/messageContent", GetMessageContentHandler)
|
||||
app.Get("/editMessageForm", GetEditMessageFormHandler)
|
||||
|
||||
// Settings routes
|
||||
app.Post("/addKeys", addKeys)
|
||||
@ -56,6 +57,11 @@ func main() {
|
||||
app.Get("/callback", handleCallback)
|
||||
app.Get("/callbackSignup", handleCallbackSignup)
|
||||
|
||||
app.Get("/test", func(c *fiber.Ctx) error {
|
||||
fmt.Println("Current User: ", getCurrentUser(), " - ", checkIfLogin())
|
||||
return c.Render("test", fiber.Map{})
|
||||
})
|
||||
|
||||
// Start server
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
@ -173,3 +173,17 @@ svg text {
|
||||
-ms-transform: rotate(45deg);
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
/* Message button styles */
|
||||
.message-button {
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.message-user:hover .message-button {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.message-bot:hover .message-button {
|
||||
opacity: 1;
|
||||
}
|
4
utils.go
4
utils.go
@ -53,7 +53,7 @@ func model2Icon(model string) string {
|
||||
if strings.Contains(model, "mistral") || strings.Contains(model, "mixtral") {
|
||||
return "mistral"
|
||||
}
|
||||
return "openai"
|
||||
return "bouvai2"
|
||||
}
|
||||
|
||||
func model2Name(model string) string {
|
||||
@ -62,7 +62,7 @@ func model2Name(model string) string {
|
||||
return ModelsInfos[i].Name
|
||||
}
|
||||
}
|
||||
return "OpenAI"
|
||||
return "You"
|
||||
}
|
||||
|
||||
func getExistingKeys() (bool, bool, bool) {
|
||||
|
@ -22,6 +22,13 @@
|
||||
|
||||
{{embed}}
|
||||
|
||||
<script>
|
||||
function updateIcon(icon, ConversationAreaId) {
|
||||
var selectedIcon = document.getElementById('selectedIcon-' + ConversationAreaId);
|
||||
selectedIcon.src = 'icons/' + icon + '.png';
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function copyToClipboardCode(button) {
|
||||
// Get the code element next to the button
|
||||
|
15
views/partials/edit-message-form.html
Normal file
15
views/partials/edit-message-form.html
Normal file
@ -0,0 +1,15 @@
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<textarea class="textarea mt-2" placeholder="Enter your message here"
|
||||
style="background-color: transparent;">{{ Content }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field is-grouped mb-3">
|
||||
<div class="control">
|
||||
<button hx-get="/test" class="button is-primary is-small">Submit</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button hx-get="/messageContent?id={{ ID }}&onlyContent=true" hx-target="#content-{{ ID }}"
|
||||
class="button is-light is-outlined is-small">Cancel</button>
|
||||
</div>
|
||||
</div>
|
@ -67,21 +67,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.message-button {
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.message-bot:hover .message-button {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function updateIcon(icon, ConversationAreaId) {
|
||||
var selectedIcon = document.getElementById('selectedIcon-' + ConversationAreaId);
|
||||
selectedIcon.src = 'icons/' + icon + '.png';
|
||||
}
|
||||
</script>
|
@ -15,7 +15,7 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="message-body">
|
||||
<div class="content" style="overflow-x: auto;">
|
||||
<div class="content" style="overflow-x: auto;" id="content-{{ ID }}">
|
||||
{{ Content|safe }}
|
||||
</div>
|
||||
</div>
|
||||
@ -27,7 +27,8 @@
|
||||
<i class="fa-solid fa-arrows-rotate"></i>
|
||||
</span>
|
||||
</button>
|
||||
<button id="edit-button-{{ ID }}" class="button is-small is-primary message-button is-outlined mr-2">
|
||||
<button hx-get="/editMessageForm?id={{ ID }}" hx-target="#content-{{ ID }}" id="edit-button-{{ ID }}"
|
||||
class="button is-small is-primary message-button is-outlined mr-5">
|
||||
<span class="icon">
|
||||
<i class="fa-solid fa-pen"></i>
|
||||
</span>
|
||||
@ -42,14 +43,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.message-button {
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.message-user:hover .message-button {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user