From 92981e06e10170ab2881aac387c1e4eaee0d0649 Mon Sep 17 00:00:00 2001 From: Sertac Ozercan Date: Mon, 20 Mar 2023 16:32:18 +0000 Subject: [PATCH] confirmation ux changes Signed-off-by: Sertac Ozercan --- README.md | 30 ++++++++++++++++++++++-------- cmd/cli/root.go | 14 +++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 73fbd70..b7e3d9c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Kubectl OpenAI plugin ✨ -This project is a `kubectl` plugin to generate and apply Kubernetes manifests using OpenAI GPT-3. +This project is a `kubectl` plugin to generate and apply Kubernetes manifests using OpenAI GPT. -Main motivation for me is to avoid finding random manifests when dev/testing things. +My main motivation is to avoid finding and collecting random manifests when dev/testing things. ## Usage ### Prerequisites -`kubectl-ai` requires an [OpenAI API key](https://platform.openai.com/overview) or an [Azure OpenAI Service](https://aka.ms/azure-openai) API key and endpoint. Also, `kubectl` is required with a valid kubeconfig. +`kubectl-ai` requires an [OpenAI API key](https://platform.openai.com/overview) or an [Azure OpenAI Service](https://aka.ms/azure-openai) API key and endpoint, and a valid Kubernetes configuration. > I don't have a non-Azure OpenAI API key, non-Azure OpenAI API is not tested. @@ -35,7 +35,7 @@ If `AZURE_OPENAI_ENDPOINT` variable is set, then it will use the Azure OpenAI Se ### Flags and environment variables -- `--require-confirmation` flag or `REQUIRE_CONFIRMATION` environment varible can be set to prompt the user for confirmation before applying the manifest. Defaults to false. +- `--require-confirmation` flag or `REQUIRE_CONFIRMATION` environment varible can be set to prompt the user for confirmation before applying the manifest. Defaults to true. - `--temperature` flag or `TEMPERATURE` environment variable can be set between 0 and 1. Higher temperature will result in more creative completions. Lower temperature will result in more deterministic completions. Defaults to 0. @@ -68,6 +68,10 @@ spec: ports: - containerPort: 80 EOF +Use the arrow keys to navigate: ↓ ↑ → ← +? Would you like to apply this? [Apply/Don't Apply]: + ▸ Apply + Don't Apply ``` ```shell @@ -91,12 +95,18 @@ spec: - name: nginx image: nginx EOF +Use the arrow keys to navigate: ↓ ↑ → ← +? Would you like to apply this? [Apply/Don't Apply]: + ▸ Apply + Don't Apply ``` +> Please note that the plugin does not know the current state of the cluster (yet?), so it will always generate the full manifest. + Optional `--require-confirmation` flag: ```shell -$ kubectl ai "create a service with type LoadBalancer with selector as 'app:nginx'" --require-confirmation +$ kubectl ai "create a service with type LoadBalancer with selector as 'app:nginx'" --require-confirmation=false ✨ Attempting to apply the following manifest: apiVersion: v1 kind: Service @@ -110,9 +120,9 @@ spec: targetPort: 80 type: LoadBalancer Use the arrow keys to navigate: ↓ ↑ → ← -? Would you like to apply this? [Yes/No]: - ▸ Yes - No +? Would you like to apply this? [Apply/Don't Apply]: + ▸ Apply + Don't Apply ``` Multiple objects: @@ -135,6 +145,10 @@ spec: - name: nginx image: nginx:latest EOF +Use the arrow keys to navigate: ↓ ↑ → ← +? Would you like to apply this? [Apply/Don't Apply]: + ▸ Apply + Don't Apply ``` ## Acknowledgements and Credits diff --git a/cmd/cli/root.go b/cmd/cli/root.go index 9b0e8dc..579b4b3 100644 --- a/cmd/cli/root.go +++ b/cmd/cli/root.go @@ -22,7 +22,7 @@ var ( openAIDeploymentName = flag.String("openai-deployment-name", env.GetOr("OPENAI_DEPLOYMENT_NAME", env.String, "text-davinci-003"), "The deployment name used for the model in OpenAI service.") openAIAPIKey = flag.String("openai-api-key", env.GetOr("OPENAI_API_KEY", env.String, ""), "The API key for the OpenAI service. This is required.") azureOpenAIEndpoint = flag.String("azure-openai-endpoint", env.GetOr("AZURE_OPENAI_ENDPOINT", env.String, ""), "The endpoint for Azure OpenAI service. If provided, Azure OpenAI service will be used instead of OpenAI service.") - requireConfirmation = flag.Bool("require-confirmation", env.GetOr("REQUIRE_CONFIRMATION", strconv.ParseBool, false), "Whether to require confirmation before executing the command. Defaults to false.") + requireConfirmation = flag.Bool("require-confirmation", env.GetOr("REQUIRE_CONFIRMATION", strconv.ParseBool, true), "Whether to require confirmation before executing the command. Defaults to true.") temperature = flag.Float64("temperature", env.GetOr("TEMPERATURE", env.WithBitSize(strconv.ParseFloat, 64), 0.0), "The temperature to use for the model. Range is between 0 and 1. Set closer to 0 if your want output to be more deterministic but less creative. Defaults to 0.0.") ) @@ -87,7 +87,7 @@ func run(args []string) error { text := fmt.Sprintf("✨ Attempting to apply the following manifest: %s", completion) fmt.Println(text) - conf, err := yesNo() + conf, err := getUserConfirmation() if err != nil { return err } @@ -100,18 +100,18 @@ func run(args []string) error { return nil } -func yesNo() (bool, error) { - result := "Yes" +func getUserConfirmation() (bool, error) { + result := "Apply" var err error if *requireConfirmation { prompt := promptui.Select{ - Label: "Would you like to apply this? [Yes/No]", - Items: []string{"Yes", "No"}, + Label: "Would you like to apply this? [Apply/Don't Apply]", + Items: []string{"Apply", "Don't Apply"}, } _, result, err = prompt.Run() if err != nil { return false, err } } - return result == "Yes", nil + return result == "Apply", nil }