Class: ReplicateClient::Training
- Inherits:
-
Object
- Object
- ReplicateClient::Training
- Defined in:
- lib/replicate-client/training.rb
Defined Under Namespace
Modules: Status
Constant Summary collapse
- INDEX_PATH =
"/trainings"
Instance Attribute Summary collapse
-
#completed_at ⇒ Time?
The timestamp when the training was completed.
-
#created_at ⇒ String
The timestamp when the training was created.
-
#error ⇒ String?
The error message, if any, encountered during the training process.
-
#id ⇒ String
The unique identifier of the training.
-
#input ⇒ Hash
The input data provided for the training.
-
#logs ⇒ String
The logs generated during the training process.
-
#metrics ⇒ Hash?
The metrics generated during the training process.
-
#model_full_name ⇒ String
The full model name in the format “owner/name”.
-
#output ⇒ Hash?
The output data generated during the training process.
-
#started_at ⇒ Time?
The timestamp when the training was started.
-
#status ⇒ String
The current status of the training.
-
#urls ⇒ Hash
URLs related to the training, such as those for retrieving or canceling it.
-
#version_id ⇒ String
The version ID of the model being trained.
Class Method Summary collapse
-
.auto_paging_each {|ReplicateClient::Training| ... } ⇒ void
List all trainings.
-
.build_path(id:) ⇒ String
Build the path for a specific training.
-
.cancel!(id) ⇒ void
Cancel a training.
-
.create!(owner:, name:, version:, destination:, input:, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Training
Create a new training.
-
.create_for_model!(model:, destination:, input:, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Training
Create a new training for a specific model.
-
.find(id) ⇒ ReplicateClient::Training
Find a training by id.
Instance Method Summary collapse
-
#cancel! ⇒ void
Cancel the training.
-
#canceled? ⇒ Boolean
Check if the training was canceled.
-
#failed? ⇒ Boolean
Check if the training has failed.
-
#initialize(attributes) ⇒ ReplicateClient::Training
constructor
Initialize a new training instance.
-
#model ⇒ ReplicateClient::Model
The model instance of the training.
-
#processing? ⇒ Boolean
Check if the training is processing.
-
#reload! ⇒ void
Reload the training.
-
#starting? ⇒ Boolean
Check if the training is starting.
-
#succeeded? ⇒ Boolean
Check if the training has succeeded.
-
#version ⇒ ReplicateClient::Model::Version
The version instance of the training.
Constructor Details
#initialize(attributes) ⇒ ReplicateClient::Training
Initialize a new training instance.
191 192 193 |
# File 'lib/replicate-client/training.rb', line 191 def initialize(attributes) reset_attributes(attributes) end |
Instance Attribute Details
#completed_at ⇒ Time?
The timestamp when the training was completed.
154 155 156 |
# File 'lib/replicate-client/training.rb', line 154 def completed_at @completed_at end |
#created_at ⇒ String
The timestamp when the training was created.
149 150 151 |
# File 'lib/replicate-client/training.rb', line 149 def created_at @created_at end |
#error ⇒ String?
The error message, if any, encountered during the training process.
169 170 171 |
# File 'lib/replicate-client/training.rb', line 169 def error @error end |
#id ⇒ String
The unique identifier of the training.
123 124 125 |
# File 'lib/replicate-client/training.rb', line 123 def id @id end |
#input ⇒ Hash
The input data provided for the training.
138 139 140 |
# File 'lib/replicate-client/training.rb', line 138 def input @input end |
#logs ⇒ String
The logs generated during the training process.
164 165 166 |
# File 'lib/replicate-client/training.rb', line 164 def logs @logs end |
#metrics ⇒ Hash?
The metrics generated during the training process.
184 185 186 |
# File 'lib/replicate-client/training.rb', line 184 def metrics @metrics end |
#model_full_name ⇒ String
The full model name in the format “owner/name”.
128 129 130 |
# File 'lib/replicate-client/training.rb', line 128 def model_full_name @model_full_name end |
#output ⇒ Hash?
The output data generated during the training process.
179 180 181 |
# File 'lib/replicate-client/training.rb', line 179 def output @output end |
#started_at ⇒ Time?
The timestamp when the training was started.
159 160 161 |
# File 'lib/replicate-client/training.rb', line 159 def started_at @started_at end |
#status ⇒ String
The current status of the training. Possible values: “starting”, “processing”, “succeeded”, “failed”, “canceled”.
144 145 146 |
# File 'lib/replicate-client/training.rb', line 144 def status @status end |
#urls ⇒ Hash
URLs related to the training, such as those for retrieving or canceling it.
174 175 176 |
# File 'lib/replicate-client/training.rb', line 174 def urls @urls end |
#version_id ⇒ String
The version ID of the model being trained.
133 134 135 |
# File 'lib/replicate-client/training.rb', line 133 def version_id @version_id end |
Class Method Details
.auto_paging_each {|ReplicateClient::Training| ... } ⇒ void
This method returns an undefined value.
List all trainings.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/replicate-client/training.rb', line 21 def auto_paging_each(&block) cursor = nil loop do url_params = cursor ? "?cursor=#{cursor}" : "" attributes = ReplicateClient.client.get("#{INDEX_PATH}#{url_params}") trainings = attributes["results"].map { |training| new(training) } trainings.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(id:) ⇒ String
Build the path for a specific training.
115 116 117 |
# File 'lib/replicate-client/training.rb', line 115 def build_path(id:) "#{INDEX_PATH}/#{id}" end |
.cancel!(id) ⇒ void
This method returns an undefined value.
Cancel a training.
105 106 107 108 |
# File 'lib/replicate-client/training.rb', line 105 def cancel!(id) path = "#{build_path(id: id)}/cancel" ReplicateClient.client.post(path) end |
.create!(owner:, name:, version:, destination:, input:, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Training
Create a new training.
format.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/replicate-client/training.rb', line 49 def create!(owner:, name:, version:, destination:, input:, webhook_url: nil, webhook_events_filter: nil) destination_str = destination.is_a?(ReplicateClient::Model) ? destination.full_name : destination version_id = version.is_a?(ReplicateClient::Model::Version) ? version.id : version path = "/models/#{owner}/#{name}/versions/#{version_id}/trainings" body = { destination: destination_str, input: input, webhook: webhook_url || ReplicateClient.configuration.webhook_url, webhook_events_filter: webhook_events_filter } attributes = ReplicateClient.client.post(path, body) new(attributes) end |
.create_for_model!(model:, destination:, input:, webhook_url: nil, webhook_events_filter: nil) ⇒ ReplicateClient::Training
Create a new training for a specific model.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/replicate-client/training.rb', line 74 def create_for_model!(model:, destination:, input:, webhook_url: nil, webhook_events_filter: nil) model_instance = model.is_a?(ReplicateClient::Model) ? model : ReplicateClient::Model.find(model) raise ArgumentError, "Invalid model" unless model_instance create!( owner: model_instance.owner, name: model_instance.name, version: model_instance.version_id, destination: destination, input: input, webhook_url: webhook_url || ReplicateClient.configuration.webhook_url, webhook_events_filter: webhook_events_filter ) end |
.find(id) ⇒ ReplicateClient::Training
Find a training by id.
94 95 96 97 98 |
# File 'lib/replicate-client/training.rb', line 94 def find(id) path = build_path(id: id) attributes = ReplicateClient.client.get(path) new(attributes) end |
Instance Method Details
#cancel! ⇒ void
This method returns an undefined value.
Cancel the training.
233 234 235 |
# File 'lib/replicate-client/training.rb', line 233 def cancel! ReplicateClient::Training.cancel!(id) end |
#canceled? ⇒ Boolean
Check if the training was canceled.
226 227 228 |
# File 'lib/replicate-client/training.rb', line 226 def canceled? status == Status::CANCELED end |
#failed? ⇒ Boolean
Check if the training has failed.
219 220 221 |
# File 'lib/replicate-client/training.rb', line 219 def failed? status == Status::FAILED end |
#model ⇒ ReplicateClient::Model
The model instance of the training.
248 249 250 |
# File 'lib/replicate-client/training.rb', line 248 def model @model ||= ReplicateClient::Model.find(model_full_name, version_id: version_id) end |
#processing? ⇒ Boolean
Check if the training is processing.
205 206 207 |
# File 'lib/replicate-client/training.rb', line 205 def processing? status == Status::PROCESSING end |
#reload! ⇒ void
This method returns an undefined value.
Reload the training.
240 241 242 243 |
# File 'lib/replicate-client/training.rb', line 240 def reload! attributes = ReplicateClient.client.get(Training.build_path(id: id)) reset_attributes(attributes) end |
#starting? ⇒ Boolean
Check if the training is starting.
198 199 200 |
# File 'lib/replicate-client/training.rb', line 198 def starting? status == Status::STARTING end |
#succeeded? ⇒ Boolean
Check if the training has succeeded.
212 213 214 |
# File 'lib/replicate-client/training.rb', line 212 def succeeded? status == Status::SUCCEEDED end |
#version ⇒ ReplicateClient::Model::Version
The version instance of the training.
255 256 257 |
# File 'lib/replicate-client/training.rb', line 255 def version @version ||= model.version end |