From f6e55f6bff68afdb95c5f7d4805c1a3ad12de46a Mon Sep 17 00:00:00 2001 From: Matt Low Date: Mon, 20 May 2024 16:07:38 +0000 Subject: [PATCH] `lmcli chat`: check that conversation exists --- pkg/cmd/chat.go | 8 +++++++- pkg/cmd/util/util.go | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/chat.go b/pkg/cmd/chat.go index f86c98d..527529d 100644 --- a/pkg/cmd/chat.go +++ b/pkg/cmd/chat.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" + cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util" "git.mlow.ca/mlow/lmcli/pkg/lmcli" "git.mlow.ca/mlow/lmcli/pkg/tui" "github.com/spf13/cobra" @@ -14,11 +15,16 @@ func ChatCmd(ctx *lmcli.Context) *cobra.Command { Short: "Open the chat interface", Long: `Open the chat interface, optionally on a given conversation.`, RunE: func(cmd *cobra.Command, args []string) error { - // TODO: implement jump-to-conversation logic shortname := "" if len(args) == 1 { shortname = args[0] } + if shortname != ""{ + _, err := cmdutil.LookupConversationE(ctx, shortname) + if err != nil { + return err + } + } err := tui.Launch(ctx, shortname) if err != nil { return fmt.Errorf("Error fetching LLM response: %v", err) diff --git a/pkg/cmd/util/util.go b/pkg/cmd/util/util.go index 4f2390a..5f325ba 100644 --- a/pkg/cmd/util/util.go +++ b/pkg/cmd/util/util.go @@ -57,7 +57,7 @@ func LookupConversation(ctx *lmcli.Context, shortName string) *model.Conversatio lmcli.Fatal("Could not lookup conversation: %v\n", err) } if c.ID == 0 { - lmcli.Fatal("Conversation not found with short name: %s\n", shortName) + lmcli.Fatal("Conversation not found: %s\n", shortName) } return c } @@ -68,7 +68,7 @@ func LookupConversationE(ctx *lmcli.Context, shortName string) (*model.Conversat return nil, fmt.Errorf("Could not lookup conversation: %v", err) } if c.ID == 0 { - return nil, fmt.Errorf("Conversation not found with short name: %s", shortName) + return nil, fmt.Errorf("Conversation not found: %s", shortName) } return c, nil }