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
-
#client ⇒ ReplicateClient::Client
The client used to make API requests for this model version.
-
#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:, client: ReplicateClient.client) {|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:, client: ReplicateClient.client) ⇒ ReplicateClient::Model::Version
Find a version of a model.
-
.find_by!(owner:, name:, version_id:, client: ReplicateClient.client) ⇒ ReplicateClient::Model::Version
Find a version of a model.
-
.where(owner:, name:, client: ReplicateClient.client) ⇒ 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, client: ReplicateClient.client) ⇒ 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, client: ReplicateClient.client) ⇒ Version
Returns a new instance of Version.
117 118 119 120 121 122 123 |
# File 'lib/replicate-client/model/version.rb', line 117 def initialize(attributes, client: ReplicateClient.client) @client = client @id = attributes["id"] @created_at = Time.parse(attributes["created_at"]) @cog_version = attributes["cog_version"] @openapi_schema = attributes["openapi_schema"] end |
Instance Attribute Details
#client ⇒ ReplicateClient::Client
The client used to make API requests for this model version.
115 116 117 |
# File 'lib/replicate-client/model/version.rb', line 115 def client @client end |
#cog_version ⇒ String
The cog version of the model version.
105 106 107 |
# File 'lib/replicate-client/model/version.rb', line 105 def cog_version @cog_version end |
#created_at ⇒ Time
The date the model version was created.
100 101 102 |
# File 'lib/replicate-client/model/version.rb', line 100 def created_at @created_at end |
#id ⇒ String
The ID of the model version.
95 96 97 |
# File 'lib/replicate-client/model/version.rb', line 95 def id @id end |
#openapi_schema ⇒ Hash
The OpenAPI schema of the model version.
110 111 112 |
# File 'lib/replicate-client/model/version.rb', line 110 def openapi_schema @openapi_schema end |
Class Method Details
.auto_paging_each(owner:, name:, client: ReplicateClient.client) {|ReplicateClient::Model| ... } ⇒ void
This method returns an undefined value.
Paginate through all models.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/replicate-client/model/version.rb', line 62 def auto_paging_each(owner:, name:, client: ReplicateClient.client, &block) cursor = nil model_path = Model.build_path(owner: owner, name: name) loop do url_params = cursor ? "?cursor=#{cursor}" : "" attributes = client.get("#{model_path}#{INDEX_PATH}#{url_params}") versions = attributes["results"].map { |version| new(version, client: client) } 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.
86 87 88 89 |
# File 'lib/replicate-client/model/version.rb', line 86 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:, client: ReplicateClient.client) ⇒ ReplicateClient::Model::Version
Find a version of a model.
31 32 33 34 35 |
# File 'lib/replicate-client/model/version.rb', line 31 def find_by(owner:, name:, version_id:, client: ReplicateClient.client) find_by!(owner: owner, name: name, version_id: version_id, client: client) rescue ReplicateClient::NotFoundError nil end |
.find_by!(owner:, name:, version_id:, client: ReplicateClient.client) ⇒ ReplicateClient::Model::Version
Find a version of a model.
17 18 19 20 21 |
# File 'lib/replicate-client/model/version.rb', line 17 def find_by!(owner:, name:, version_id:, client: ReplicateClient.client) path = build_path(owner: owner, name: name, version_id: version_id) response = client.get(path) new(response, client: client) end |
.where(owner:, name:, client: ReplicateClient.client) ⇒ Array<ReplicateClient::Model::Version>
Get all versions of a model.
44 45 46 47 48 49 50 51 52 |
# File 'lib/replicate-client/model/version.rb', line 44 def where(owner:, name:, client: ReplicateClient.client) versions = [] auto_paging_each(owner: owner, name: name, client: client) 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.
132 133 134 135 136 137 138 139 140 |
# File 'lib/replicate-client/model/version.rb', line 132 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, client: @client ) end |
#prediction_input_schema ⇒ Hash
Get the prediction input schema from the openapi schema.
145 146 147 |
# File 'lib/replicate-client/model/version.rb', line 145 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.
152 153 154 |
# File 'lib/replicate-client/model/version.rb', line 152 def training_input_schema resolve_ref(openapi_schema.dig("components", "schemas", "TrainingRequest", "properties", "input")) end |