automatic1111 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: 64fba0709fdd2df4befa859bb0ffb2d440806a5da1a43e4f116f8c90eb90c388
4
- data.tar.gz: 94e0fcdc2affc297686c28118d05495a87969387b9e631bc0ae0f0e30ad88d3d
3
+ metadata.gz: 9a8c1b57810fbb72e37672ce301f69562f46e9f4464b3ed581c590d0953f817d
4
+ data.tar.gz: 5be97962003ad08c0298fd475561ae8020da3fcf59d35fbbaadf5b2bda6a732f
5
5
  SHA512:
6
- metadata.gz: fdd1482b5a057331f20688c24eb9c5fe6012563cc024f43d6b4b0b76e3ae94ae5303ca4bae855fd78d8e08a2ac2373893f7a7163389c44887d5607d0d128e804
7
- data.tar.gz: 8191fc84cdfaeae328d24748b322673aad8266fab3cc3f6892eded79ee8c4034ffe932d8de37c4c461edafdfece55517153a8511d6d3feefae6e77afb204746c
6
+ metadata.gz: 38a68f00f0c8673f458ad17d16ab55c300b3b33c56401d2b2a4b270fea8fb7a74e02dcc7e3b12c666a63a25c54f8483c861ca9759e39fbc9c809960d614979a9
7
+ data.tar.gz: 0031e4b51cee3bda637662d454ab37321fa79f8bfbbd2987c7dffce35d36c743e3632dac9bcf839fe7501a71014baaa972add34c574335d259b6a7b174a587d1
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ automatic1111 (0.1.0)
5
+ addressable
6
+ faraday (>= 2.0)
7
+ faraday-multipart
8
+ faraday-retry
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.8.1)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ ast (2.4.2)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ crack (0.4.5)
19
+ rexml
20
+ faraday (2.7.4)
21
+ faraday-net_http (>= 2.0, < 3.1)
22
+ ruby2_keywords (>= 0.0.4)
23
+ faraday-multipart (1.0.4)
24
+ multipart-post (~> 2)
25
+ faraday-net_http (3.0.2)
26
+ faraday-retry (2.0.0)
27
+ faraday (~> 2.0)
28
+ hashdiff (1.0.1)
29
+ json (2.6.3)
30
+ method_source (1.0.0)
31
+ minitest (5.17.0)
32
+ multipart-post (2.3.0)
33
+ parallel (1.22.1)
34
+ parser (3.2.1.0)
35
+ ast (~> 2.4.1)
36
+ pry (0.14.2)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ public_suffix (5.0.1)
40
+ rainbow (3.1.1)
41
+ rake (13.0.6)
42
+ regexp_parser (2.7.0)
43
+ rexml (3.2.5)
44
+ rubocop (1.46.0)
45
+ json (~> 2.3)
46
+ parallel (~> 1.10)
47
+ parser (>= 3.2.0.0)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ regexp_parser (>= 1.8, < 3.0)
50
+ rexml (>= 3.2.5, < 4.0)
51
+ rubocop-ast (>= 1.26.0, < 2.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 2.4.0, < 3.0)
54
+ rubocop-ast (1.26.0)
55
+ parser (>= 3.2.1.0)
56
+ ruby-progressbar (1.11.0)
57
+ ruby2_keywords (0.0.5)
58
+ unicode-display_width (2.4.2)
59
+ webmock (3.18.1)
60
+ addressable (>= 2.8.0)
61
+ crack (>= 0.3.2)
62
+ hashdiff (>= 0.4.0, < 2.0.0)
63
+
64
+ PLATFORMS
65
+ arm64-darwin-22
66
+
67
+ DEPENDENCIES
68
+ automatic1111!
69
+ byebug
70
+ minitest (~> 5.0)
71
+ pry
72
+ rake (~> 13.0)
73
+ rubocop (~> 1.21)
74
+ webmock
75
+
76
+ BUNDLED WITH
77
+ 2.4.6
data/README.md CHANGED
@@ -13,7 +13,17 @@ gem 'automatic1111'
13
13
 
14
14
  ## Usage
15
15
 
16
- TODO: Write usage instructions here
16
+ ```ruby
17
+ # Setup client
18
+ client = Automatic1111::Client.new(api_endpoint_url: '<http://127.0.0.1:7860 or
19
+ https://xxxxxx.gradio.live')
20
+
21
+ # Authenticate
22
+ client.post('/login', params: { username: 'username', password: 'password' }, headers: { 'Content-Type' => 'application/x-www-form-urlencoded' })
23
+
24
+ # Call endpoint
25
+ client.post('/sdapi/v1/txt2img', params: { prompt: 'test' })
26
+ ```
17
27
 
18
28
  ## Development
