Class: Sublayer::Commands::Action

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/sublayer/cli/commands/action.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



12
13
14
# File 'lib/sublayer/cli/commands/action.rb', line 12

def self.banner
  "sublayer generate:action"
end

Instance Method Details

#ask_for_action_detailsObject



30
31
32
33
34
35
# File 'lib/sublayer/cli/commands/action.rb', line 30

def ask_for_action_details
  @ai_provider = options[:provider] || ask("Select an AI provider:", default: "OpenAI", limited_to: @available_providers)
  @ai_model = options[:model] || select_ai_model

  @description = options[:description] || ask("Enter a description for the Sublayer Action you'd like to create:")
end

#confirm_usage_of_ai_apiObject



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_providersObject



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_folderObject



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_actionObject



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_folderObject



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