Class: Desiru::Models::OpenRouter

Inherits:
Base
  • Object
show all
Defined in:
lib/desiru/models/open_router.rb

Overview

OpenRouter model adapter - provides access to multiple models through a single API

Constant Summary collapse

DEFAULT_MODEL =
'anthropic/claude-3-haiku'

Instance Attribute Summary

Attributes inherited from Base

#client, #config

Instance Method Summary collapse

Methods inherited from Base

#complete, #healthy?, #reset_stats, #stats

Constructor Details

#initialize(config = {}) ⇒ OpenRouter

Returns a new instance of OpenRouter.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/desiru/models/open_router.rb', line 11

def initialize(config = {})
  super
  @api_key = config[:api_key] || ENV.fetch('OPENROUTER_API_KEY', nil)
  raise ArgumentError, 'OpenRouter API key is required' unless @api_key

  # Configure OpenRouter client
  ::OpenRouter.configure do |c|
    c.access_token = @api_key
    c.site_name = config[:site_name] || 'Desiru'
    c.site_url = config[:site_url] || 'https://github.com/obie/desiru'
  end

  @client = ::OpenRouter::Client.new
  @models_cache = nil
  @models_fetched_at = nil
end

Instance Method Details

#modelsObject



28
29
30
31
32
# File 'lib/desiru/models/open_router.rb', line 28

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