19
29
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "automatic1111/configurable"
4
+ require "automatic1111/connection"
5
+
6
+ module Automatic1111
7
+ class Client
8
+ include Automatic1111::Configurable
9
+ include Automatic1111::Connection
10
+
11
+ def initialize(options = {})
12
+ # Use options passed in, but fall back to module defaults
13
+ Automatic1111::Configurable.keys.each do |key|
14
+ value = options.key?(key) ? options[key] : Automatic1111.instance_variable_get(:"@#{key}")
15
+ instance_variable_set(:"@#{key}", value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Automatic1111
4
+ module Configurable
5
+ attr_accessor :api_endpoint_url, :cookie
6
+
7
+ class << self
8
+ # List of configurable keys for {Datatrans::Client}
9
+ # @return [Array] of option keys
10
+ def keys
11
+ @keys ||= %i[api_endpoint_url cookie]
12
+ end
13
+ end
14
+
15
+ # Set configuration options using a block
16
+ def configure
17
+ yield self
18
+ end
19
+
20
+ private
21
+
22
+ def options
23
+ Hash[Automatic1111::Configurable.keys.map { |key| [key, send(key)] }]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'byebug'
4
+ require "faraday"
5
+ require "faraday/net_http"
6
+ require "faraday/retry"
7
+ require "faraday/multipart"
8
+ require "addressable/uri"
9
+
10
+ module Automatic1111
11
+ # Network layer for API clients.
12
+ module Connection
13
+ def get(url, params: {}, headers: {})
14
+ request :get, url, params, headers: headers
15
+ end
16
+
17
+ def post(url, params: {}, headers: {})
18
+ request :post, url, params, headers: headers
19
+ end
20
+
21
+ def put(url, params: {}, headers: {})
22
+ request :put, url, params, headers: headers
23
+ end
24
+
25
+ def patch(url, params: {}, headers: {})
26
+ request :patch, url, params, headers: headers
27
+ end
28
+
29
+ def delete(url, params: {}, headers: {})
30
+ request :delete, url, params, headers: headers
31
+ end
32
+
33
+ def head(url, params: {}, headers: {})
34
+ request :head, url, params, headers: headers
35
+ end
36
+
37
+ # Response for last HTTP request
38
+ #
39
+ # @return [Sawyer::Response]
40
+ def last_response
41
+ @last_response if defined? @last_response
42
+ end
43
+
44
+ private
45
+
46
+ def request(method, path, data, headers: {})
47
+ headers['Content-Type'] ||= 'application/json'
48
+ headers['Cookie'] ||= cookie
49
+
50
+ connection = Faraday.new(url: api_endpoint_url) do |conn|
51
+ conn.request :retry
52
+ conn.adapter :net_http
53
+ end
54
+
55
+ # @last_response = connection.send(method, Addressable::URI.parse(path.to_s).normalize.to_s, data)
56
+ @last_response = connection.send(method, Addressable::URI.parse(path.to_s).normalize.to_s) do |req|
57
+ req.headers = headers
58
+ case headers["Content-Type"]
59
+ when 'application/x-www-form-urlencoded'
60
+ req.body = URI.encode_www_form(data)
61
+ else
62
+ req.body = data.to_json
63
+ end
64
+ end
65
+
66
+ case @last_response.status
67
+ when 400
68
+ raise Error, "#{@last_response.status} #{@last_response.reason_phrase}: #{JSON.parse(@last_response.body)}"
69
+ else
70
+ self.cookie = @last_response.headers['set-cookie'] if @last_response.headers['set-cookie']
71
+
72
+ case headers["Content-Type"]
73
+ when 'application/json'
74
+ JSON.parse(@last_response.body)
75
+ else
76
+ @last_response.body
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Automatic1111
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/automatic1111.rb CHANGED
@@ -1,8 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "automatic1111/version"
4
+ require_relative "automatic1111/client"
4
5
 
5
6
  module Automatic1111
6
7
  class Error < StandardError; end
7
- # Your code goes here...
8
+
9
+ class << self
10
+ include Automatic1111::Configurable
11
+
12
+ def client
13
+ return @client if defined?(@client)
14
+ @client = Automatic1111::Client.new(options)
15
+ end
16
+ end
8
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automatic1111
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
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-multipart
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: addressable
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description:
84
112
  email:
85
113
  - hey@dreamingtulpa.com
@@ -90,9 +118,13 @@ files:
90
118
  - ".rubocop.yml"
91
119
  - CHANGELOG.md
92
120
  - Gemfile
121
+ - Gemfile.lock
93
122
  - README.md
94
123
  - Rakefile
95
124
  - lib/automatic1111.rb
125
+ - lib/automatic1111/client.rb
126
+ - lib/automatic1111/configurable.rb
127
+ - lib/automatic1111/connection.rb
96
128
  - lib/automatic1111/version.rb
97
129
  - sig/automatic1111.rbs
98
130
  homepage: https://github.com/dreamingtulpa/automatic1111-ruby