lmcli chat: check that conversation exists

This commit is contained in:
Matt Low 2024-05-20 16:07:38 +00:00
parent dc1edf8c3e
commit f6e55f6bff
2 changed files with 9 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package cmd
import ( import (
"fmt" "fmt"
cmdutil "git.mlow.ca/mlow/lmcli/pkg/cmd/util"
"git.mlow.ca/mlow/lmcli/pkg/lmcli" "git.mlow.ca/mlow/lmcli/pkg/lmcli"
"git.mlow.ca/mlow/lmcli/pkg/tui" "git.mlow.ca/mlow/lmcli/pkg/tui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -14,11 +15,16 @@ func ChatCmd(ctx *lmcli.Context) *cobra.Command {
Short: "Open the chat interface", Short: "Open the chat interface",
Long: `Open the chat interface, optionally on a given conversation.`, Long: `Open the chat interface, optionally on a given conversation.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// TODO: implement jump-to-conversation logic
shortname := "" shortname := ""
if len(args) == 1 { if len(args) == 1 {
shortname = args[0] shortname = args[0]
} }
if shortname != ""{
_, err := cmdutil.LookupConversationE(ctx, shortname)
if err != nil {
return err
}
}
err := tui.Launch(ctx, shortname) err := tui.Launch(ctx, shortname)
if err != nil { if err != nil {
return fmt.Errorf("Error fetching LLM response: %v", err) return fmt.Errorf("Error fetching LLM response: %v", err)

View File

@ -57,7 +57,7 @@ func LookupConversation(ctx *lmcli.Context, shortName string) *model.Conversatio
lmcli.Fatal("Could not lookup conversation: %v\n", err) lmcli.Fatal("Could not lookup conversation: %v\n", err)
} }
if c.ID == 0 { 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 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) return nil, fmt.Errorf("Could not lookup conversation: %v", err)
} }
if c.ID == 0 { 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 return c, nil
} }