Class: RailsAgents::Configuration

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

Constant Summary collapse

PROVIDERS =
%i[openai anthropic openrouter grok].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



13
14
15
16
17
18
19
20
21
# File 'lib/rails_agents/configuration.rb', line 13

def initialize
  @openai_api_key = ENV["OPENAI_API_KEY"]
  @anthropic_api_key = ENV["ANTHROPIC_API_KEY"]
  @openrouter_api_key = ENV["OPENROUTER_API_KEY"]
  @grok_api_key = ENV["XAI_API_KEY"] || ENV["GROK_API_KEY"]
  @default_provider = :openai
  @anthropic_auto_download_files = true
  @anthropic_files_directory = nil
end

Instance Attribute Details

#anthropic_api_keyObject

Returns the value of attribute anthropic_api_key.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def anthropic_api_key
  @anthropic_api_key
end

#anthropic_auto_download_filesObject

Returns the value of attribute anthropic_auto_download_files.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def anthropic_auto_download_files
  @anthropic_auto_download_files
end

#anthropic_files_directoryObject

Returns the value of attribute anthropic_files_directory.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def anthropic_files_directory
  @anthropic_files_directory
end

#default_providerObject

Returns the value of attribute default_provider.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def default_provider
  @default_provider
end

#grok_api_keyObject

Returns the value of attribute grok_api_key.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def grok_api_key
  @grok_api_key
end

#openai_api_keyObject

Returns the value of attribute openai_api_key.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def openai_api_key
  @openai_api_key
end

#openrouter_api_keyObject

Returns the value of attribute openrouter_api_key.



10
11
12
# File 'lib/rails_agents/configuration.rb', line 10

def openrouter_api_key
  @openrouter_api_key
end

Instance Method Details

#anthropic_files_directory!Object



27
28
29
30
31
32
33
# File 'lib/rails_agents/configuration.rb', line 27

def anthropic_files_directory!
  return Pathname.new(@anthropic_files_directory) if @anthropic_files_directory.to_s != ""

  return Rails.root.join("tmp/rails_agents/files") if defined?(Rails)

  Pathname.new(Dir.mktmpdir("rails_agents_files_"))
end

#api_key_for(provider) ⇒ Object



23
24
25
# File 'lib/rails_agents/configuration.rb', line 23

def api_key_for(provider)
  public_send(:"#{provider}_api_key")
end