Class: RubyLLM::Models::Registry::PublishedSource

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/models/registry.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = PUBLISHED_URL) ⇒ PublishedSource

Returns a new instance of PublishedSource.



91
92
93
# File 'lib/ruby_llm/models/registry.rb', line 91

def initialize(url = PUBLISHED_URL)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



89
90
91
# File 'lib/ruby_llm/models/registry.rb', line 89

def url
  @url
end

Instance Method Details

#fetch(etag: nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ruby_llm/models/registry.rb', line 95

def fetch(etag: nil)
  connection = RubyLLM::Transport::Connection.basic do |faraday|
    faraday.response :json, parser_options: { symbolize_names: true }
  end
  response = connection.get(url) do |request|
    request.headers['If-None-Match'] = etag if etag
  end

  return Result.new(nil, response.headers['etag'] || etag, true) if response.status == 304

  models = Registry.models_from_data(response.body, source: url)
  raise ModelRegistryError, 'Published model registry is empty' if models.empty?

  Result.new(models, response.headers['etag'], false)
rescue ModelRegistryError
  raise
rescue StandardError => e
  raise ModelRegistryError, "Could not refresh the model registry from #{url}: #{e.message}"
end