From fd667a1f471e46ac98fdb2e4fa39552c7d3deb7b Mon Sep 17 00:00:00 2001 From: Matt Low Date: Fri, 3 Nov 2023 02:44:16 +0000 Subject: [PATCH] Add 'prompt' command --- main.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index af57fb3..bd5d550 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "strings" "github.com/spf13/cobra" ) @@ -117,8 +118,30 @@ var newCmd = &cobra.Command{ }, } +var promptCmd = &cobra.Command{ + Use: "prompt", + Short: "Do a one-shot prompt", + Long: `Prompt the Large Language Model and get a response.`, + Run: func(cmd *cobra.Command, args []string) { + messages := []Message{ + { + OriginalContent: strings.Join(args, " "), + Role: "user", + }, + } + + err := CreateChatCompletionStream("You are a helpful assistant.", messages, os.Stdout) + if err != nil { + fmt.Fprintf(os.Stderr, "An error occured: %v\n", err) + os.Exit(1) + } + + fmt.Println() + }, +} + func main() { - rootCmd.AddCommand(newCmd) // Add other commands similarly + rootCmd.AddCommand(newCmd, promptCmd) if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1)