Skip to content

Commit

Permalink
fix: Resolve comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Aris Boutselis <aris.boutselis@senseon.io>
  • Loading branch information
Aris Boutselis committed Apr 26, 2023
1 parent 4430854 commit 8655e83
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
5 changes: 2 additions & 3 deletions cmd/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ var AuthCmd = &cobra.Command{
}

// check if backend is not empty and a valid value
backends := util.Backends()
if backend == "" || !util.ValidBackend(backends, backend) {
color.Red("Error: Backend AI cannot be empty and accepted values are '%v'", strings.Join(backends, ", "))
if backend == "" || !util.ValidBackend(ai.Backends, backend) {
color.Red("Error: Backend AI cannot be empty and accepted values are '%v'", strings.Join(ai.Backends, ", "))
os.Exit(1)
}

Expand Down
32 changes: 21 additions & 11 deletions pkg/ai/iai.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ import (
"github.com/k8sgpt-ai/k8sgpt/pkg/cache"
)

var (
clients = []IAI{
&OpenAIClient{},
&AzureAIClient{},
&LocalAIClient{},
&NoOpAIClient{},
}
Backends = []string{
"openai",
"localai",
"azureopenai",
"noopai",
}
)

type IAI interface {
Configure(config IAIConfig, language string) error
GetCompletion(ctx context.Context, prompt string) (string, error)
Expand All @@ -34,18 +49,13 @@ type IAIConfig interface {
}

func NewClient(provider string) IAI {
switch provider {
case "openai":
return &OpenAIClient{}
case "azureopenai":
return &AzureAIClient{}
case "localai":
return &LocalAIClient{}
case "noopai":
return &NoOpAIClient{}
default:
return &OpenAIClient{}
for _, c := range clients {
if provider == c.GetName() {
return c
}
}
// default client
return &OpenAIClient{}
}

type AIConfiguration struct {
Expand Down
4 changes: 0 additions & 4 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ func EnsureDirExists(dir string) error {
return err
}

func Backends() []string {
return []string{"openai", "localai", "azureopenai", "noopai"}
}

func ValidBackend(validBackends []string, backend string) bool {
for _, b := range validBackends {
if b == backend {
Expand Down

0 comments on commit 8655e83

Please sign in to comment.