Class: Qualspec::Configuration

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

Constant Summary collapse

DEFAULT_API_URL =
'https://openrouter.ai/api/v1'
DEFAULT_MODEL =

Universal fallback. openrouter/auto routes to a sensible model for any request, so qualspec works even with no model configured anywhere.

'openrouter/auto'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/qualspec/configuration.rb', line 14

def initialize
  @api_url = ENV.fetch('QUALSPEC_API_URL', DEFAULT_API_URL)
  # Default nil: set explicitly via Qualspec.configure { |c| c.api_key = ... }.
  # When unset, #api_key falls back to env vars (see reader below).
  @api_key = nil
  @default_model = ENV.fetch('QUALSPEC_MODEL', DEFAULT_MODEL)
  @judge_model = ENV.fetch('QUALSPEC_JUDGE_MODEL') { @default_model }
  @cache_enabled = false
  @cache_dir = '.qualspec_cache'
  @judge_system_prompt = nil # Uses default if nil
  @request_timeout = 120
end

Instance Attribute Details

#api_keyObject

Explicitly configured key wins; otherwise fall back to env vars. Prefer QUALSPEC_API_KEY, then OPEN_ROUTER_API_KEY (default backend is OpenRouter). The env vars are a convenience fallback, not a requirement — pass api_key in Qualspec.configure to avoid relying on them.



31
32
33
# File 'lib/qualspec/configuration.rb', line 31

def api_key
  @api_key || ENV['QUALSPEC_API_KEY'] || ENV['OPEN_ROUTER_API_KEY']
end

#api_urlObject

Returns the value of attribute api_url.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def api_url
  @api_url
end

#cache_dirObject

Returns the value of attribute cache_dir.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def cache_dir
  @cache_dir
end

#cache_enabledObject

Returns the value of attribute cache_enabled.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def cache_enabled
  @cache_enabled
end

#default_modelObject

Returns the value of attribute default_model.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def default_model
  @default_model
end

#judge_modelObject

Returns the value of attribute judge_model.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def judge_model
  @judge_model
end

#judge_system_promptObject

Returns the value of attribute judge_system_prompt.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def judge_system_prompt
  @judge_system_prompt
end

#request_timeoutObject

Returns the value of attribute request_timeout.



5
6
7
# File 'lib/qualspec/configuration.rb', line 5

def request_timeout
  @request_timeout
end

Instance Method Details

#api_headersObject



35
36
37
38
39
# File 'lib/qualspec/configuration.rb', line 35

def api_headers
  headers = { 'Content-Type' => 'application/json' }
  headers['Authorization'] = "Bearer #{api_key}" unless api_key.to_s.empty?
  headers
end

#api_key_configured?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/qualspec/configuration.rb', line 41

def api_key_configured?
  !api_key.to_s.empty?
end