Class: CleoQualityReview::LlmProviders::OpenAi::Config
- Inherits:
-
Object
- Object
- CleoQualityReview::LlmProviders::OpenAi::Config
- 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
-
#api_key ⇒ String
The OpenAI API key.
-
#api_key_env ⇒ String
Environment variable name for the API key.
-
#configured? ⇒ Boolean
Check if the OpenAI configuration is complete.
-
#initialize(env: ENV) ⇒ Config
constructor
A new instance of Config.
-
#model ⇒ String
The model identifier to use.
-
#timeout_seconds ⇒ Integer
Timeout in seconds for OpenAI HTTP requests.
-
#timeout_seconds_env ⇒ String
Environment variable name for the request timeout.
-
#validate ⇒ void
Validate that the configuration is complete.
Constructor Details
#initialize(env: ENV) ⇒ Config
Returns a new instance of Config.
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_key ⇒ String
Returns the OpenAI API key.
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_env ⇒ String
Returns 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.
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 |
#model ⇒ String
Returns the model identifier to use.
43 |
# File 'lib/cleo_quality_review/llm_providers/open_ai_config.rb', line 43 def model = DEFAULT_MODEL |
#timeout_seconds ⇒ Integer
Returns timeout in seconds for OpenAI HTTP requests.
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_env ⇒ String
Returns 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 |
#validate ⇒ void
This method returns an undefined value.
Validate that the configuration is complete.
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 |