Skip to content

Commit

Permalink
fix: disable adding multiple openai provider (#1191)
Browse files Browse the repository at this point in the history
Signed-off-by: Guangya Liu <gyliu@ibm.com>
Co-authored-by: Matthis <matthish29@gmail.com>
  • Loading branch information
gyliu513 and matthisholleville authored Aug 20, 2024
1 parent d702209 commit 644581f
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions cmd/auth/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ var addCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {

// get ai configuration
err := viper.UnmarshalKey("ai", &configAI)
if err != nil {
color.Red("Error: %v", err)
os.Exit(1)
}

// search for provider with same name
providerIndex := -1
for i, provider := range configAI.Providers {
if backend == provider.Name {
providerIndex = i
break
}
}

validBackend := func(validBackends []string, backend string) bool {
for _, b := range validBackends {
if b == backend {
Expand All @@ -90,6 +74,28 @@ var addCmd = &cobra.Command{
}
}

// get ai configuration
err := viper.UnmarshalKey("ai", &configAI)
if err != nil {
color.Red("Error: %v", err)
os.Exit(1)
}

// search for provider with same name
providerIndex := -1
for i, provider := range configAI.Providers {
if backend == provider.Name {
providerIndex = i
break
}
}

if providerIndex != -1 {
// provider with same name exists, update provider info
color.Yellow("Provider with same name already exists.")
os.Exit(1)
}

// check if model is not empty
if model == "" {
model = defaultModel
Expand Down Expand Up @@ -146,9 +152,6 @@ var addCmd = &cobra.Command{
os.Exit(1)
}
color.Green("%s added to the AI backend provider list", backend)
} else {
// provider with same name exists, update provider info
color.Yellow("Provider with same name already exists.")
}
},
}
Expand Down

0 comments on commit 644581f

Please sign in to comment.