diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go index 87ff6b6..7bb5dfe 100644 --- a/cmd/auth/auth.go +++ b/cmd/auth/auth.go @@ -24,9 +24,13 @@ var AuthCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { backendType := viper.GetString("backend_type") - if backendType == "" && backend == "" { - color.Red("No backend set. Please run k8sgpt auth") - os.Exit(1) + if backendType == "" { + // Set the default backend + viper.Set("backend_type", "openai") + if err := viper.WriteConfig(); err != nil { + color.Red("Error writing config file: %s", err.Error()) + os.Exit(1) + } } // override the default backend if a flag is provided if backend != "" { diff --git a/pkg/ai/ai.go b/pkg/ai/ai.go index 1c42b37..ca14050 100644 --- a/pkg/ai/ai.go +++ b/pkg/ai/ai.go @@ -13,10 +13,10 @@ type OpenAIClient struct { func (c *OpenAIClient) Configure(token string) error { client := openai.NewClient(token) - if client == nil { return errors.New("error creating OpenAI client") } + c.client = client return nil }