replicate-ruby 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c894d68b6c7c1dcc1bfdb5fbe0067a1485c3e918029f3d1fd5139ae8acbcc8b
4
- data.tar.gz: 00de848d1fc16197959283ae65c136e1723eca8c15a2a0556bb08d84e9a06a2f
3
+ metadata.gz: 6ad53464a361eeeb5bac077b1e7e997eceae6e70648634ac12d8139f6d3926cc
4
+ data.tar.gz: a7304c1a101ee4b9bfb0dfccc76af2b0d55805bbd856125edf6ee7432e2c0034
5
5
  SHA512:
6
- metadata.gz: b3c7f2edbba1a0e3c572e7f1f9e614336e8dd015f7683f094fda645f942c75b8abf9dac43719625761ad5b5ebbb00e65ef5f71741c1b1c0d12f2e7d3c72df75e
7
- data.tar.gz: ddced9835e3e37acd8c132be0036519b63b4a5adca1332ee33aef2dd75a3830112df937492aa90e5337007db24252bacdae1cc404e063e11ac3e0608c8498566
6
+ metadata.gz: ef7e5a987822959b24a9872b76d6728983b7857c4d08339b2b56e6d24ce98b433fc961af0128a4ece3b8af36bb13ebd24570515557a3b6ff7385f4d09318cf72
7
+ data.tar.gz: c43a37df64ea431e77b217803a3b4d86d5e092e01d4bf7d2e6d3347e5631b158ce7167edbbb520cd0418f03200e2ca44a69f618a54cd04a07da4d0d407c88bd1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- replicate-ruby (0.1.0)
4
+ replicate-ruby (0.1.1)
5
5
  addressable
6
6
  faraday (>= 2.0)
7
7
  faraday-retry
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Replicate Ruby client
2
2
 
3
- This is a Ruby client for Replicate. It lets you run models from your Ruby code and do various other things on Replicate.
3
+ This is a Ruby client for [Replicate](https://replicate.com/). It lets you run models from your Ruby code and do various other things on Replicate.
4
4
 
5
5
  ## Installation
6
6
 
@@ -28,7 +28,7 @@ model = Replicate.client.retrieve_model("stability-ai/stable-diffusion")
28
28
  version = model.latest_version
29
29
 
30
30
  # List of versions
31
- version = Replicate.client.retrieve_model("stability-ai/stable-diffusion", version: all)
31
+ version = Replicate.client.retrieve_model("stability-ai/stable-diffusion", version: :all)
32
32
 
33
33
  # Specific version
34
34
  version = Replicate.client.retrieve_model("stability-ai/stable-diffusion", version: "<id>")
@@ -39,10 +39,7 @@ And then run predictions on it:
39
39
  ```ruby
40
40
  prediction = version.predict(prompt: "a handsome teddy bear")
41
41
 
42
- # Optionally you can submit a webhook url for replicate to send a POST request once a prediction has completed
43
- prediction = version.predict(prompt: "a handsome teddy bear", "https://webhook.url/path")
44
-
45
- # Or manually refetch predictions
42
+ # manually refetch the prediction status
46
43
  prediction = prediction.refetch
47
44
 
48
45
  # or cancel a running prediction
@@ -50,14 +47,13 @@ prediction = prediction.cancel
50
47
 
51
48
  # and if a prediction returns with status succeeded, you can retrieve the output
52
49
  output = prediction.output
50
+
51
+ # Optionally you can submit a webhook url for replicate to send a POST request once a prediction has completed
52
+ prediction = version.predict(prompt: "a handsome teddy bear", "https://webhook.url/path") # call predict
53
+ id = prediction.id # store prediction id in your backend
54
+ prediction = Replicate.client.retrieve_prediction(id) # retrieve prediction during webhook with id from backend
53
55
  ```
54
56
 
55
57
  ## Development
56
58
 
57
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
-
59
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
-
61
- ## Contributing
62
-
63
- Bug reports and pull requests are welcome on GitHub at https://github.com/YOUR_GITHUB_USERNAME/replicate-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/YOUR_GITHUB_USERNAME/replicate-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -3,33 +3,24 @@
3
3
  module Replicate
4
4
  module Record
5
5
  class Base
6
+ attr_accessor :data
7
+
6
8
  def initialize(client, params)
7
9
  @client = client
8
- self.assign_attributes = params
9
- end
10
-
11
- def assign_attributes=(params)
12
- params = params.instance_variables_hash if params.is_a?(self.class)
13
- params.each do |key, value|
14
- instance_variable_set("@#{key}", value)
15
- end
10
+ @data = params
16
11
  end
17
12
 
18
13
  def method_missing(method_name, *args, &block)
19
- if instance_variables.include? :"@#{method_name}"
20
- instance_variable_get "@#{method_name}"
14
+ if data.key? method_name.to_s
15
+ data[method_name.to_s]
21
16
  else
22
17
  super
23
18
  end
24
19
  end
25
20
 
26
- def instance_variables_hash
27
- Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] } ]
28
- end
29
-
30
21
  def inspect
31
22
  string = "#<#{self.class.name}:#{object_id} "
32
- fields = instance_variables_hash.except("client").map { |attr, value| "#{attr}: #{value.inspect}" }
23
+ fields = data.map { |attr, value| "#{attr}: #{value.inspect}" }
33
24
  string << fields.join(", ") << ">"
34
25
  end
35
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Replicate
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replicate-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Puglisi
8
- autorequire:
7
+ - Dreaming Tulpa
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-13 00:00:00.000000000 Z
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -80,9 +80,9 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
- - daniel@codegestalt.com
85
+ - hey@dreamingtulpa.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -105,13 +105,13 @@ files:
105
105
  - lib/replicate/record/prediction.rb
106
106
  - lib/replicate/version.rb
107
107
  - sig/replicate/ruby.rbs
108
- homepage: https://github.com/danielpuglisi/replicate-ruby
108
+ homepage: https://github.com/dreamingtulpa/replicate-ruby
109
109
  licenses: []
110
110
  metadata:
111
- homepage_uri: https://github.com/danielpuglisi/replicate-ruby
112
- source_code_uri: https://github.com/danielpuglisi/replicate-ruby
113
- changelog_uri: https://github.com/danielpuglisi/replicate-ruby/blob/master/CHANGELOG.md
114
- post_install_message:
111
+ homepage_uri: https://github.com/dreamingtulpa/replicate-ruby
112
+ source_code_uri: https://github.com/dreamingtulpa/replicate-ruby
113
+ changelog_uri: https://github.com/dreamingtulpa/replicate-ruby/blob/master/CHANGELOG.md
114
+ post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths:
117
117
  - lib
@@ -126,8 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.3.7
130
- signing_key:
129
+ rubygems_version: 3.0.3.1
130
+ signing_key:
131
131
  specification_version: 4
132
132
  summary: Ruby client for Replicate
133
133
  test_files: []