From 920c34c25c448842669c4b0032f0e9cd1c2b1f56 Mon Sep 17 00:00:00 2001 From: Adrien Date: Thu, 16 May 2024 17:11:26 +0200 Subject: [PATCH] fex --- Chat.go | 4 +-- Request.go | 86 +++++++++++++++++++++++++++---------------------- ssefiber/sse.go | 2 +- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/Chat.go b/Chat.go index af73723..ec48210 100644 --- a/Chat.go +++ b/Chat.go @@ -196,7 +196,7 @@ func generateWelcomeChatHTML() string { NextMessages := []TemplateMessage{} nextMsg := TemplateMessage{ - Icon: "bouvai2", // Assuming Icon is a field you want to include from Message + Icon: "icons/bouvai2.png", // Assuming Icon is a field you want to include from Message Content: "
" + markdownToHTML(welcomeMessage) + loginButton, Hidden: false, // Assuming Hidden is a field you want to include from Message Id: "0", @@ -223,7 +223,7 @@ func generateEnterKeyChatHTML() string { NextMessages := []TemplateMessage{} nextMsg := TemplateMessage{ - Icon: "bouvai2", // Assuming Icon is a field you want to include from Message + Icon: "icons/bouvai2.png", // Assuming Icon is a field you want to include from Message Content: "
" + markdownToHTML(welcomeMessage), Hidden: false, // Assuming Hidden is a field you want to include from Message Id: "0", diff --git a/Request.go b/Request.go index 508459d..d9d92cf 100644 --- a/Request.go +++ b/Request.go @@ -147,54 +147,62 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error { select { case firstDone <- idx: // Generate the HTML content - out := "
" - out += "

" - out += templateMessage.Name - out += "

" - out += "
" - out += "
" - out += " " - out += templateMessage.Content - out += " " - out += "
" + outContent := "
" + outContent += "

" + outContent += templateMessage.Name + outContent += "

" + outContent += "
" + outContent += "
" + outContent += " " + outContent += templateMessage.Content + outContent += " " + outContent += "
" - go func() { + outBtn, err := selectBtnTmpl.Execute(map[string]interface{}{ + "message": templateMessage, + "ConversationAreaId": message.Area.Position, + }) + if err != nil { + fmt.Println("Error in modelSelecBtnTmpl.Execute: in HandleGenerateMultipleMessages 3") + log.Fatal(err) + } + outBtn = strings.ReplaceAll(outBtn, "\n", "") - // Send Content event - sseChanel.SendEvent( - "swapContent-"+fmt.Sprintf("%d", message.Area.Position), - out, - ) + outIcon := `User Image` - out, err := selectBtnTmpl.Execute(map[string]interface{}{ - "message": templateMessage, - "ConversationAreaId": message.Area.Position, - }) - if err != nil { - fmt.Println("Error in modelSelecBtnTmpl.Execute: in HandleGenerateMultipleMessages 3") - log.Fatal(err) - } + sseChanel.SendEvent( + "swapContent-"+fmt.Sprintf("%d", message.Area.Position), + outContent, + ) - // Replace newline characters to prevent premature termination - out = strings.ReplaceAll(out, "\n", "") + sseChanel.SendEvent( + "swapSelectionBtn-"+selectedLLMs[idx].ID.String(), + outBtn, + ) - // Send Content event - sseChanel.SendEvent( - "swapSelectionBtn-"+selectedLLMs[idx].ID.String(), - out, - ) - - // Send Icon Swap event - sseChanel.SendEvent( - "swapIcon-"+fmt.Sprintf("%d", message.Area.Position), - `User Image`, - ) - }() + sseChanel.SendEvent( + "swapIcon-"+fmt.Sprintf("%d", message.Area.Position), + outIcon, + ) default: + out, err := selectBtnTmpl.Execute(map[string]interface{}{ + "message": templateMessage, + "ConversationAreaId": message.Area.Position, + }) + if err != nil { + fmt.Println("Error in modelSelecBtnTmpl.Execute: in HandleGenerateMultipleMessages 3") + log.Fatal(err) + } + + // Replace newline characters to prevent premature termination + out = strings.ReplaceAll(out, "\n", "") + + fmt.Println("Sending event: swapSelectionBtn-" + templateMessage.ModelID) + // Send Content event sseChanel.SendEvent( "swapSelectionBtn-"+templateMessage.ModelID, - "New button", + out, ) } } diff --git a/ssefiber/sse.go b/ssefiber/sse.go index 6c214c0..d48a77a 100644 --- a/ssefiber/sse.go +++ b/ssefiber/sse.go @@ -120,7 +120,7 @@ func (app *FiberSSEApp) CreateChannel(name, base string) *FiberSSEChannel { newChannel := &FiberSSEChannel{ Name: name, Base: base, - Events: make(chan *FiberSSEEvent), + Events: make(chan *FiberSSEEvent, 100), ParentSSEApp: app, Handlers: make(map[string][]FiberSSEEventHandler), EventHandlers: make(map[string][]FiberSSEOnEventHandler),