replicate-rails 0.1.0 → 0.1.1

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: 187cc3b85a25e4c4affcf809fd9287f86eb3a59e7cd972fb4efa4ec05bf683e6
4
- data.tar.gz: 9e11f3b84e40377fab28a1124cc5e2cfdcb076c0c229afc27e4b7d6315894a16
3
+ metadata.gz: d67d82a77422c0855515d26493290cb270a60a02c80be16417dba9a21cdf434d
4
+ data.tar.gz: 3a9f6b98554f066aee9a886c066547b9d0a22976c825cad22b758a43e30ac756
5
5
  SHA512:
6
- metadata.gz: 93ff4864a34282eef64be50f62ee52ebbe4f62ec00a5662ad6a3805b4e4621fe8c29d735836aa211395a4a90828ed07fb677426381cbdac3c95c7a4f772fca17
7
- data.tar.gz: b3f43be20e66a254406b7f0221ea949e38e0894a239821db5e4cab03f11063e983c645feed158fcf6f2c055f765ecd8577bb8ef7c20ace1d224b984deaeb3292
6
+ metadata.gz: e3766b6a8e3abf0d042389bf903901bbe955e24354da3e9d6a6057d70a8875493de676f5eac84b5fffcedd413d32cd029d8755ac1b690eb7a850f142374a7cb4
7
+ data.tar.gz: cc7fc5ce9377ac2c1c3677d96b02516d47f290ed7cc75019c1be3ae26fd5176397efe73d1f24768c8705a8bf99c2a2ac0ba8fbce6f4cc1c5a04fe7a6b5f6b3ae
data/Gemfile CHANGED
@@ -1,12 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in replicate-rails.gemspec
6
4
  gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "minitest", "~> 5.0"
11
-
12
- gem "rubocop", "~> 1.21"
data/Gemfile.lock CHANGED
@@ -1,25 +1,119 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- replicate-rails (0.1.0)
4
+ replicate-rails (0.1.1)
5
+ activesupport (>= 3.1)
5
6
  replicate-ruby (~> 0.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ actioncable (7.0.4)
12
+ actionpack (= 7.0.4)
13
+ activesupport (= 7.0.4)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.4)
17
+ actionpack (= 7.0.4)
18
+ activejob (= 7.0.4)
19
+ activerecord (= 7.0.4)
20
+ activestorage (= 7.0.4)
21
+ activesupport (= 7.0.4)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.4)
27
+ actionpack (= 7.0.4)
28
+ actionview (= 7.0.4)
29
+ activejob (= 7.0.4)
30
+ activesupport (= 7.0.4)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (7.0.4)
37
+ actionview (= 7.0.4)
38
+ activesupport (= 7.0.4)
39
+ rack (~> 2.0, >= 2.2.0)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.4)
44
+ actionpack (= 7.0.4)
45
+ activerecord (= 7.0.4)
46
+ activestorage (= 7.0.4)
47
+ activesupport (= 7.0.4)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.4)
51
+ activesupport (= 7.0.4)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.4)
57
+ activesupport (= 7.0.4)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.4)
60
+ activesupport (= 7.0.4)
61
+ activerecord (7.0.4)
62
+ activemodel (= 7.0.4)
63
+ activesupport (= 7.0.4)
64
+ activestorage (7.0.4)
65
+ actionpack (= 7.0.4)
66
+ activejob (= 7.0.4)
67
+ activerecord (= 7.0.4)
68
+ activesupport (= 7.0.4)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.4)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
10
76
  addressable (2.8.1)
11
77
  public_suffix (>= 2.0.2, < 6.0)
12
78
  ast (2.4.2)
79
+ builder (3.2.4)
80
+ byebug (11.1.3)
13
81
  coderay (1.1.3)
82
+ concurrent-ruby (1.1.10)
83
+ crass (1.0.6)
84
+ erubi (1.11.0)
14
85
  faraday (2.6.0)
15
86
  faraday-net_http (>= 2.0, < 3.1)
16
87
  ruby2_keywords (>= 0.0.4)
17
88
  faraday-net_http (3.0.1)
