-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting of AI config using ai command (#272)
* Allow setting of AI config using ai command * We're going through changes * Add support for multiple OpenAI tokens * Run gofumft and linter * Revert "Add support for multiple OpenAI tokens" This reverts commit 2f33aef. --------- Co-authored-by: Jarryd Tilbrook <jarryd@buildkite.com>
- Loading branch information
1 parent
16f0d73
commit ff63543
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
openai_token: jumanji | ||
selected_org: buildkite-org | ||
organizations: | ||
buildkite-test: | ||
api_token: test-token-abcd | ||
api_token: test-token-abcd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package add | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdAIAdd(f *factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add", | ||
Args: cobra.NoArgs, | ||
Short: "Add an OpenAI token.", | ||
Long: "Add an OpenAI token for use with CLI AI tooling", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return ConfigureRun(f) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func ConfigureRun(f *factory.Factory) error { | ||
qs := []*survey.Question{ | ||
{ | ||
Name: "token", | ||
Prompt: &survey.Password{Message: "Paste your OpenAI token:"}, | ||
Validate: survey.Required, | ||
}, | ||
} | ||
answers := struct{ Token string }{} | ||
|
||
err := survey.Ask(qs, &answers) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = f.Config.SetOpenAIToken(answers.Token) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ai | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdAI(f *factory.Factory) *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "ai <command>", | ||
Short: "Manage AI integration.", | ||
Long: "Work with Buildkite AI.", | ||
Example: heredoc.Doc(` | ||
# To configure your AI token | ||
$ bk ai configure | ||
`), | ||
} | ||
|
||
cmd.AddCommand(NewCmdAIConfigure(f)) | ||
|
||
return &cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ai | ||
|
||
import ( | ||
"errors" | ||
|
||
addCmd "github.com/buildkite/cli/v3/pkg/cmd/ai/add" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdAIConfigure(f *factory.Factory) *cobra.Command { | ||
var force bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "configure", | ||
Aliases: []string{"config"}, | ||
Args: cobra.NoArgs, | ||
Short: "Configure OpenAI token.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// if the token already exists and --force is not used | ||
if !force && f.Config.GetOpenAIToken() != "" { | ||
return errors.New("OpenAI token already configured. You must use --force.") | ||
} | ||
|
||
return addCmd.ConfigureRun(f) | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&force, "force", false, "Force setting a new token") | ||
|
||
cmd.AddCommand(addCmd.NewCmdAIAdd(f)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters