File tree 4 files changed +26
-11
lines changed
4 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -22,9 +22,11 @@ var chatCmd = &cobra.Command{
22
22
Use : "chat" ,
23
23
Short : "Open ended chat with OpenAI" ,
24
24
Long : `` ,
25
- Args : cobra .ExactArgs (1 ), // Expect exactly one argument
25
+ Args : func (cmd * cobra.Command , args []string ) error {
26
+ return checkArgs (args )
27
+ },
26
28
Run : func (cmd * cobra.Command , args []string ) {
27
- prompt := args [ 0 ]
29
+
28
30
var err error
29
31
if convo {
30
32
for {
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ var imageCmd = &cobra.Command{
25
25
Use : "image" ,
26
26
Short : "Generate an image from a prompt" ,
27
27
Long : `` ,
28
+ Args : func (cmd * cobra.Command , args []string ) error {
29
+ return checkArgs (args )
30
+ },
28
31
Run : func (cmd * cobra.Command , args []string ) {
29
32
createImage (prompt , imageFile )
30
33
},
Original file line number Diff line number Diff line change @@ -41,15 +41,7 @@ var rootCmd = &cobra.Command{
41
41
Or whatever else you can think of. 🤔
42
42
` ,
43
43
Args : func (cmd * cobra.Command , args []string ) error {
44
- if convo && len (args ) == 0 {
45
- // When --convo is used, no args are required
46
- return nil
47
- }
48
- // Otherwise, exactly one arg must be provided
49
- if len (args ) != 1 {
50
- return fmt .Errorf ("Prompt Required" )
51
- }
52
- return nil
44
+ return checkArgs (args )
53
45
},
54
46
Run : func (cmd * cobra.Command , args []string ) {
55
47
var prompt string
@@ -61,6 +53,19 @@ var rootCmd = &cobra.Command{
61
53
},
62
54
}
63
55
56
+ func checkArgs (args []string ) error {
57
+ if convo && len (args ) == 0 {
58
+ // When --convo is used, no args are required
59
+ return nil
60
+ }
61
+ // Otherwise, exactly one arg must be provided
62
+ if len (args ) != 1 {
63
+ return fmt .Errorf ("Prompt Required" )
64
+ }
65
+ prompt = args [0 ]
66
+ return nil
67
+ }
68
+
64
69
// Execute adds all child commands to the root command and sets flags appropriately.
65
70
// This is called by main.main(). It only needs to happen once to the rootCmd.
66
71
func Execute () {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ package cmd
5
5
6
6
import (
7
7
"bytes"
8
+ "fmt"
8
9
"io"
9
10
"os"
10
11
@@ -21,6 +22,9 @@ var ttsCmd = &cobra.Command{
21
22
Long : `OpenAI Text to Speech API - TTS
22
23
You can use the TTS API to generate audio from text.
23
24
` ,
25
+ Args : func (cmd * cobra.Command , args []string ) error {
26
+ return checkArgs (args )
27
+ },
24
28
Run : func (cmd * cobra.Command , args []string ) {
25
29
audio := tts (prompt )
26
30
if audio != nil {
@@ -36,6 +40,7 @@ func init() {
36
40
37
41
func tts (text string ) []byte {
38
42
ai .Voice = voice
43
+ fmt .Println ("Generating audio..." , text )
39
44
audioData , err := ai .TTS (text )
40
45
catchErr (err , "fatal" )
41
46
if audioFile != "" {
You can’t perform that action at this time.
0 commit comments