Class: MitchAI::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/mitch_ai/configuration.rb

Constant Summary collapse

CONFIG_FILE =
File.expand_path('~/.mitch_ai.yml')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



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_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/mitch_ai/configuration.rb', line 11

def api_key
  @api_key
end

#languagesObject

Returns the value of attribute languages.



11
12
13
# File 'lib/mitch_ai/configuration.rb', line 11

def languages
  @languages
end

#providerObject

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