Add 'prompt' command
This commit is contained in:
parent
5fa1255493
commit
fd667a1f47
25
main.go
25
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)
|
||||
|
Loading…
Reference in New Issue
Block a user