replicate-client 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6798a521201c15a08cd456167052ac6de82b43f60487ea454dabda1865a28ce
4
- data.tar.gz: cd44ea8758209f771645f2d9755438d6ad890758f83ef2ce8dd03d39f1162d4e
3
+ metadata.gz: e9834788e800bcbdd19fe6e813b8c19c30b4d62ca0fe5035fe05d32b95126ac7
4
+ data.tar.gz: da4c94e22f0f3e884a690ab7c4d4701c812b17ec304efd2e8e956ea557aebf9f
5
5
  SHA512:
6
- metadata.gz: 7b0f59e6ae5803a0cefc0ec8a0d2312cf45b4205a7052cfae84bc70b13c062ebd533fed18c92971513139235418cb1a08662eff816cfa211fdc854451133df29
7
- data.tar.gz: 18e5cb1d7eb54ceddb10eac736da1e56baa8245eb558b4670da2fcd4e99a1d5519bc473313bee0bb5ba7a191cf1f3aeeafccbedea24a202a474df6a716684dba
6
+ metadata.gz: 60b067804aae73acf3bdf193936fa504bc748f023b3a55d2a168fc3014fd8a920b3b6a276ef2f5fa2c76d51c57ad2354cb324bd2e6495d7ba95b7d7283ab39e2
7
+ data.tar.gz: e8bba1499966efe2ec8deb92bcf9cc352368586b39f06309a151dbfb18d3f6de85ed69c36be86340d18b820989f36efde8666cc2d14718026713cd9c00fc9437
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- replicate-client (0.1.6)
4
+ replicate-client (0.1.8)
5
5
  faraday (>= 1)
6
6
 
7
7
  GEM
@@ -15,13 +15,15 @@ module ReplicateClient
15
15
  #
16
16
  # @param path [String] The path to the API endpoint.
17
17
  # @param payload [Hash] The payload to send to the API.
18
+ # @param headers [Hash] The headers to send to the API.
18
19
  #
19
20
  # @return [Hash] The response from the API.
20
- def post(path, payload)
21
+ def post(path, payload, headers: {})
21
22
  response = connection.post(build_url(path)) do |request|
22
23
  request.headers["Authorization"] = "Bearer #{@configuration.access_token}"
23
24
  request.headers["Content-Type"] = "application/json"
24
25
  request.headers["Accept"] = "application/json"
26
+ request.headers.merge!(headers)
25
27
  request.body = payload.compact.to_json
26
28
  end
27
29
 
@@ -19,9 +19,10 @@ module ReplicateClient
19
19
  # @param input [Hash] The input data for the prediction.
20
20
  # @param webhook_url [String] The URL to send webhook events to.
21
21
  # @param webhook_events_filter [Array<Symbol>] The events to send to the webhook.
22
+ # @param sync [Boolean] Whether to wait for the prediction to complete.
22
23
  #
23
24
  # @return [ReplicateClient::Prediction]
24
- def create!(version:, input:, webhook_url: nil, webhook_events_filter: nil)
25
+ def create!(version:, input:, webhook_url: nil, webhook_events_filter: nil, sync: false)
25
26
  args = {
26
27
  version: version.is_a?(Model::Version) ? version.id : version,
27
28
  input: input,
@@ -29,7 +30,9 @@ module ReplicateClient
29
30
  webhook_events_filter: webhook_events_filter&.map(&:to_s)
30
31
  }
31
32
 
32
- prediction = ReplicateClient.client.post(INDEX_PATH, args)
33
+ headers = sync ? { "Prefer" => "wait" } : {}
34
+
35
+ prediction = ReplicateClient.client.post(INDEX_PATH, args, headers:)
33
36
 
34
37
  new(prediction)
35
38
  end
@@ -40,16 +43,21 @@ module ReplicateClient
40
43
  # @param input [Hash] The input data for the prediction.
41
44
  # @param webhook_url [String] The URL to send webhook events to.
42
45
  # @param webhook_events_filter [Array<Symbol>] The events to send to the webhook.
46
+ # @param sync [Boolean] Whether to wait for the prediction to complete.
43
47
  #
44
48
  # @return [ReplicateClient::Prediction]
45
- def create_for_deployment!(deployment:, input:, webhook_url: nil, webhook_events_filter: nil)
49
+ def create_for_deployment!(deployment:, input:, webhook_url: nil, webhook_events_filter: nil, sync: false)
46
50
  args = {
47
51
  input: input,
48
52
  webhook: webhook_url || ReplicateClient.configuration.webhook_url,
49
53
  webhook_events_filter: webhook_events_filter&.map(&:to_s)
50
54
  }
51
55
 
52
- prediction = ReplicateClient.client.post("#{deployment.path}#{INDEX_PATH}", args)
56
+ headers = sync ? { "Prefer" => "wait" } : {}
57
+
58
+ deployment_path = deployment.is_a?(Deployment) ? deployment.path : "#{Deployment::INDEX_PATH}/#{deployment}"
59
+
60
+ prediction = ReplicateClient.client.post("#{deployment_path}#{INDEX_PATH}", args, headers:)
53
61
 
54
62
  new(prediction)
55
63
  end
@@ -60,9 +68,10 @@ module ReplicateClient
60
68
  # @param input [Hash] The input data for the prediction.
61
69
  # @param webhook_url [String] The URL to send webhook events to.
62
70
  # @param webhook_events_filter [Array<Symbol>] The events to send to the webhook.
71
+ # @param sync [Boolean] Whether to wait for the prediction to complete.
63
72
  #
64
73
  # @return [ReplicateClient::Prediction]
65
- def create_for_official_model!(model:, input:, webhook_url: nil, webhook_events_filter: nil)
74
+ def create_for_official_model!(model:, input:, webhook_url: nil, webhook_events_filter: nil, sync: false)
66
75
  model_path = model.is_a?(Model) ? model.path : Model.build_path(**Model.parse_model_name(model))
67
76
 
68
77
  args = {
@@ -71,7 +80,9 @@ module ReplicateClient
71
80
  webhook_events_filter: webhook_events_filter&.map(&:to_s)
72
81
  }
73
82
 
74
- prediction = ReplicateClient.client.post("#{model_path}#{INDEX_PATH}", args)
83
+ headers = sync ? { "Prefer" => "wait" } : {}
84
+
85
+ prediction = ReplicateClient.client.post("#{model_path}#{INDEX_PATH}", args, headers:)
75
86
 
76
87
  new(prediction)
77
88
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReplicateClient
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replicate-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Player
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-02 00:00:00.000000000 Z
11
+ date: 2025-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday