Class: Credentials
- Inherits:
-
Object
- Object
- Credentials
- Defined in:
- lib/credentials.rb
Overview
Credentials class
Instance Attribute Summary collapse
-
#credentials_file ⇒ Object
Returns the value of attribute credentials_file.
-
#key ⇒ Object
Returns the value of attribute key.
-
#model ⇒ Object
Returns the value of attribute model.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #initial_file_format ⇒ Object
-
#initialize ⇒ Credentials
constructor
A new instance of Credentials.
- #missing_config_message(message) ⇒ Object
Constructor Details
#initialize ⇒ Credentials
Returns a new instance of Credentials.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/credentials.rb', line 10 def initialize @credentials_file = File.('~/.gchatsh') unless File.exist?(credentials_file) File.write(credentials_file, initial_file_format) = <<~ERROR You need to add your API key to the credentials file at #{credentials_file} ERROR raise "\n#{}" end Dotenv.load(credentials_file) if ENV['KEY'].empty? raise ('API key not found') elsif ENV['URL'].empty? raise ('API URL not found') elsif ENV['MODEL'].empty? raise ('Model not found') end @url = ENV['URL'] @key = ENV['KEY'] @model = ENV['MODEL'] end |
Instance Attribute Details
#credentials_file ⇒ Object
Returns the value of attribute credentials_file.
8 9 10 |
# File 'lib/credentials.rb', line 8 def credentials_file @credentials_file end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/credentials.rb', line 8 def key @key end |
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'lib/credentials.rb', line 8 def model @model end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/credentials.rb', line 8 def url @url end |
Instance Method Details
#initial_file_format ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/credentials.rb', line 39 def initial_file_format <<~CREDENTIALS URL=https://api.groq.com/openai/v1/chat/completions KEY= MODEL=llama3-8b-8192 CREDENTIALS end |
#missing_config_message(message) ⇒ Object
35 36 37 |
# File 'lib/credentials.rb', line 35 def () "#{} in the credentials file at #{credentials_file}" end |