18
89
  faraday-retry (2.0.0)
19
90
  faraday (~> 2.0)
91
+ globalid (1.0.0)
92
+ activesupport (>= 5.0)
93
+ i18n (1.12.0)
94
+ concurrent-ruby (~> 1.0)
20
95
  json (2.6.2)
96
+ loofah (2.19.0)
97
+ crass (~> 1.0.2)
98
+ nokogiri (>= 1.5.9)
99
+ mail (2.7.1)
100
+ mini_mime (>= 0.1.1)
101
+ marcel (1.0.2)
21
102
  method_source (1.0.0)
103
+ mini_mime (1.1.2)
22
104
  minitest (5.16.3)
105
+ mocha (1.15.0)
106
+ net-imap (0.3.1)
107
+ net-protocol
108
+ net-pop (0.1.2)
109
+ net-protocol
110
+ net-protocol (0.1.3)
111
+ timeout
112
+ net-smtp (0.3.2)
113
+ net-protocol
114
+ nio4r (2.5.8)
115
+ nokogiri (1.13.8-x86_64-darwin)
116
+ racc (~> 1.4)
23
117
  parallel (1.22.1)
24
118
  parser (3.1.2.1)
25
119
  ast (~> 2.4.1)
@@ -27,10 +121,40 @@ GEM
27
121
  coderay (~> 1.1)
28
122
  method_source (~> 1.0)
29
123
  public_suffix (5.0.0)
124
+ racc (1.6.0)
125
+ rack (2.2.4)
126
+ rack-test (2.0.2)
127
+ rack (>= 1.3)
128
+ rails (7.0.4)
129
+ actioncable (= 7.0.4)
130
+ actionmailbox (= 7.0.4)
131
+ actionmailer (= 7.0.4)
132
+ actionpack (= 7.0.4)
133
+ actiontext (= 7.0.4)
134
+ actionview (= 7.0.4)
135
+ activejob (= 7.0.4)
136
+ activemodel (= 7.0.4)
137
+ activerecord (= 7.0.4)
138
+ activestorage (= 7.0.4)
139
+ activesupport (= 7.0.4)
140
+ bundler (>= 1.15.0)
141
+ railties (= 7.0.4)
142
+ rails-dom-testing (2.0.3)
143
+ activesupport (>= 4.2.0)
144
+ nokogiri (>= 1.6)
145
+ rails-html-sanitizer (1.4.3)
146
+ loofah (~> 2.3)
147
+ railties (7.0.4)
148
+ actionpack (= 7.0.4)
149
+ activesupport (= 7.0.4)
150
+ method_source
151
+ rake (>= 12.2)
152
+ thor (~> 1.0)
153
+ zeitwerk (~> 2.5)
30
154
  rainbow (3.1.1)
31
155
  rake (13.0.6)
32
156
  regexp_parser (2.6.0)
33
- replicate-ruby (0.1.1)
157
+ replicate-ruby (0.1.2)
34
158
  addressable
35
159
  faraday (>= 2.0)
36
160
  faraday-retry
@@ -49,14 +173,25 @@ GEM
49
173
  parser (>= 3.1.1.0)
50
174
  ruby-progressbar (1.11.0)
51
175
  ruby2_keywords (0.0.5)
176
+ thor (1.2.1)
177
+ timeout (0.3.0)
178
+ tzinfo (2.0.5)
179
+ concurrent-ruby (~> 1.0)
52
180
  unicode-display_width (2.3.0)
181
+ websocket-driver (0.7.5)
182
+ websocket-extensions (>= 0.1.0)
183
+ websocket-extensions (0.1.5)
184
+ zeitwerk (2.6.1)
53
185
 
54
186
  PLATFORMS
55
187
  x86_64-darwin-21
56
188
 
57
189
  DEPENDENCIES
190
+ byebug
58
191
  minitest (~> 5.0)
192
+ mocha
59
193
  pry
194
+ rails (>= 6)
60
195
  rake (~> 13.0)
61
196
  replicate-rails!
