Module: Legion::LLM::API::Namespaces::Anthropic::Models

Defined in:
lib/legion/llm/api/namespaces/anthropic/models.rb

Overview

Models provides Anthropic-format model serialization helpers. These are called by the unified /v1/models namespace (OpenAI::Models) when detect_client(env) identifies an Anthropic client. There are NO routes here – do NOT register this as a Sinatra::Extension under /v1/models; that path is already owned by OpenAI::Models.

Constant Summary collapse

MODEL_CREATED_AT =
'2025-01-01T00:00:00Z'

Class Method Summary collapse

Class Method Details

.format_model(offering) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/legion/llm/api/namespaces/anthropic/models.rb', line 34

def self.format_model(offering)
  id = offering[:model].to_s
  {
    id:           id,
    type:         'model',
    display_name: id.split(/[-_]/).map(&:capitalize).join(' '),
    created_at:   MODEL_CREATED_AT
  }
end

.format_model_list(offerings) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/legion/llm/api/namespaces/anthropic/models.rb', line 16

def self.format_model_list(offerings)
  seen = {}
  model_list = offerings.filter_map do |offering|
    id = offering[:model].to_s
    next if seen[id]

    seen[id] = true
    format_model(offering)
  end

  {
    data:     model_list,
    has_more: false,
    first_id: model_list.first&.fetch(:id, nil),
    last_id:  model_list.last&.fetch(:id, nil)
  }
end