-
Notifications
You must be signed in to change notification settings - Fork 4
# Summary #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+548
−140
Merged
# Summary #49
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,217 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/Wangggym/quick-workflow/internal/ui" | ||
| "github.com/Wangggym/quick-workflow/pkg/config" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var aiCmd = &cobra.Command{ | ||
| Use: "ai", | ||
| Short: "Manage AI provider settings", | ||
| Long: `View and switch between AI providers (Cerebras, DeepSeek, OpenAI).`, | ||
| Run: runAIStatus, | ||
| } | ||
|
|
||
| var aiSwitchCmd = &cobra.Command{ | ||
| Use: "switch [provider]", | ||
| Short: "Switch AI provider", | ||
| Long: `Switch to a specific AI provider. | ||
| Available providers: auto, cerebras, deepseek, openai | ||
|
|
||
| Examples: | ||
| qkflow ai switch cerebras # Switch to Cerebras | ||
| qkflow ai switch deepseek # Switch to DeepSeek | ||
| qkflow ai switch openai # Switch to OpenAI | ||
| qkflow ai switch auto # Auto-select best available`, | ||
| Args: cobra.ExactArgs(1), | ||
| Run: runAISwitch, | ||
| } | ||
|
|
||
| var aiSetCmd = &cobra.Command{ | ||
| Use: "set [key] [value]", | ||
| Short: "Set AI configuration", | ||
| Long: `Set AI provider configuration values. | ||
|
|
||
| Examples: | ||
| qkflow ai set cerebras-key YOUR_API_KEY | ||
| qkflow ai set cerebras-url https://api.cerebras.ai/v1 | ||
| qkflow ai set deepseek-key YOUR_API_KEY | ||
| qkflow ai set openai-key YOUR_API_KEY`, | ||
| Args: cobra.ExactArgs(2), | ||
| Run: runAISet, | ||
| } | ||
|
|
||
| func init() { | ||
| aiCmd.AddCommand(aiSwitchCmd) | ||
| aiCmd.AddCommand(aiSetCmd) | ||
| } | ||
|
|
||
| func runAIStatus(cmd *cobra.Command, args []string) { | ||
| cfg := config.Get() | ||
| if cfg == nil { | ||
| ui.Error("No configuration found. Run 'qkflow init' first.") | ||
| return | ||
| } | ||
|
|
||
| fmt.Println("🤖 AI Provider Status:") | ||
| fmt.Println() | ||
|
|
||
| // Current provider | ||
| provider := cfg.AIProvider | ||
| if provider == "" { | ||
| provider = "auto" | ||
| } | ||
| fmt.Printf(" Current Mode: %s\n", provider) | ||
| fmt.Println() | ||
|
|
||
| // Available providers | ||
| fmt.Println(" Available Providers:") | ||
|
|
||
| // Cerebras | ||
| if cfg.CerebrasKey != "" { | ||
| if provider == "cerebras" || (provider == "auto" && cfg.CerebrasKey != "") { | ||
| fmt.Printf(" ✅ Cerebras: %s (Active)\n", maskToken(cfg.CerebrasKey)) | ||
| } else { | ||
| fmt.Printf(" ⚪ Cerebras: %s\n", maskToken(cfg.CerebrasKey)) | ||
| } | ||
| if cfg.CerebrasURL != "" { | ||
| fmt.Printf(" URL: %s\n", cfg.CerebrasURL) | ||
| } | ||
| } else { | ||
| fmt.Printf(" ❌ Cerebras: not configured\n") | ||
| } | ||
|
|
||
| // DeepSeek | ||
| if cfg.DeepSeekKey != "" { | ||
| isActive := provider == "deepseek" || (provider == "auto" && cfg.CerebrasKey == "" && cfg.DeepSeekKey != "") | ||
| if isActive { | ||
| fmt.Printf(" ✅ DeepSeek: %s (Active)\n", maskToken(cfg.DeepSeekKey)) | ||
| } else { | ||
| fmt.Printf(" ⚪ DeepSeek: %s\n", maskToken(cfg.DeepSeekKey)) | ||
| } | ||
| } else { | ||
| fmt.Printf(" ❌ DeepSeek: not configured\n") | ||
| } | ||
|
|
||
| // OpenAI | ||
| if cfg.OpenAIKey != "" { | ||
| isActive := provider == "openai" || (provider == "auto" && cfg.CerebrasKey == "" && cfg.DeepSeekKey == "" && cfg.OpenAIKey != "") | ||
| if isActive { | ||
| fmt.Printf(" ✅ OpenAI: %s (Active)\n", maskToken(cfg.OpenAIKey)) | ||
| } else { | ||
| fmt.Printf(" ⚪ OpenAI: %s\n", maskToken(cfg.OpenAIKey)) | ||
| } | ||
| if cfg.OpenAIProxyURL != "" { | ||
| fmt.Printf(" Proxy: %s\n", cfg.OpenAIProxyURL) | ||
| } | ||
| } else { | ||
| fmt.Printf(" ❌ OpenAI: not configured\n") | ||
| } | ||
|
|
||
| fmt.Println() | ||
| fmt.Println(" Commands:") | ||
| fmt.Println(" qkflow ai switch <provider> - Switch AI provider (auto/cerebras/deepseek/openai)") | ||
| fmt.Println(" qkflow ai set <key> <value> - Set API key or URL") | ||
| } | ||
|
|
||
| func runAISwitch(cmd *cobra.Command, args []string) { | ||
| provider := args[0] | ||
|
|
||
| // Validate provider | ||
| validProviders := map[string]bool{ | ||
| "auto": true, | ||
| "cerebras": true, | ||
| "deepseek": true, | ||
| "openai": true, | ||
| } | ||
|
|
||
| if !validProviders[provider] { | ||
| ui.Error(fmt.Sprintf("Invalid provider: %s. Valid options: auto, cerebras, deepseek, openai", provider)) | ||
| return | ||
| } | ||
|
|
||
| cfg := config.Get() | ||
| if cfg == nil { | ||
| ui.Error("No configuration found. Run 'qkflow init' first.") | ||
| return | ||
| } | ||
|
|
||
| // Check if the selected provider has a key configured | ||
| switch provider { | ||
| case "cerebras": | ||
| if cfg.CerebrasKey == "" { | ||
| ui.Warning("Cerebras API key not configured. Set it with: qkflow ai set cerebras-key YOUR_KEY") | ||
| } | ||
| case "deepseek": | ||
| if cfg.DeepSeekKey == "" { | ||
| ui.Warning("DeepSeek API key not configured. Set it with: qkflow ai set deepseek-key YOUR_KEY") | ||
| } | ||
| case "openai": | ||
| if cfg.OpenAIKey == "" { | ||
| ui.Warning("OpenAI API key not configured. Set it with: qkflow ai set openai-key YOUR_KEY") | ||
| } | ||
| } | ||
|
|
||
| cfg.AIProvider = provider | ||
|
|
||
| if err := config.Save(cfg); err != nil { | ||
| ui.Error(fmt.Sprintf("Failed to save configuration: %v", err)) | ||
| return | ||
| } | ||
|
|
||
| ui.Success(fmt.Sprintf("Switched AI provider to: %s", provider)) | ||
|
|
||
| // Show which provider will be active | ||
| if provider == "auto" { | ||
| if cfg.CerebrasKey != "" { | ||
| ui.Info("Auto mode will use: Cerebras (highest priority)") | ||
| } else if cfg.DeepSeekKey != "" { | ||
| ui.Info("Auto mode will use: DeepSeek") | ||
| } else if cfg.OpenAIKey != "" { | ||
| ui.Info("Auto mode will use: OpenAI") | ||
| } else { | ||
| ui.Warning("No AI keys configured. Run 'qkflow ai set' to add one.") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func runAISet(cmd *cobra.Command, args []string) { | ||
| key := args[0] | ||
| value := args[1] | ||
|
|
||
| cfg := config.Get() | ||
| if cfg == nil { | ||
| ui.Error("No configuration found. Run 'qkflow init' first.") | ||
| return | ||
| } | ||
|
|
||
| switch key { | ||
| case "cerebras-key": | ||
| cfg.CerebrasKey = value | ||
| ui.Success("Cerebras API key set successfully") | ||
| case "cerebras-url": | ||
| cfg.CerebrasURL = value | ||
| ui.Success(fmt.Sprintf("Cerebras URL set to: %s", value)) | ||
| case "deepseek-key": | ||
| cfg.DeepSeekKey = value | ||
| ui.Success("DeepSeek API key set successfully") | ||
| case "openai-key": | ||
| cfg.OpenAIKey = value | ||
| ui.Success("OpenAI API key set successfully") | ||
| case "openai-proxy-url": | ||
| cfg.OpenAIProxyURL = value | ||
| ui.Success(fmt.Sprintf("OpenAI Proxy URL set to: %s", value)) | ||
| default: | ||
| ui.Error(fmt.Sprintf("Unknown key: %s", key)) | ||
| fmt.Println("Valid keys: cerebras-key, cerebras-url, deepseek-key, openai-key, openai-proxy-url") | ||
| return | ||
| } | ||
|
|
||
| if err := config.Save(cfg); err != nil { | ||
| ui.Error(fmt.Sprintf("Failed to save configuration: %v", err)) | ||
| return | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Success message displayed before config save completes
Low Severity
The
runAISetfunction displays success messages (e.g., "Cerebras API key set successfully") in the switch cases beforeconfig.Save(cfg)is called. If the save operation fails on line 213, users will see both the success message and the subsequent error message, creating a misleading user experience.