Class: ReplicateClient::Model::Version
- Inherits:
-
Object
- Object
- ReplicateClient::Model::Version
- Defined in:
- lib/replicate-client/model/version.rb
Constant Summary collapse
- INDEX_PATH =
"/versions"
Instance Attribute Summary collapse
-
#cog_version ⇒ String
The cog version of the model version.
-
#created_at ⇒ Time
The date the model version was created.
-
#id ⇒ String
The ID of the model version.
-
#openapi_schema ⇒ Hash
The OpenAPI schema of the model version.
Class Method Summary collapse
-
.auto_paging_each(owner:, name:) {|ReplicateClient::Model| ... } ⇒ void
Paginate through all models.
-
.build_path(owner:, name:, version_id:) ⇒ String
Build the path for the model version.
-
.find_by(owner:, name:, version_id:) ⇒ ReplicateClient::Model::Version
Find a version of a model.
-
.find_by!(owner:, name:, version_id:) ⇒ ReplicateClient::Model::Version
Find a version of a model.
-
.where(owner:, name:) ⇒ Array<ReplicateClient::Model::Version>
Get all versions of a model.
Instance Method Summary collapse
-
#create_prediction!(input:, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Prediction
Create a new prediction.
-
#initialize(attributes) ⇒ Version
constructor
A new instance of Version.
-
#prediction_input_schema ⇒ Hash
Get the prediction input schema from the openapi schema.
-
#training_input_schema ⇒ Hash
Get the training input schema from the openapi schema.
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_version ⇒ String
The cog version of the model version.
101 102 103 |
# File 'lib/replicate-client/model/version.rb', line 101 def cog_version @cog_version end |
#created_at ⇒ Time
The date the model version was created.
96 97 98 |
# File 'lib/replicate-client/model/version.rb', line 96 def created_at @created_at end |
#id ⇒ String
The ID of the model version.
91 92 93 |
# File 'lib/replicate-client/model/version.rb', line 91 def id @id end |
#openapi_schema ⇒ Hash
The OpenAPI schema of the model version.
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.
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.
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.
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.
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.
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.
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_schema ⇒ Hash
Get the prediction input schema from the openapi 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_schema ⇒ Hash
Get the training input schema from the openapi 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 |