Add limit to number of conversations shown by default by lmcli ls

This commit is contained in:
Matt Low 2024-01-03 07:20:46 +00:00
parent 1184f9aaae
commit b3913d0027

View File

@ -17,6 +17,11 @@ var (
systemPromptFile string
)
const (
// Limit to number of conversations shown with `ls`, without --all
LS_LIMIT int = 25
)
func init() {
inputCmds := []*cobra.Command{newCmd, promptCmd, replyCmd, retryCmd, continueCmd, editCmd}
for _, cmd := range inputCmds {
@ -27,6 +32,7 @@ func init() {
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
}
lsCmd.Flags().Bool("all", false, fmt.Sprintf("Show all conversations, by default only the last %d are shown", LS_LIMIT))
renameCmd.Flags().Bool("generate", false, "Generate a conversation title")
rootCmd.AddCommand(
@ -203,6 +209,8 @@ var lsCmd = &cobra.Command{
}
categorized := map[string][]ConversationLine{}
all, _ := cmd.Flags().GetBool("all")
for _, conversation := range conversations {
lastMessage, err := store.LastMessage(&conversation)
if lastMessage == nil || err != nil {
@ -232,17 +240,27 @@ var lsCmd = &cobra.Command{
)
}
var conversationsPrinted int
outer:
for _, category := range categories {
conversations, ok := categorized[category]
conversations, ok := categorized[category.name]
if !ok {
continue
}
slices.SortFunc(conversations, func(a, b ConversationLine) int {
return int(a.timeSinceReply - b.timeSinceReply)
})
fmt.Printf("%s:\n", category)
fmt.Printf("%s:\n", category.name)
for _, conv := range conversations {
if conversationsPrinted >= LS_LIMIT && !all {
fmt.Printf("%d remaining message(s), use --all to view.\n", len(conversations)-conversationsPrinted)
break outer
}
fmt.Printf(" %s\n", conv.formatted)
conversationsPrinted++
}
}
},