diff options
| -rw-r--r-- | helpfuncs.go | 10 | ||||
| -rw-r--r-- | tables.go | 9 | ||||
| -rw-r--r-- | tools.go | 3 |
3 files changed, 17 insertions, 5 deletions
diff --git a/helpfuncs.go b/helpfuncs.go index 73f8fb0..4a3719c 100644 --- a/helpfuncs.go +++ b/helpfuncs.go @@ -8,6 +8,7 @@ import ( "os" "path" "strings" + "time" "unicode" "math/rand/v2" @@ -111,10 +112,11 @@ func startNewChat() { chatBody.Messages = chatBody.Messages[:2] textView.SetText(chatToText(cfg.ShowSys)) newChat := &models.Chat{ - ID: id + 1, - Name: fmt.Sprintf("%d_%s", id+1, cfg.AssistantRole), - Msgs: string(defaultStarterBytes), - Agent: cfg.AssistantRole, + ID: id + 1, + Name: fmt.Sprintf("%d_%s", id+1, cfg.AssistantRole), + Msgs: string(defaultStarterBytes), + Agent: cfg.AssistantRole, + CreatedAt: time.Now(), } activeChatName = newChat.Name chatMap[newChat.Name] = newChat @@ -23,6 +23,15 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table { chatList[i] = name i++ } + // Sort chatList by UpdatedAt field in descending order (most recent first) + for i := 0; i < len(chatList)-1; i++ { + for j := i + 1; j < len(chatList); j++ { + if chatMap[chatList[i]].UpdatedAt.Before(chatMap[chatList[j]].UpdatedAt) { + // Swap chatList[i] and chatList[j] + chatList[i], chatList[j] = chatList[j], chatList[i] + } + } + } // Add 1 extra row for header rows, cols := len(chatMap)+1, len(actions)+4 // +2 for name, +2 for timestamps chatActTable := tview.NewTable(). @@ -24,7 +24,7 @@ var ( starRE = regexp.MustCompile(`(\*.*?\*)`) thinkRE = regexp.MustCompile(`(<think>\s*([\s\S]*?)</think>)`) codeBlockRE = regexp.MustCompile(`(?s)\x60{3}(?:.*?)\n(.*?)\n\s*\x60{3}\s*`) - singleBacktickRE = regexp.MustCompile(`\x60([^\x60]*)\x60`) + singleBacktickRE = regexp.MustCompile(`\x60([^\x60]*)\x60`) roleRE = regexp.MustCompile(`^(\w+):`) rpDefenitionSysMsg = ` For this roleplay immersion is at most importance. @@ -330,6 +330,7 @@ func memorise(args map[string]string) []byte { Topic: args["topic"], Mind: args["data"], UpdatedAt: time.Now(), + CreatedAt: time.Now(), } if _, err := store.Memorise(memory); err != nil { logger.Error("failed to save memory", "err", err, "memoory", memory) |
