Compare commits

..

No commits in common. "59e78669c8ce4db3d621db5ed44ac386811690fc" and "f6ded3e20e91ec639e2effb922054d187628cc1d" have entirely different histories.

2 changed files with 16 additions and 36 deletions

View File

@ -2,7 +2,6 @@ package cli
import ( import (
"fmt" "fmt"
"os"
"slices" "slices"
"strings" "strings"
"time" "time"
@ -229,9 +228,9 @@ var lsCmd = &cobra.Command{
} }
var rmCmd = &cobra.Command{ var rmCmd = &cobra.Command{
Use: "rm <conversation>...", Use: "rm <conversation>",
Short: "Remove conversations", Short: "Remove a conversation",
Long: `Remove conversations by their short names.`, Long: `Removes a conversation by its short name.`,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
argCount := 1 argCount := 1
if err := cobra.MinimumNArgs(argCount)(cmd, args); err != nil { if err := cobra.MinimumNArgs(argCount)(cmd, args); err != nil {
@ -240,8 +239,7 @@ var rmCmd = &cobra.Command{
return nil return nil
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var toRemove []*Conversation shortName := args[0]
for _, shortName := range args {
conversation, err := store.ConversationByShortName(shortName) conversation, err := store.ConversationByShortName(shortName)
if err != nil { if err != nil {
Fatal("Could not search for conversation: %v\n", err) Fatal("Could not search for conversation: %v\n", err)
@ -249,35 +247,17 @@ var rmCmd = &cobra.Command{
if conversation.ID == 0 { if conversation.ID == 0 {
Fatal("Conversation not found with short name: %s\n", shortName) Fatal("Conversation not found with short name: %s\n", shortName)
} }
toRemove = append(toRemove, conversation) err = store.DeleteConversation(conversation)
}
var errors []error
for _, c := range toRemove {
err := store.DeleteConversation(c)
if err != nil { if err != nil {
errors = append(errors, fmt.Errorf("Could not remove conversation %s: %v", c.ShortName.String, err)) Fatal("Could not delete conversation: %v\n", err)
}
}
for _, err := range errors {
fmt.Fprintln(os.Stderr, err.Error())
}
if len(errors) > 0 {
os.Exit(1)
} }
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
compMode := cobra.ShellCompDirectiveNoFileComp compMode := cobra.ShellCompDirectiveNoFileComp
var completions []string if len(args) != 0 {
outer: for _, completion := range store.ConversationShortNameCompletions(toComplete) { return nil, compMode
parts := strings.Split(completion, "\t")
for _, arg := range args {
if parts[0] == arg {
continue outer
} }
} return store.ConversationShortNameCompletions(toComplete), compMode
completions = append(completions, completion)
}
return completions, compMode
}, },
} }

View File

@ -90,7 +90,7 @@ func CreateChatCompletion(model string, messages []Message, maxTokens int, repli
messages = append(append(messages, assistantReply), toolReplies...) messages = append(append(messages, assistantReply), toolReplies...)
// Recurse into CreateChatCompletion with the tool call replies added // Recurse into CreateChatCompletion with the tool call replies added
// to the original messages // to the original messages
return CreateChatCompletion(model, messages, maxTokens, replies) return CreateChatCompletion(model, append(messages, toolReplies...), maxTokens, replies)
} }
if replies != nil { if replies != nil {