# frozen_string_literal: true

RubyLLM.configure do |config|
  config.openai_api_key = Rails.application.credentials.openai_secret
  config.openrouter_api_key = Rails.application.credentials.openrouter.api_key
  config.vertexai_project_id = "norse-baton-398712"
  config.vertexai_location = "global"

  # Basic settings
  config.request_timeout = 300        # Seconds to wait for response (default: 300)
  config.max_retries = 3              # Retry attempts on failure (default: 3)

  # Advanced retry behavior
  config.retry_interval = 1 # Initial retry delay in seconds (default: 0.1)
  config.retry_backoff_factor = 2 # Exponential backoff multiplier (default: 2)
  config.retry_interval_randomness = 0.5 # Jitter to prevent thundering herd (default: 0.5)
end

begin
  RubyLLM.models.refresh!
rescue StandardError => e
  Rails.logger.warn "RubyLLM failed to refresh models on boot: #{e.message}"
end
