Class: Legion::TTY::Components::WizardPrompt
- Inherits:
-
Object
- Object
- Legion::TTY::Components::WizardPrompt
- Defined in:
- lib/legion/tty/components/wizard_prompt.rb
Constant Summary collapse
- PROVIDERS =
{ 'Claude (Anthropic)' => 'claude', 'OpenAI' => 'openai', 'Gemini (Google)' => 'gemini', 'Azure OpenAI' => 'azure', 'AWS Bedrock' => 'bedrock', 'Local (Ollama/LM Studio)' => 'local', 'Skip for now' => nil }.freeze
Instance Method Summary collapse
- #ask_api_key(provider:) ⇒ Object
- #ask_name ⇒ Object
- #ask_name_with_default(default) ⇒ Object
- #ask_secret(question) ⇒ Object
- #ask_with_default(question, default) ⇒ Object
-
#confirm(question) ⇒ Object
rubocop:disable Naming/PredicateMethod.
- #display_provider_results(providers) ⇒ Object
-
#initialize(prompt: nil) ⇒ WizardPrompt
constructor
A new instance of WizardPrompt.
- #select_default_provider(working_providers) ⇒ Object
-
#select_from(question, choices) ⇒ Object
rubocop:enable Naming/PredicateMethod.
- #select_provider ⇒ Object
Constructor Details
#initialize(prompt: nil) ⇒ WizardPrompt
Returns a new instance of WizardPrompt.
19 20 21 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 19 def initialize(prompt: nil) @prompt = prompt || ::TTY::Prompt.new end |
Instance Method Details
#ask_api_key(provider:) ⇒ Object
35 36 37 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 35 def ask_api_key(provider:) @prompt.mask("Enter API key for #{provider}:") end |
#ask_name ⇒ Object
23 24 25 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 23 def ask_name @prompt.ask('What should I call you?', required: true) { |q| q.modify(:strip) } end |
#ask_name_with_default(default) ⇒ Object
27 28 29 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 27 def ask_name_with_default(default) @prompt.ask('What should I call you?', default: default) { |q| q.modify(:strip) } end |
#ask_secret(question) ⇒ Object
39 40 41 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 39 def ask_secret(question) @prompt.mask(question) end |
#ask_with_default(question, default) ⇒ Object
43 44 45 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 43 def ask_with_default(question, default) @prompt.ask(question, default: default) end |
#confirm(question) ⇒ Object
rubocop:disable Naming/PredicateMethod
48 49 50 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 48 def confirm(question) @prompt.yes?(question) end |
#display_provider_results(providers) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 57 def display_provider_results(providers) providers.each do |p| icon = p[:status] == :ok ? "\u2705" : "\u274C" latency = "#{p[:latency_ms]}ms" label = "#{icon} #{p[:name]} (#{p[:model]}) \u2014 #{latency}" label += " [#{p[:error]}]" if p[:error] @prompt.say(label) end end |
#select_default_provider(working_providers) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 67 def select_default_provider(working_providers) return nil if working_providers.empty? return working_providers.first[:name] if working_providers.size == 1 choices = working_providers.map do |p| { name: "#{p[:name]} (#{p[:model]}, #{p[:latency_ms]}ms)", value: p[:name] } end choices << { name: 'Skip for now', value: nil } @prompt.select('Multiple providers available. Choose your default:', choices) end |
#select_from(question, choices) ⇒ Object
rubocop:enable Naming/PredicateMethod
53 54 55 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 53 def select_from(question, choices) @prompt.select(question, choices) end |
#select_provider ⇒ Object
31 32 33 |
# File 'lib/legion/tty/components/wizard_prompt.rb', line 31 def select_provider @prompt.select('Choose an AI provider:', PROVIDERS) end |