Class: Rubino::API::Operations::Models::ListOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/api/operations/models/list_operation.rb

Overview

GET /v1/models — returns the model catalog from ruby_llm. The source defaults to RubyLLM.models.all but accepts any callable returning an enumerable of model objects/hashes for tests.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_source: nil) ⇒ ListOperation

Accepts an alternate model source (callable) for tests.



18
19
20
# File 'lib/rubino/api/operations/models/list_operation.rb', line 18

def initialize(model_source: nil)
  @model_source = model_source || -> { RubyLLM.models.all }
end

Class Method Details

.call(request) ⇒ Object



13
14
15
# File 'lib/rubino/api/operations/models/list_operation.rb', line 13

def self.call(request)
  new.call(request)
end

Instance Method Details

#call(_request) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rubino/api/operations/models/list_operation.rb', line 22

def call(_request)
  models = @model_source.call.map do |m|
    {
      id: model_id(m),
      provider: m.respond_to?(:provider) ? m.provider.to_s : nil,
      context_window: m.respond_to?(:context_window) ? m.context_window : nil
    }
  end
  [200, models]
end