Class: CleoQualityReview::LlmProviders::OpenAi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/llm_providers/open_ai_config.rb

Overview

Configuration for OpenAI API access.

Constant Summary collapse

OPEN_AI_API_KEY =
"CLEO_QUALITY_REVIEW_OPEN_AI_KEY"
TIMEOUT_SECONDS =
"CLEO_QUALITY_REVIEW_TIMEOUT_SECONDS"
DEFAULT_MODEL =
"gpt-5.5"
DEFAULT_TIMEOUT_SECONDS =
180

Instance Method Summary collapse

Constructor Details

#initialize(env: ENV) ⇒ Config

Returns a new instance of Config.

Parameters:

  • env (Hash{String => String}) (defaults to: ENV)

    environment variables



18
19
20
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 18

def initialize(env: ENV)
  @env = env
end

Instance Method Details

#api_keyString

Returns the OpenAI API key.

Returns:

  • (String)

    the OpenAI API key

Raises:

  • (KeyError)

    if the API key is not set



37
38
39
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 37

def api_key
  env.fetch(OPEN_AI_API_KEY)
end

#api_key_envString

Returns environment variable name for the API key.

Returns:

  • (String)

    environment variable name for the API key



24
25
26
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 24

def api_key_env
  OPEN_AI_API_KEY
end

#configured?Boolean

Check if the OpenAI configuration is complete.

Returns:

  • (Boolean)


62
63
64
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 62

def configured?
  env.fetch(OPEN_AI_API_KEY, "").to_s.strip != ""
end

#modelString

Returns the model identifier to use.

Returns:

  • (String)

    the model identifier to use



43
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 43

def model = DEFAULT_MODEL

#timeout_secondsInteger

Returns timeout in seconds for OpenAI HTTP requests.

Returns:

  • (Integer)

    timeout in seconds for OpenAI HTTP requests

Raises:

  • (ArgumentError)

    if the configured timeout is not a positive integer



48
49
50
51
52
53
54
55
56
57
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 48

def timeout_seconds
  value = env.fetch(TIMEOUT_SECONDS, "").to_s.strip
  return DEFAULT_TIMEOUT_SECONDS if value.empty?

  Integer(value, 10).tap do |seconds|
    raise ArgumentError if seconds <= 0
  end
rescue ArgumentError
  raise ArgumentError, "#{TIMEOUT_SECONDS} must be a positive integer number of seconds"
end

#timeout_seconds_envString

Returns environment variable name for the request timeout.

Returns:

  • (String)

    environment variable name for the request timeout



30
31
32
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 30

def timeout_seconds_env
  TIMEOUT_SECONDS
end

#validatevoid

This method returns an undefined value.

Validate that the configuration is complete.

Raises:



71
72
73
74
75
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 71

def validate
  raise MissingLlmConfigurationError, "Missing OpenAI API key. Set #{api_key_env}." unless configured?

  timeout_seconds
end