summaryrefslogtreecommitdiffhomepage
path: root/lib/dispatch/adapter/claude/model_catalog.rb
blob: 51fb2a3ca06169d189e3086cd0dfb12ee5a74626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

module Dispatch
  module Adapter
    class Claude < Base
      module ModelCatalog
        module_function

        # Build a ModelInfo for a given model id using the bundled pricing table.
        #
        # @param id [String] a model id present in PricingTable
        # @return [Dispatch::Adapter::ModelInfo]
        def build(id)
          ModelInfo.new(
            id: id,
            name: id,
            max_context_tokens: PricingTable.context_window(id) || 200_000,
            supports_vision: true,
            supports_tool_use: true,
            supports_streaming: true,
            premium_request_multiplier: nil,
            pricing: PricingTable.lookup(id)
          )
        end

        # Build a ModelInfo from a runtime API entry (from GET /v1/models).
        #
        # If the model is in the bundled pricing table, pricing data and
        # context-window size are taken from there; the runtime display_name
        # overrides the name.  For unknown models, pricing is nil and a
        # default context window of 200_000 is used.
        #
        # @param api_entry [Hash]  one element of the "data" array from GET /v1/models
        # @return [Dispatch::Adapter::ModelInfo]
        def build_from_api(api_entry)
          id           = api_entry["id"].to_s
          display_name = api_entry["display_name"].to_s
          display_name = id if display_name.empty?

          pricing     = PricingTable.lookup(id)
          context_win = PricingTable.context_window(id) || 200_000

          name = if pricing.nil?
                   "(unrated) #{display_name}"
                 else
                   display_name
                 end

          ModelInfo.new(
            id: id,
            name: name,
            max_context_tokens: context_win,
            supports_vision: true,
            supports_tool_use: true,
            supports_streaming: true,
            premium_request_multiplier: nil,
            pricing: pricing
          )
        end
      end
    end
  end
end