Class: Desiru::Models::OpenAI
Overview
OpenAI GPT model adapter
Constant Summary collapse
- DEFAULT_MODEL =
'gpt-4o-mini'
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ OpenAI
constructor
A new instance of OpenAI.
- #models ⇒ Object
Methods inherited from Base
#complete, #healthy?, #reset_stats, #stats
Constructor Details
#initialize(config = {}) ⇒ OpenAI
Returns a new instance of OpenAI.
11 12 13 14 15 16 17 18 19 |
# File 'lib/desiru/models/open_ai.rb', line 11 def initialize(config = {}) super @api_key = config[:api_key] || ENV.fetch('OPENAI_API_KEY', nil) raise ArgumentError, 'OpenAI API key is required' unless @api_key @client = ::OpenAI::Client.new(access_token: @api_key) @models_cache = nil @models_fetched_at = nil end |
Instance Method Details
#models ⇒ Object
21 22 23 24 25 |
# File 'lib/desiru/models/open_ai.rb', line 21 def models # Cache models for 1 hour fetch_models if @models_cache.nil? || @models_fetched_at.nil? || (Time.now - @models_fetched_at) > 3600 @models_cache end |