Add 'prompt' command

This commit is contained in:
Matt Low 2023-11-03 02:44:16 +00:00
parent 5fa1255493
commit fd667a1f47
1 changed files with 24 additions and 1 deletions

25
main.go
View File

@ -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)