Class: Commiti::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/services/helpers/config_loader.rb

Constant Summary collapse

DEFAULT_TEXT_GENERATION_CONFIG =
Commiti::TextGenerationStyle::DEFAULT_CONFIG
DEFAULT_CONFIG =
{
  google_api_key: nil,
  github_token: nil,
  gitlab_token: nil,
  gitbucket_token: nil,
  model: Commiti::GoogleClient::DEFAULT_MODEL,
  candidates: 1,
  base_branch: 'main',
  no_copy: false,
  auto_split: false,
  temperature: Commiti::GoogleClient::DEFAULT_TEMPERATURE,
  timeout_seconds: Commiti::GoogleClient::DEFAULT_TIMEOUT_SECONDS,
  open_timeout_seconds: Commiti::GoogleClient::DEFAULT_OPEN_TIMEOUT_SECONDS,
  text_generation: DEFAULT_TEXT_GENERATION_CONFIG
}.freeze

Class Method Summary collapse

Class Method Details

.load(env: ENV, cwd: Dir.pwd) ⇒ Object

Loads configuration from environment variables. Keys are returned as symbols with parsed values.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/services/helpers/config_loader.rb', line 28

def self.load(env: ENV, cwd: Dir.pwd)
  DEFAULT_CONFIG.merge(
    google_api_key: google_api_key_from_env(env),
    github_token: present_or_nil(env.fetch('COMMITI_GITHUB_TOKEN', nil)),
    gitlab_token: present_or_nil(env.fetch('COMMITI_GITLAB_TOKEN', nil)),
    gitbucket_token: present_or_nil(env.fetch('COMMITI_GITBUCKET_TOKEN', nil)),
    model: present_or_default(env.fetch('COMMITI_MODEL', nil), DEFAULT_CONFIG[:model]),
    candidates: integer_or_default(env.fetch('COMMITI_CANDIDATES', nil), DEFAULT_CONFIG[:candidates]),
    base_branch: present_or_default(env.fetch('COMMITI_BASE_BRANCH', nil), DEFAULT_CONFIG[:base_branch]),
    no_copy: boolean_or_default(env.fetch('COMMITI_NO_COPY', nil), DEFAULT_CONFIG[:no_copy]),
    auto_split: boolean_or_default(env.fetch('COMMITI_AUTO_SPLIT', nil), DEFAULT_CONFIG[:auto_split]),
    temperature: float_or_default(env.fetch('COMMITI_MODEL_TEMPERATURE', nil), DEFAULT_CONFIG[:temperature]),
    timeout_seconds: integer_or_default(env.fetch('COMMITI_MODEL_TIMEOUT_SECONDS', nil), DEFAULT_CONFIG[:timeout_seconds]),
    open_timeout_seconds: integer_or_default(env.fetch('COMMITI_MODEL_OPEN_TIMEOUT_SECONDS', nil),
                                             DEFAULT_CONFIG[:open_timeout_seconds]),
    text_generation: load_text_generation_config(env: env, cwd: cwd)
  )
end