Class: Docit::Generators::AiSetupGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Docit::Generators::AiSetupGenerator
- Defined in:
- lib/generators/docit/ai_setup/ai_setup_generator.rb
Constant Summary collapse
- PROVIDER_OPTIONS =
{ "1" => "openai", "2" => "anthropic", "3" => "groq" }.freeze
Instance Method Summary collapse
- #print_instructions ⇒ Object
- #prompt_api_key ⇒ Object
- #prompt_provider ⇒ Object
- #save_configuration ⇒ Object
- #update_gitignore ⇒ Object
Instance Method Details
#print_instructions ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/generators/docit/ai_setup/ai_setup_generator.rb', line 67 def print_instructions say "" say "Docit AI configured successfully!", :green say "" say "Docit stores your API key in .docit_ai.yml with restricted file permissions." say "Keep that file out of version control." say "" say "Next steps:" say " rails docit:autodoc # document all undocumented endpoints" say " rails docit:autodoc[Api::V1::UsersController] # document a specific controller" say " DRY_RUN=1 rails docit:autodoc # preview without writing files" say "" say "To reconfigure, run this generator again." say "" end |
#prompt_api_key ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/generators/docit/ai_setup/ai_setup_generator.rb', line 30 def prompt_api_key loop do @api_key = ask_secret("Enter your #{@provider.capitalize} API key:") return if @api_key.empty? == false say "API key cannot be blank", :red end end |
#prompt_provider ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/docit/ai_setup/ai_setup_generator.rb', line 16 def prompt_provider say "" say "Select your AI provider:" say " 1. OpenAI" say " 2. Anthropic" say " 3. Groq (free tier available)" say "" choice = ask_choice("Enter choice (1-3):", PROVIDER_OPTIONS.keys) @provider = PROVIDER_OPTIONS[choice] say "Selected: #{@provider.capitalize}", :green end |
#save_configuration ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/docit/ai_setup/ai_setup_generator.rb', line 39 def save_configuration model = Docit::Ai::Configuration::DEFAULT_MODELS[@provider] Docit::Ai::Configuration.save( provider: @provider, model: model, api_key: @api_key ) say "Saved AI configuration to .docit_ai.yml", :green end |
#update_gitignore ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/docit/ai_setup/ai_setup_generator.rb', line 49 def update_gitignore gitignore = Rails.root.join(".gitignore") if File.exist?(gitignore) == false say "Warning: .gitignore not found. Add .docit_ai.yml manually to avoid committing your API key.", :yellow return end content = File.read(gitignore) return if content.include?(".docit_ai.yml") File.open(gitignore, "a") do |f| f.puts "" if content.end_with?("\n") == false f.puts "# Docit AI configuration (contains API key)" f.puts ".docit_ai.yml" end say "Added .docit_ai.yml to .gitignore", :green end |