Feat: chat preview

This commit is contained in:
Grail Finder
2025-01-24 09:24:37 +03:00
parent 75f51c1a19
commit 3374080ba0
3 changed files with 29 additions and 9 deletions

View File

@@ -41,6 +41,8 @@
- change temp, min-p and other params from tui; - change temp, min-p and other params from tui;
- DRY; - DRY;
- keybind to switch between openai and llamacpp endpoints; - keybind to switch between openai and llamacpp endpoints;
- option to remove <thinking> from chat history;
- in chat management table add preview of the last message;
### FIX: ### FIX:
- bot responding (or hanging) blocks everything; + - bot responding (or hanging) blocks everything; +

View File

@@ -6,32 +6,48 @@ import (
"path" "path"
"time" "time"
"elefant/models"
"elefant/rag" "elefant/rag"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/rivo/tview" "github.com/rivo/tview"
) )
func makeChatTable(chatList []string) *tview.Table { func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
actions := []string{"load", "rename", "delete"} 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(). chatActTable := tview.NewTable().
SetBorders(true) SetBorders(true)
// for chatName, chat := range chatMap {
for r := 0; r < rows; r++ { for r := 0; r < rows; r++ {
// r := 0
for c := 0; c < cols; c++ { for c := 0; c < cols; c++ {
color := tcell.ColorWhite color := tcell.ColorWhite
if c < 1 { switch c {
case 0:
chatActTable.SetCell(r, c, chatActTable.SetCell(r, c,
tview.NewTableCell(chatList[r]). tview.NewTableCell(chatList[r]).
SetTextColor(color). SetTextColor(color).
SetAlign(tview.AlignCenter)) SetAlign(tview.AlignCenter))
} else { case 1:
chatActTable.SetCell(r, c, 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). SetTextColor(color).
SetAlign(tview.AlignCenter)) SetAlign(tview.AlignCenter))
} }
} }
// r++
} }
chatActTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) { chatActTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEsc || key == tcell.KeyF1 { if key == tcell.KeyEsc || key == tcell.KeyF1 {

10
tui.go
View File

@@ -340,11 +340,13 @@ func init() {
logger.Error("failed to load chat history", "error", err) logger.Error("failed to load chat history", "error", err)
return nil return nil
} }
nameList := make([]string, len(chatList)) chatMap := make(map[string]models.Chat)
for i, chat := range chatList { // nameList := make([]string, len(chatList))
nameList[i] = chat.Name for _, chat := range chatList {
// nameList[i] = chat.Name
chatMap[chat.Name] = chat
} }
chatActTable := makeChatTable(nameList) chatActTable := makeChatTable(chatMap)
pages.AddPage(historyPage, chatActTable, true, true) pages.AddPage(historyPage, chatActTable, true, true)
colorText() colorText()
updateStatusLine() updateStatusLine()