62
197
  rubocop (~> 1.21)
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # ReplicateRails
1
+ # Replicate Rails Gem
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/replicate/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This gem bundles the [replicate-ruby](https://github.com/dreamingtulpa/replicate-ruby) gem and adds webhook support for replicate.com.
6
4
 
7
5
  ## Installation
8
6
 
@@ -12,17 +10,39 @@ Add this line to your application's Gemfile:
12
10
  gem 'replicate-rails'
13
11
  ```
14
12
 
15
- And then execute:
13
+ ## Usage
16
14
 
17
- $ bundle install
15
+ Setup an initializer and webhook adapter class:
18
16
 
19
- Or install it yourself as:
17
+ ```ruby
18
+ # config/initializers/replicate.rb
19
+ Replicate.client.api_token = "your-api-token"
20
+
21
+ ReplicateRails.configure do |config|
22
+ config.webhook_adapter = ReplicateWebhook.new
23
+ end
24
+
25
+ class ReplicateWebhook
26
+ def call(prediction)
27
+ # do your thing
28
+ end
29
+ end
30
+ ```
20
31
 
21
- $ gem install replicate-rails
32
+ and mount the route:
22
33
 
23
- ## Usage
34
+ ```ruby
35
+ # config/routes.rb
36
+ mount ReplicateRails::Engine => "/replicate/webhook"
37
+ ```
38
+
39
+ Now you can run predictions as follows:
24
40
 
25
- TODO: Write usage instructions here
41
+ ```
42
+ model = Replicate.client.retrieve_model("stability-ai/stable-diffusion")
43
+ version = model.latest_version
44
+ version.predict(prompt: "a beautiful sunset", "https://yourdomain.tld/replicate/webhook")
45
+ ```
26
46
 
27
47
  ## Development
28
48
 
@@ -0,0 +1,20 @@
1
+ module ReplicateRails
2
+ class WebhookController < ActionController::Base
3
+ if Rails.application.config.action_controller.default_protect_from_forgery
4
+ skip_before_action :verify_authenticity_token
5
+ end
6
+
7
+ def event
8
+ ReplicateRails.config.webhook_adapter.call(prediction)
9
+ head :ok
10
+ rescue ReplicateRails::WebhookError
11
+ head :unprocessable_entity
12
+ end
13
+
14
+ private
15
+
16
+ def prediction
17
+ Replicate::Record::Prediction.new(Replicate.client, JSON.parse(request.body.read))
18
+ end
19
+ end
20
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ ReplicateRails::Engine.routes.draw do
2
+ root to: 'webhook#event', via: :post
3
+ end
@@ -0,0 +1,5 @@
1
+ module ReplicateRails
2
+ class Configuration
3
+ attr_accessor :webhook_adapter
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module ReplicateRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ReplicateRails
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReplicateRails
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,8 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "replicate_rails/version"
3
+ require "replicate"
4
+ require "replicate_rails/version"
5
+ require "replicate_rails/engine" if defined?(Rails)
6
+
7
+ require "replicate_rails/configuration"
4
8
 
5
9
  module ReplicateRails
6
10
  class Error < StandardError; end
7
- # Your code goes here...
11
+ class WebhookError < Error; end
12
+
13
+ class << self
14
+ def config
15
+ @config ||= Configuration.new
16
+ end
17
+
18
+ def configure
19
+ yield(config)
20
+ end
21
+ end
8
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replicate-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dreaming Tulpa
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: replicate-ruby
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,90 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.21'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.21'
41
139
  description:
42
140
  email:
43
141
  - hey@dreamingtulpa.com
@@ -51,7 +149,11 @@ files:
51
149
  - Gemfile.lock
52
150
  - README.md
53
151
  - Rakefile
152
+ - app/controllers/replicate_rails/webhook_controller.rb
153
+ - config/routes.rb
54
154
  - lib/replicate_rails.rb
155
+ - lib/replicate_rails/configuration.rb
156
+ - lib/replicate_rails/engine.rb
55
157
  - lib/replicate_rails/version.rb
56
158
  - sig/replicate_rails.rb
57
159
  homepage: https://github.com/dreamingtulpa/replicate-rails