├── .github └── workflows │ └── main.yml ├── .gitignore ├── .rubocop.yml ├── CHANGELOG.md ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app └── controllers │ └── replicate_rails │ └── webhook_controller.rb ├── bin ├── console └── setup ├── config └── routes.rb ├── lib ├── replicate_rails.rb └── replicate_rails │ ├── configuration.rb │ ├── engine.rb │ └── version.rb ├── replicate-rails.gemspec ├── sig └── replicate_rails.rb └── test ├── controllers └── replicate_rails │ └── webhook_controller_test.rb ├── dummy ├── Rakefile ├── app │ ├── controllers │ │ └── application_controller.rb │ ├── helpers │ │ └── application_helper.rb │ ├── models │ │ ├── application_record.rb │ │ └── replicate_webhook.rb │ └── views │ │ └── layouts │ │ └── application.html.erb ├── config.ru └── config │ ├── application.rb │ ├── boot.rb │ ├── environment.rb │ ├── environments │ └── test.rb │ └── routes.rb ├── fixtures └── evt_prediction_completed.json ├── replicate_rails_test.rb └── test_helper.rb /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Ruby 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up Ruby 17 | uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 18 | with: 19 | ruby-version: '3.1' 20 | - name: Install dependencies 21 | run: bundle install 22 | - name: Run tests 23 | run: bundle exec rake test 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | /.bundle/ 3 | /.yardoc 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | /test/dummy/tmp 11 | /test/dummy/log 12 | .byebug_history 13 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | TargetRubyVersion: 2.6 3 | 4 | Style/StringLiterals: 5 | Enabled: true 6 | EnforcedStyle: double_quotes 7 | 8 | Style/StringLiteralsInInterpolation: 9 | Enabled: true 10 | EnforcedStyle: double_quotes 11 | 12 | Layout/LineLength: 13 | Max: 120 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [Unreleased] 2 | 3 | ## [0.1.0] - 2022-10-14 4 | 5 | - Initial release 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | gemspec 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | replicate-rails (0.1.1) 5 | activesupport (>= 3.1) 6 | replicate-ruby (~> 0.1) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 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) 76 | addressable (2.8.1) 77 | public_suffix (>= 2.0.2, < 6.0) 78 | ast (2.4.2) 79 | builder (3.2.4) 80 | byebug (11.1.3) 81 | coderay (1.1.3) 82 | concurrent-ruby (1.1.10) 83 | crass (1.0.6) 84 | erubi (1.11.0) 85 | faraday (2.6.0) 86 | faraday-net_http (>= 2.0, < 3.1) 87 | ruby2_keywords (>= 0.0.4) 88 | faraday-net_http (3.0.1) 89 | faraday-retry (2.0.0) 90 | faraday (~> 2.0) 91 | globalid (1.0.0) 92 | activesupport (>= 5.0) 93 | i18n (1.12.0) 94 | concurrent-ruby (~> 1.0) 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) 102 | method_source (1.0.0) 103 | mini_mime (1.1.2) 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) 117 | parallel (1.22.1) 118 | parser (3.1.2.1) 119 | ast (~> 2.4.1) 120 | pry (0.14.1) 121 | coderay (~> 1.1) 122 | method_source (~> 1.0) 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) 154 | rainbow (3.1.1) 155 | rake (13.0.6) 156 | regexp_parser (2.6.0) 157 | replicate-ruby (0.1.2) 158 | addressable 159 | faraday (>= 2.0) 160 | faraday-retry 161 | rexml (3.2.5) 162 | rubocop (1.36.0) 163 | json (~> 2.3) 164 | parallel (~> 1.10) 165 | parser (>= 3.1.2.1) 166 | rainbow (>= 2.2.2, < 4.0) 167 | regexp_parser (>= 1.8, < 3.0) 168 | rexml (>= 3.2.5, < 4.0) 169 | rubocop-ast (>= 1.20.1, < 2.0) 170 | ruby-progressbar (~> 1.7) 171 | unicode-display_width (>= 1.4.0, < 3.0) 172 | rubocop-ast (1.21.0) 173 | parser (>= 3.1.1.0) 174 | ruby-progressbar (1.11.0) 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) 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) 185 | 186 | PLATFORMS 187 | x86_64-darwin-21 188 | 189 | DEPENDENCIES 190 | byebug 191 | minitest (~> 5.0) 192 | mocha 193 | pry 194 | rails (>= 6) 195 | rake (~> 13.0) 196 | replicate-rails! 197 | rubocop (~> 1.21) 198 | 199 | BUNDLED WITH 200 | 2.3.7 201 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Replicate Rails Gem 2 | 3 | This gem bundles the [replicate-ruby](https://github.com/dreamingtulpa/replicate-ruby) gem and adds webhook support for replicate.com. 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'replicate-rails', require: 'replicate_rails' 11 | ``` 12 | 13 | ## Usage 14 | 15 | Setup an initializer and webhook adapter class: 16 | 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 | ``` 31 | 32 | and mount the route: 33 | 34 | ```ruby 35 | # config/routes.rb 36 | mount ReplicateRails::Engine => "/replicate/webhook" 37 | ``` 38 | 39 | Now you can run predictions as follows: 40 | 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 | ``` 46 | 47 | ## Development 48 | 49 | 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. 50 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | require "rake/testtask" 5 | 6 | Rake::TestTask.new(:test) do |t| 7 | t.libs << "test" 8 | t.libs << "lib" 9 | t.test_files = FileList["test/**/*_test.rb"] 10 | end 11 | 12 | require "rubocop/rake_task" 13 | 14 | RuboCop::RakeTask.new 15 | 16 | task default: %i[test rubocop] 17 | -------------------------------------------------------------------------------- /app/controllers/replicate_rails/webhook_controller.rb: -------------------------------------------------------------------------------- 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 21 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "bundler/setup" 5 | require "replicate_rails" 6 | 7 | # You can add fixtures and/or initialization code here to make experimenting 8 | # with your gem easier. You can also use a different console, if you like. 9 | 10 | # (If you use this, don't forget to add pry to your Gemfile!) 11 | # require "pry" 12 | # Pry.start 13 | 14 | require "irb" 15 | IRB.start(__FILE__) 16 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | ReplicateRails::Engine.routes.draw do 2 | root to: 'webhook#event', via: :post 3 | end 4 | -------------------------------------------------------------------------------- /lib/replicate_rails.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "replicate" 4 | require "replicate_rails/version" 5 | require "replicate_rails/engine" if defined?(Rails) 6 | 7 | require "replicate_rails/configuration" 8 | 9 | module ReplicateRails 10 | class Error < StandardError; end 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 22 | end 23 | -------------------------------------------------------------------------------- /lib/replicate_rails/configuration.rb: -------------------------------------------------------------------------------- 1 | module ReplicateRails 2 | class Configuration 3 | attr_accessor :webhook_adapter 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/replicate_rails/engine.rb: -------------------------------------------------------------------------------- 1 | module ReplicateRails 2 | class Engine < ::Rails::Engine 3 | isolate_namespace ReplicateRails 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/replicate_rails/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ReplicateRails 4 | VERSION = "0.1.1" 5 | end 6 | -------------------------------------------------------------------------------- /replicate-rails.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "lib/replicate_rails/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "replicate-rails" 7 | spec.version = ReplicateRails::VERSION 8 | spec.authors = ["Dreaming Tulpa"] 9 | spec.email = ["hey@dreamingtulpa.com"] 10 | 11 | spec.summary = "Rails gem for Replicate" 12 | spec.homepage = "https://github.com/dreamingtulpa/replicate-rails" 13 | spec.required_ruby_version = ">= 2.6.0" 14 | 15 | # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" 16 | 17 | spec.metadata["homepage_uri"] = spec.homepage 18 | spec.metadata["source_code_uri"] = "https://github.com/dreamingtulpa/replicate-rails" 19 | spec.metadata["changelog_uri"] = "https://github.com/dreamingtulpa/replicate-rails/blob/master/CHANGELOG.md" 20 | 21 | # Specify which files should be added to the gem when it is released. 22 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 23 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 24 | `git ls-files -z`.split("\x0").reject do |f| 25 | (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) 26 | end 27 | end 28 | spec.bindir = "exe" 29 | spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } 30 | spec.require_paths = ["lib"] 31 | 32 | # Uncomment to register a new dependency of your gem 33 | spec.add_dependency "activesupport", ">= 3.1" 34 | spec.add_dependency "replicate-ruby", "~> 0.1" 35 | 36 | spec.add_development_dependency "pry" 37 | spec.add_development_dependency "byebug" 38 | spec.add_development_dependency "rails", ">= 6" 39 | spec.add_development_dependency "rake", "~> 13.0" 40 | spec.add_development_dependency "minitest", "~> 5.0" 41 | spec.add_development_dependency "mocha" 42 | spec.add_development_dependency "rubocop", "~> 1.21" 43 | 44 | # For more information and examples about making a new gem, check out our 45 | # guide at: https://bundler.io/guides/creating_gem.html 46 | end 47 | -------------------------------------------------------------------------------- /sig/replicate_rails.rb: -------------------------------------------------------------------------------- 1 | module ReplicateRails 2 | VERSION: String 3 | # See the writing guide of rbs: https://github.com/ruby/rbs#guides 4 | end 5 | -------------------------------------------------------------------------------- /test/controllers/replicate_rails/webhook_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ReplicateRails::WebhookControllerTest < ActionController::TestCase 4 | def payload 5 | @payload ||= File.read(File.join(FIXTURES_DIR, "evt_prediction_completed.json")).strip 6 | end 7 | 8 | setup do 9 | @routes = ReplicateRails::Engine.routes 10 | 11 | ReplicateRails.configure do |config| 12 | config.webhook_adapter = ReplicateWebhook.new 13 | end 14 | end 15 | 16 | test "should post prediction event" do 17 | ReplicateWebhook.any_instance.expects(:call).returns(true) 18 | post :event, format: :json, body: payload 19 | assert_response :success 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Dummy::Application.load_tasks 8 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/models/replicate_webhook.rb: -------------------------------------------------------------------------------- 1 | class ReplicateWebhook 2 | def call(prediction) 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | 8 | <%= stylesheet_link_tag "replicate_rails/application", media: "all" %> 9 | 10 | 11 | 12 | <%= yield %> 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Dummy::Application 5 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require "action_controller/railtie" 4 | 5 | require "replicate_rails" 6 | 7 | module Dummy 8 | class Application < Rails::Application 9 | # Settings in config/environments/* take precedence over those specified here. 10 | # Application configuration should go into files in config/initializers 11 | # -- all .rb files in that directory are automatically loaded. 12 | 13 | # Custom directories with classes and modules you want to be autoloadable. 14 | # config.autoload_paths += %W(#{config.root}/extras) 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | if File.exist?(gemfile) 5 | ENV['BUNDLE_GEMFILE'] = gemfile 6 | require 'bundler' 7 | Bundler.setup 8 | end 9 | 10 | $:.unshift File.expand_path('../../../../lib', __FILE__) 11 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | # config.whiny_nils = true 16 | 17 | # Configure eager load to avoid Rails 4 warning 18 | config.eager_load = false 19 | 20 | # Show full error reports and disable caching 21 | config.consider_all_requests_local = true 22 | config.action_controller.perform_caching = false 23 | 24 | # Raise exceptions instead of rendering exception templates 25 | config.action_dispatch.show_exceptions = false 26 | 27 | # Disable request forgery protection in test environment 28 | config.action_controller.allow_forgery_protection = false 29 | 30 | # Tell Action Mailer not to deliver emails to the real world. 31 | # The :test delivery method accumulates sent emails in the 32 | # ActionMailer::Base.deliveries array. 33 | # config.action_mailer.delivery_method = :test 34 | 35 | # Raise exception on mass assignment protection for Active Record models 36 | # config.active_record.mass_assignment_sanitizer = :strict 37 | 38 | # Print deprecation notices to the stderr 39 | config.active_support.deprecation = :stderr 40 | end 41 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | mount ReplicateRails::Engine => "/replicate/events" 3 | end 4 | -------------------------------------------------------------------------------- /test/fixtures/evt_prediction_completed.json: -------------------------------------------------------------------------------- 1 | {"completed_at":"2022-10-13T14:05:57.574265Z","created_at":"2022-10-13T14:05:45.239516Z","error":null,"hardware":"gpu-a100","id":"xhnjhe4afrb7pljcdaodhw57ue","input":{"prompt":"a beautiful sunrise"},"logs":"Using seed: 10837\n\n0it [00:00, ?it/s]\n2it [00:00, 13.72it/s]\n4it [00:00, 13.71it/s]\n6it [00:00, 14.00it/s]\n8it [00:00, 14.02it/s]\n10it [00:00, 14.10it/s]\n12it [00:00, 14.12it/s]\n14it [00:00, 14.06it/s]\n16it [00:01, 14.08it/s]\n18it [00:01, 14.12it/s]\n20it [00:01, 14.23it/s]\n22it [00:01, 14.15it/s]\n24it [00:01, 14.21it/s]\n26it [00:01, 14.21it/s]\n28it [00:01, 13.99it/s]\n30it [00:02, 14.16it/s]\n32it [00:02, 14.20it/s]\n34it [00:02, 14.15it/s]\n36it [00:02, 14.21it/s]\n38it [00:02, 14.21it/s]\n40it [00:02, 14.25it/s]\n42it [00:02, 14.10it/s]\n44it [00:03, 14.21it/s]\n46it [00:03, 14.19it/s]\n48it [00:03, 14.21it/s]\n50it [00:03, 14.31it/s]\n50it [00:03, 14.15it/s]","metrics":{"predict_time":3.981787},"output":["https://replicate.delivery/pbxt/F94indaerA17AqHWJIHYpyqQZcuTYfd5IrC6cyujfkeVUzVfB/out-0.png"],"started_at":"2022-10-13T14:05:53.592478Z","status":"succeeded","urls":{"get":"https://api.replicate.com/v1/predictions/xhnjhe4afrb7pljcdaodhw57ue","cancel":"https://api.replicate.com/v1/predictions/xhnjhe4afrb7pljcdaodhw57ue/cancel"},"version":"a9758cbfbd5f3c2094457d996681af52552901775aa2d6dd0b17fd15df959bef","webhook_completed":null} 2 | -------------------------------------------------------------------------------- /test/replicate_rails_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | 5 | class ReplicateRailsTest < Minitest::Test 6 | def test_that_it_has_a_version_number 7 | refute_nil ::ReplicateRails::VERSION 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Configure Rails Environment 4 | ENV["RAILS_ENV"] = "test" 5 | 6 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 7 | require "rails/test_help" 8 | require "mocha/minitest" 9 | require "byebug" 10 | 11 | Rails.backtrace_cleaner.remove_silencers! 12 | 13 | # Load support files 14 | FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures') 15 | --------------------------------------------------------------------------------