Class: ReplicateClient::Model::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/replicate-client/model/version.rb

Constant Summary collapse

INDEX_PATH =
"/versions"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Version

Returns a new instance of Version.



108
109
110
111
112
113
# File 'lib/replicate-client/model/version.rb', line 108

def initialize(attributes)
  @id = attributes["id"]
  @created_at = Time.parse(attributes["created_at"])
  @cog_version = attributes["cog_version"]
  @openapi_schema = attributes["openapi_schema"]
end

Instance Attribute Details

#cog_versionString

The cog version of the model version.

Returns:

  • (String)


101
102
103
# File 'lib/replicate-client/model/version.rb', line 101

def cog_version
  @cog_version
end

#created_atTime

The date the model version was created.

Returns:

  • (Time)


96
97
98
# File 'lib/replicate-client/model/version.rb', line 96

def created_at
  @created_at
end

#idString

The ID of the model version.

Returns:

  • (String)


91
92
93
# File 'lib/replicate-client/model/version.rb', line 91

def id
  @id
end

#openapi_schemaHash

The OpenAPI schema of the model version.

Returns:

  • (Hash)


106
107
108
# File 'lib/replicate-client/model/version.rb', line 106

def openapi_schema
  @openapi_schema
end

Class Method Details

.auto_paging_each(owner:, name:) {|ReplicateClient::Model| ... } ⇒ void

This method returns an undefined value.

Paginate through all models.

Parameters:

  • name (String)

    The name of the model.

  • owner (String)

    The owner of the model.

Yields:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/replicate-client/model/version.rb', line 58

def auto_paging_each(owner:, name:, &block)
  cursor = nil
  model_path = Model.build_path(owner: owner, name: name)

  loop do
    url_params = cursor ? "?cursor=#{cursor}" : ""
    attributes = ReplicateClient.client.get("#{model_path}#{INDEX_PATH}#{url_params}")

    versions = attributes["results"].map { |version| new(version) }

    versions.each(&block)

    cursor = attributes["next"] ? URI.decode_www_form(URI.parse(attributes["next"]).query).to_h["cursor"] : nil
    break if cursor.nil?
  end
end

.build_path(owner:, name:, version_id:) ⇒ String

Build the path for the model version.

Parameters:

  • owner (String)

    The owner of the model.

  • name (String)

    The name of the model.

  • version_id (String)

    The version id of the model.

Returns:

  • (String)


82
83
84
85
# File 'lib/replicate-client/model/version.rb', line 82

def build_path(owner:, name:, version_id:)
  model_path = Model.build_path(owner: owner, name: name)
  "#{model_path}#{INDEX_PATH}/#{version_id}"
end

.find_by(owner:, name:, version_id:) ⇒ ReplicateClient::Model::Version

Find a version of a model.

Parameters:

  • owner (String)

    The owner of the model.

  • name (String)

    The name of the model.

  • version_id (String)

    The version id of the model.

Returns:



29
30
31
32
33
# File 'lib/replicate-client/model/version.rb', line 29

def find_by(owner:, name:, version_id:)
  find_by!(owner: owner, name: name, version_id: version_id)
rescue ReplicateClient::NotFoundError
  nil
end

.find_by!(owner:, name:, version_id:) ⇒ ReplicateClient::Model::Version

Find a version of a model.

Parameters:

  • owner (String)

    The owner of the model.

  • name (String)

    The name of the model.

  • version_id (String)

    The version id of the model.

Returns:



16
17
18
19
20
# File 'lib/replicate-client/model/version.rb', line 16

def find_by!(owner:, name:, version_id:)
  path = build_path(owner: owner, name: name, version_id: version_id)
  response = ReplicateClient.client.get(path)
  new(response)
end

.where(owner:, name:) ⇒ Array<ReplicateClient::Model::Version>

Get all versions of a model.

Parameters:

  • owner (String)

    The owner of the model.

  • name (String)

    The name of the model.

Returns:



41
42
43
44
45
46
47
48
49
# File 'lib/replicate-client/model/version.rb', line 41

def where(owner:, name:)
  versions = []

  auto_paging_each(owner: owner, name: name) do |version|
    versions << version
  end

  versions
end

Instance Method Details

#create_prediction!(input:, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Prediction

Create a new prediction.

Parameters:

  • input (Hash)

    The input data for the prediction.

  • webhook_url (String, nil) (defaults to: nil)

    A URL to receive webhook notifications.

  • webhook_events_filter (Array, nil) (defaults to: nil)

    The events to trigger webhook requests.

Returns:



122
123
124
125
126
127
128
129
# File 'lib/replicate-client/model/version.rb', line 122

def create_prediction!(input:, webhook_url: nil, webhook_events_filter: nil)
  Prediction.create!(
    version: self,
    input: input,
    webhook_url: webhook_url,
    webhook_events_filter: webhook_events_filter
  )
end

#prediction_input_schemaHash

Get the prediction input schema from the openapi schema.

Returns:

  • (Hash)

    The prediction input schema.



134
135
136
# File 'lib/replicate-client/model/version.rb', line 134

def prediction_input_schema
  resolve_ref(openapi_schema.dig("components", "schemas", "PredictionRequest", "properties", "input"))
end

#training_input_schemaHash

Get the training input schema from the openapi schema.

Returns:

  • (Hash)

    The training input schema.



141
142
143
# File 'lib/replicate-client/model/version.rb', line 141

def training_input_schema
  resolve_ref(openapi_schema.dig("components", "schemas", "TrainingRequest", "properties", "input"))
end