Class: MitchAI::Configuration
- Inherits:
-
Object
- Object
- MitchAI::Configuration
- Defined in:
- lib/mitch_ai/configuration.rb
Constant Summary collapse
- CONFIG_FILE =
File.('~/.mitch_ai.yml')
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#languages ⇒ Object
Returns the value of attribute languages.
-
#provider ⇒ Object
Returns the value of attribute provider.
Instance Method Summary collapse
- #configure_api_key(provider) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
13 14 15 16 17 18 |
# File 'lib/mitch_ai/configuration.rb', line 13 def initialize @provider = :openai @languages = i[ruby python javascript] @api_key = ENV.fetch('OPENAI_API_KEY', nil) # Check environment variable first load_config unless @api_key # Only load from config if not already set end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/mitch_ai/configuration.rb', line 11 def api_key @api_key end |
#languages ⇒ Object
Returns the value of attribute languages.
11 12 13 |
# File 'lib/mitch_ai/configuration.rb', line 11 def languages @languages end |
#provider ⇒ Object
Returns the value of attribute provider.
11 12 13 |
# File 'lib/mitch_ai/configuration.rb', line 11 def provider @provider end |
Instance Method Details
#configure_api_key(provider) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mitch_ai/configuration.rb', line 20 def configure_api_key(provider) print "Enter your #{provider.upcase} API key: " api_key = ask_securely # Validate API key (basic check) if valid_api_key?(api_key) save_api_key(provider, api_key) puts 'API key saved successfully!' else puts 'Invalid API key. Please try again.' end end |