Class: Sublayer::Commands::Action
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Sublayer::Commands::Action
- Includes:
- Thor::Actions
- Defined in:
- lib/sublayer/cli/commands/action.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ask_for_action_details ⇒ Object
- #confirm_usage_of_ai_api ⇒ Object
- #determine_available_providers ⇒ Object
- #determine_destination_folder ⇒ Object
- #generate_action ⇒ Object
- #save_action_to_destination_folder ⇒ Object
Class Method Details
.banner ⇒ Object
12 13 14 |
# File 'lib/sublayer/cli/commands/action.rb', line 12 def self. "sublayer generate:action" end |
Instance Method Details
#ask_for_action_details ⇒ Object
30 31 32 33 34 35 |
# File 'lib/sublayer/cli/commands/action.rb', line 30 def ask_for_action_details @ai_provider = [:provider] || ask("Select an AI provider:", default: "OpenAI", limited_to: @available_providers) @ai_model = [:model] || select_ai_model @description = [:description] || ask("Enter a description for the Sublayer Action you'd like to create:") end |
#confirm_usage_of_ai_api ⇒ Object
16 17 18 19 20 |
# File 'lib/sublayer/cli/commands/action.rb', line 16 def confirm_usage_of_ai_api puts "You are about to generate a new agent that uses an AI API to generate content." puts "Please ensure you have the necessary API keys and that you are aware of the costs associated with using the API." exit unless yes?("Do you want to continue?") end |
#determine_available_providers ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sublayer/cli/commands/action.rb', line 22 def determine_available_providers @available_providers = [] @available_providers << "OpenAI" if ENV["OPENAI_API_KEY"] @available_providers << "Claude" if ENV["ANTHROPIC_API_KEY"] @available_providers << "Gemini" if ENV["GEMINI_API_KEY"] end |
#determine_destination_folder ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/sublayer/cli/commands/action.rb', line 41 def determine_destination_folder @destination_folder = if File.directory?("./actions") "./actions" elsif Dir.glob("./lib/**/actions").any? Dir.glob("./lib/**/actions").first else "./" end end |
#generate_action ⇒ Object
37 38 39 |
# File 'lib/sublayer/cli/commands/action.rb', line 37 def generate_action @results = SublayerActionGenerator.new(description: @description).generate end |
#save_action_to_destination_folder ⇒ Object
51 52 53 |
# File 'lib/sublayer/cli/commands/action.rb', line 51 def save_action_to_destination_folder create_file File.join(@destination_folder, @results.filename), @results.code end |