userapi-ai 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8e731075ee42254e2b5449b12c471ad38ec7b17f49ed35c27e1f8b9cb3ab994
4
+ data.tar.gz: 5649910f890faa5412886612a3a615e0e6dcfeead93a874d2bc8d018082f6f60
5
+ SHA512:
6
+ metadata.gz: b5f8753fb545c528159d891f6164adeac1a2aab4f76679c8893a73fe27c9eec19a9d406c7c22c7e3c114d5438e36f60cac32648b17aa98724f63081e96e5ee88
7
+ data.tar.gz: c7f0caef35c18a90a87c9747d85c0de3cec320ef9796de7946d20789ceffafc376794f2316c15786ef12bd9a255a55893f2cd7e18e5352f8179ceefa2d486f08
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-03-24
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at smolev@me.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Smolev Denis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # Midjourney Ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/userapi-ai.svg)](https://badge.fury.io/rb/userapi-ai)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/neonix20b/userapi-ai/blob/main/LICENSE.txt)
5
+
6
+ Userapi.ai is an awesome tool that brings great value to products.
7
+ This gem was created to facilitate Ruby and also Rails applications to use all services of Userapi.ai:
8
+ - Midjourney
9
+
10
+ ## Installation
11
+
12
+ Add the following to your Gemfile:
13
+
14
+ ```ruby
15
+ gem "userapi-ai"
16
+ ```
17
+
18
+ Or install with:
19
+
20
+ ```shell
21
+ gem install userapi-ai
22
+ ```
23
+
24
+ and require with:
25
+
26
+ ```ruby
27
+ require "userapi-ai"
28
+ ```
29
+
30
+ Run `bundle install`.
31
+
32
+ That's it. You are now ready to go!
33
+
34
+ ## Usage
35
+
36
+ Make sure you have a
37
+ - Discord Account or create one at [Discord](https://discord.com)
38
+ - A Midjourney account or sign up at [Midjourney](https://www.midjourney.com)
39
+ - A Midjourney Paid plan to use this gem or sign up at [Midjourney Plans](https://www.midjourney.com/account/)
40
+ - A Userapi.ai Paid plan at [Userapi.ai](https://userapi.ai/)
41
+
42
+ After signing in, you can get your Discord token by checking out any message request you send in the browser.
43
+ You can do this by opening the developer tools in your browser and going to the network tab.
44
+ Then send a message in any channel and look for the request to `messages` in the network tab.
45
+ Check out the Request Headers and look for the `authorization` header. Copy the value of the header and use it as your Discord User Tokens.
46
+
47
+ ### Configuration
48
+
49
+ Once you have your Userapi.ai Token, you can configure the gem with:
50
+
51
+ Open up the initializer file `config/initializers/userapi.rb` and add your API Key as the following:
52
+
53
+ ```ruby
54
+ UserapiAi.configure do |config|
55
+ config.access_token = ENV["USERAPI_USER_TOKEN"]
56
+ end
57
+ ```
58
+
59
+ ### Imagine
60
+
61
+ Imagine is a Midjourney command that allows you to use AI to generate images.
62
+ You can use it to generate images of people, animals, objects, and anything else you can imagine.
63
+
64
+ #### Basic Usage
65
+
66
+ #### Using the /imagine command
67
+
68
+ ```ruby
69
+ client = UserapiAi::Client.new(service: :midjourney)
70
+ result = client.imagine(prompt: "nice girl")
71
+ or
72
+ result = client.imagine(prompt: "nice girl",
73
+ webhook_url: "https://example.com/imagine/webhook-url",
74
+ webhook_type: "progress", # or result
75
+ account_hash: "a7d44910-88a6-4673-acc8-d60ffc3479a6",
76
+ is_disable_prefilter: false)
77
+ then
78
+ client.status(result)
79
+ ```
80
+
81
+ #### Examples of other commands with parameters
82
+
83
+ ```ruby
84
+ client = UserapiAi::Client.new(service: :midjourney)
85
+ result = client.status(hash: "xxx-xxx")
86
+ result = client.variation(hash: "xxx-xxx", choice: 1)
87
+ result = client.upsample(hash: "xxx-xxx", choice: "v6_2x_subtle")
88
+
89
+ result = client.upscale(hash: "xxx-xxx",
90
+ choice: 1,
91
+ webhook_url:  "https://example.com/upscale/webhook-url",
92
+ webhook_type: "result")
93
+ ```
94
+ See more [here](https://butternut-saffron-e5e.notion.site/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142#9abe719bb58948039acb5f0a6aee8947)
95
+
96
+ ## Development
97
+
98
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests.
99
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at [Open an Issue](https://github.com/neonix20b/userapi-ai).
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
108
+ Feel free to use it and contribute.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,2 @@
1
+ require_relative "../userapi"
2
+ require_relative "../userapi/compatibility"
@@ -0,0 +1,31 @@
1
+ module UserapiAi
2
+ class Client
3
+ extend UserapiAi::HTTP
4
+
5
+ SERVICES = {
6
+ midjourney: {
7
+ get: [:status],
8
+ post: [:imagine, :describe, :upscale, :upsample, :variation, :inpaint, :blend, :reroll, :zoom, :pan, :info]
9
+ }
10
+ }
11
+
12
+ def initialize(access_token: nil, uri_base: nil, request_timeout: nil, service: nil, extra_headers: {})
13
+ UserapiAi.configuration.access_token = access_token if access_token
14
+ UserapiAi.configuration.uri_base = uri_base if uri_base
15
+ UserapiAi.configuration.request_timeout = request_timeout if request_timeout
16
+ UserapiAi.configuration.extra_headers = extra_headers
17
+ UserapiAi.configuration.service = service if service
18
+
19
+ SERVICES[service].each do |http_method, actions|
20
+ actions.each do |action|
21
+ method_name = action
22
+ method_name = "#{http_method}_#{action}" if methods.include? method_name.to_sym
23
+ define_singleton_method method_name.to_sym do |parameters|
24
+ UserapiAi::Client.public_send("json_#{http_method}", path: action, parameters: parameters)
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Ruby
2
+ module UserapiAi
3
+ VERSION = ::UserapiAi::VERSION
4
+
5
+ Error = ::UserapiAi::Error
6
+ ConfigurationError = ::UserapiAi::ConfigurationError
7
+ Configuration = ::UserapiAi::Configuration
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ module UserapiAi
2
+ module HTTP
3
+ def json_get(path:, parameters: {})
4
+ to_json(conn.get(uri(path: path, parameters: parameters)) do |req|
5
+ req.headers = headers
6
+ end&.body)
7
+ end
8
+
9
+ def json_post(path:, parameters:)
10
+ puts uri(path: path)
11
+ puts headers
12
+ puts parameters.to_json
13
+ to_json(conn.post(uri(path: path)) do |req|
14
+ req.headers = headers
15
+ req.body = parameters.to_json
16
+ end&.body)
17
+ end
18
+
19
+ #private
20
+
21
+ def to_json(string)
22
+ return unless string
23
+
24
+ JSON.parse(string)
25
+ rescue JSON::ParserError
26
+ # Convert a multiline string of JSON objects to a JSON array.
27
+ JSON.parse(string.gsub("}\n{", "},{").prepend("[").concat("]"))
28
+ end
29
+
30
+ def conn(multipart: false)
31
+ Faraday.new do |f|
32
+ f.options[:timeout] = UserapiAi.configuration.request_timeout
33
+ f.request(:multipart) if multipart
34
+ end
35
+ end
36
+
37
+ def uri(path:, parameters: {})
38
+ str = "#{UserapiAi.configuration.uri_base}/#{UserapiAi.configuration.service}/#{UserapiAi.configuration.api_version}/#{path}"
39
+ str += "?" + URI.encode_www_form(parameters) unless parameters.empty?
40
+ str
41
+ end
42
+
43
+ def headers
44
+ {
45
+ "Content-Type" => "application/json",
46
+ "api-key" => UserapiAi.configuration.access_token
47
+ }.merge(UserapiAi.configuration.extra_headers)
48
+ end
49
+
50
+ def multipart_parameters(parameters)
51
+ parameters&.transform_values do |value|
52
+ next value unless value.is_a?(File)
53
+
54
+ # Doesn't seem like Midjourney needs mime_type yet, so not worth
55
+ # the library to figure this out. Hence the empty string
56
+ # as the second argument.
57
+ Faraday::UploadIO.new(value, "", value.path)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UserapiAi
4
+ VERSION = "0.1.0"
5
+ end
6
+
data/lib/userapi-ai.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+
6
+ require_relative "userapi/http"
7
+ require_relative "userapi/client"
8
+ require_relative "userapi/version"
9
+
10
+ module UserapiAi
11
+ class Error < StandardError; end
12
+ class ConfigurationError < Error; end
13
+
14
+ class Configuration
15
+ attr_writer :access_token
16
+ attr_accessor :api_version, :extra_headers, :request_timeout, :uri_base, :service
17
+
18
+ def initialize
19
+ @access_token = nil
20
+ @api_version = :v2
21
+ @uri_base = "https://api.userapi.ai"
22
+ @request_timeout = 120
23
+ @service = :midjourney
24
+ end
25
+
26
+ def access_token
27
+ return @access_token if @access_token
28
+
29
+ error_text = "Userapi-Ai access token missing! See https://dashboard.userapi.ai/api-keys"
30
+ raise ConfigurationError, error_text
31
+ end
32
+ end
33
+
34
+ class << self
35
+ attr_writer :configuration
36
+ end
37
+
38
+ def self.configuration
39
+ @configuration ||= UserapiAi::Configuration.new
40
+ end
41
+
42
+ def self.configure
43
+ yield(configuration)
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ module Userapi
2
+ module Ai
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: userapi-ai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Smolev Denis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ description:
42
+ email:
43
+ - smolev@me.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/ruby/userapi-ai.rb
56
+ - lib/userapi-ai.rb
57
+ - lib/userapi/client.rb
58
+ - lib/userapi/compatibility.rb
59
+ - lib/userapi/http.rb
60
+ - lib/userapi/version.rb
61
+ - sig/userapi/ai.rbs
62
+ homepage: https://userapi.ai.
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://userapi.ai.
67
+ source_code_uri: https://github.com/neonix20b/userapi-ai
68
+ changelog_uri: https://github.com/neonix20b/userapi-ai/blob/main/CHANGELOG.md
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.5.4
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Userapi.ai (midjourney) + Ruby.
88
+ test_files: []