Class: LLM::Anthropic::Models

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/providers/anthropic/models.rb

Overview

The LLM::Anthropic::Models class provides a model object for interacting with Anthropic’s models API. The models API allows a client to query Anthropic for a list of models that are available for use with the Anthropic API.

Examples:

#!/usr/bin/env ruby
require "llm"

llm = LLM.anthropic(ENV["KEY"])
res = llm.models.all
res.each do |model|
  print "id: ", model.id, "\n"
end

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ LLM::Anthropic::Files

Returns a new Models object

Parameters:



24
25
26
# File 'lib/llm/providers/anthropic/models.rb', line 24

def initialize(provider)
  @provider = provider
end

Instance Method Details

#all(**params) ⇒ LLM::Response::FileList

List all models

Examples:

llm = LLM.anthropic(ENV["KEY"])
res = llm.models.all
res.each do |model|
  print "id: ", model.id, "\n"
end

Parameters:

  • params (Hash)

    Other parameters (see Anthropic docs)

Returns:

Raises:

See Also:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/llm/providers/anthropic/models.rb', line 40

def all(**params)
  query = URI.encode_www_form(params)
  req = Net::HTTP::Get.new("/v1/models?#{query}", headers)
  res = request(http, req)
  LLM::Response::ModelList.new(res).tap { |modellist|
    models = modellist.body["data"].map do |model|
      LLM::Model.from_hash(model).tap { _1.provider = @provider }
    end
    modellist.models = models
  }
end