From 3374080ba01e601c2c05aecc114b6c0a53b60f76 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 24 Jan 2025 09:24:37 +0300 Subject: Feat: chat preview --- README.md | 2 ++ tables.go | 26 +++++++++++++++++++++----- tui.go | 10 ++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7de7558..d8fecfa 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ - change temp, min-p and other params from tui; - DRY; - keybind to switch between openai and llamacpp endpoints; +- option to remove from chat history; +- in chat management table add preview of the last message; ### FIX: - bot responding (or hanging) blocks everything; + diff --git a/tables.go b/tables.go index 16dedda..e12a690 100644 --- a/tables.go +++ b/tables.go @@ -6,32 +6,48 @@ import ( "path" "time" + "elefant/models" "elefant/rag" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) -func makeChatTable(chatList []string) *tview.Table { +func makeChatTable(chatMap map[string]models.Chat) *tview.Table { actions := []string{"load", "rename", "delete"} - rows, cols := len(chatList), len(actions)+1 + chatList := make([]string, len(chatMap)) + i := 0 + for name := range chatMap { + chatList[i] = name + i++ + } + rows, cols := len(chatMap), len(actions)+2 chatActTable := tview.NewTable(). SetBorders(true) + // for chatName, chat := range chatMap { for r := 0; r < rows; r++ { + // r := 0 for c := 0; c < cols; c++ { color := tcell.ColorWhite - if c < 1 { + switch c { + case 0: chatActTable.SetCell(r, c, tview.NewTableCell(chatList[r]). SetTextColor(color). SetAlign(tview.AlignCenter)) - } else { + case 1: chatActTable.SetCell(r, c, - tview.NewTableCell(actions[c-1]). + tview.NewTableCell(chatMap[chatList[r]].Msgs[len(chatMap[chatList[r]].Msgs)-30:]). + SetTextColor(color). + SetAlign(tview.AlignCenter)) + default: + chatActTable.SetCell(r, c, + tview.NewTableCell(actions[c-2]). SetTextColor(color). SetAlign(tview.AlignCenter)) } } + // r++ } chatActTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) { if key == tcell.KeyEsc || key == tcell.KeyF1 { diff --git a/tui.go b/tui.go index cf0a312..7645a4f 100644 --- a/tui.go +++ b/tui.go @@ -340,11 +340,13 @@ func init() { logger.Error("failed to load chat history", "error", err) return nil } - nameList := make([]string, len(chatList)) - for i, chat := range chatList { - nameList[i] = chat.Name + chatMap := make(map[string]models.Chat) + // nameList := make([]string, len(chatList)) + for _, chat := range chatList { + // nameList[i] = chat.Name + chatMap[chat.Name] = chat } - chatActTable := makeChatTable(nameList) + chatActTable := makeChatTable(chatMap) pages.AddPage(historyPage, chatActTable, true, true) colorText() updateStatusLine() -- cgit v1.2.3