ruby-leonardoai 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffeeea7f957abbf1047c55db4b65e787b4c881c5bb3025cfad2b773403bcf6c9
4
- data.tar.gz: aafa39eba2314b23210262dba8ccbb60b68dc688cd6f111ede64c50b641b6f5d
3
+ metadata.gz: 177f0c64e72ef9ede48bf722a6a8886be330abcb1f9ab10af719395cb27046c2
4
+ data.tar.gz: 4c1ed2cb485ada7871c810c6908194bbfe33876af0d44d983a2044494d81324c
5
5
  SHA512:
6
- metadata.gz: 3e0ed3ba12d42f629cb319784c6c53b8c911a0c7c1d11d07e6b1485c26293d7a44bd1b1132515adb19207641191589d4733e84bd5cda1e4a83f323611f0c9ff4
7
- data.tar.gz: 5144d1f07fb74fe88ef233255ff8e970e0985facbaa5ab56377188727e84816f740be883f10d8a607a588abe36e6d0e7924ae90a31138a5391ae8a3a9a141c68
6
+ metadata.gz: 06d681a7ed63d0d19df5506856d9f62c2254853b031dffd72710cd9988e6050d1c14797c8d5ec5508b323065557255a451d532d8bc322ab278a40607b7132095
7
+ data.tar.gz: b801221868605de96484b84fad6be03c20653b1046bb9099be052276abfe6b8b5a1b97d01d7d4eaeaf4c8b6331f8a9103333303341d115ca33590999c4a14f8e
data/CHANGELOG.md CHANGED
@@ -3,3 +3,11 @@
3
3
  ## [0.1.0] - 2023-10-01
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.3] - 2023-10-10
8
+
9
+ - Updated file structure and got image generation working.
10
+
11
+ ## [0.1.3] - 2023-10-10
12
+
13
+ - Added README.md and updated installation and how-to-use instructions
data/README.md CHANGED
@@ -1,32 +1,192 @@
1
- # Ruby::Leonardoai
1
+ # Ruby LeonardoAI
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/ruby/leonardoai`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/ruby-openai.svg)](https://badge.fury.io/rb/ruby-leonardoai)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/royalgiant/ruby-leonardoai/blob/main/LICENSE.txt)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ Use the [LeonardoAI API](https://docs.leonardo.ai/reference/getuserself) with Ruby! 🤖❤️
6
7
 
7
- ## Installation
8
+ Generate, Get, and Delete images, models, variations, and datasets with Leonardo AI
8
9
 
9
- Install the gem and add to the application's Gemfile by executing:
10
+ 🚢 Based in the US and want to hire me? Now you can! [Email Me](mailto:donaldlee50@gmail.com)
10
11
 
11
- $ bundle add ruby-leonardoai
12
+ [🐦 Twitter](https://twitter.com/donaldlee50) | [▶️ Youtube](https://youtube.com/c/donaldleecrypto)
12
13
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
14
+ ### Bundler
14
15
 
15
- $ gem install ruby-leonardoai
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem "ruby-leonardoai"
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ $ bundle install
26
+ ```
27
+
28
+ ### Gem install
29
+
30
+ Or install with:
31
+
32
+ ```bash
33
+ $ gem install ruby-leonardoai
34
+ ```
35
+
36
+ and require with:
37
+
38
+ ```ruby
39
+ require "leonardoai"
40
+ ```
16
41
 
17
42
  ## Usage
18
43
 
19
- TODO: Write usage instructions here
44
+ - Get your API access from [https://app.leonardo.ai/api-access](https://app.leonardo.ai/api-access)
45
+ - After subscribing, you will be able to generate an api key from [https://app.leonardo.ai/settings](https://app.leonardo.ai/settings)
46
+
47
+ ### Quickstart
48
+
49
+ For a quick test you can pass your token directly to a new client:
50
+
51
+ ```ruby
52
+ client = LeonardoAI::Client.new(access_token: "access_token_goes_here")
53
+ ```
54
+
55
+ ### With Config
56
+
57
+ For a more robust setup, you can configure the gem with your API keys, for example in an `leonardoai.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
58
+
59
+ ```ruby
60
+ LeonardoAI.configure do |config|
61
+ config.access_token = ENV.fetch("LEONARDOAI_ACCESS_TOKEN")
62
+ end
63
+ ```
64
+ If you use Rails 7, you would probably store your key in credentials.yml, then you can do something like this:
65
+ ```ruby
66
+ LeonardoAI.configure do |config|
67
+ config.access_token = Rails.application.credentials[Rails.env.to_sym].dig(:leonardoai, :api_key)
68
+ end
69
+ ```
70
+
71
+ Then you can create a client like this:
72
+
73
+ ```ruby
74
+ client = LeonardoAI::Client.new
75
+ ```
76
+
77
+ You can still override the config defaults when making new clients; any options not included will fall back to any global config set with LeonardoAI.configure. e.g. in this example the uri_base, request_timeout, etc. will fallback to any set globally using LeonardoAI.configure, with only the access_token overridden:
78
+
79
+ ```ruby
80
+ client = LeonardoAI::Client.new(access_token: "access_token_goes_here")
81
+ ```
82
+
83
+ #### Custom timeout or base URI
84
+
85
+ The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client. You can also change the base URI used for all requests.
86
+
87
+ ```ruby
88
+ client = LeonardoAI::Client.new(
89
+ access_token: "access_token_goes_here",
90
+ uri_base: "https://cloud.leonardo.ai/api/rest/v1/",
91
+ request_timeout: 240,
92
+ extra_headers: {
93
+ "accept" => "application/json",
94
+ "content-type": "application/json",
95
+ }
96
+ )
97
+ ```
98
+
99
+ or when configuring the gem:
100
+
101
+ ```ruby
102
+ LeonardoAI.configure do |config|
103
+ config.access_token = ENV.fetch("LEONARDOAI_ACCESS_TOKEN") # Or Rails.application.credentials[Rails.env.to_sym].dig(:leonardoai, :api_key) for Rails 7
104
+ config.uri_base = "https://cloud.leonardo.ai/api/rest/v1/",
105
+ config.request_timeout = 240 # Optional
106
+ config.extra_headers = {
107
+ "accept" => "application/json",
108
+ "content-type": "application/json",
109
+ } # Optional
110
+ end
111
+ ```
112
+
113
+ ### Generation
114
+
115
+ ChatGPT is a model that can be used to generate text in a conversational style. You can use it to [generate a response](https://platform.openai.com/docs/api-reference/chat/create) to a sequence of [messages](https://platform.openai.com/docs/guides/chat/introduction):
116
+
117
+ ```ruby
118
+ params = {
119
+ :height=>1024,
120
+ :prompt=>"A ad flyer of a ninja cat, heavy texture, moonlit background, circle design, tshirt design, pen and ink style",
121
+ :width=>512, :num_images=>1,
122
+ :photoReal=>false,
123
+ :presetStyle=>"LEONARDO",
124
+ :promptMagic=>true,
125
+ :promptMagicVersion=>"v2",
126
+ :public=>false,
127
+ :init_strength=>0.4,
128
+ :sd_version=>"v2",
129
+ }
130
+
131
+ response = client.generations.generate(parameters: params) # {"sdGenerationJob"=>{"generationId"=>"c747522c-91e7-4830-8d1f-1f1ed37efd35"}}
132
+ puts response.dig("sdGenerationJob", "generationId")
133
+ # => "c747522c-91e7-4830-8d1f-1f1ed37efd35"
134
+ ```
135
+
136
+ ### Model
137
+ ```ruby
138
+ # https://cloud.leonardo.ai/api/rest/v1/models-3d/upload
139
+
140
+ params = {
141
+ :modelExtension=>"this-is-an-example",
142
+ :name=>"some string"
143
+ }
144
+
145
+ response = client.models.upload_3d_model(parameters: params)
146
+ ```
147
+
148
+ ```ruby
149
+ # https://cloud.leonardo.ai/api/rest/v1/models/{id}
150
+
151
+ params = {
152
+ :modelExtension=>"this-is-an-example",
153
+ :name=>"some string"
154
+ }
155
+
156
+ response = client.models.get_custom_models_by_id(id: "your-custom-model-id-here")
157
+ ```
158
+
159
+ For more parameters, please check the API found [here](https://docs.leonardo.ai/reference/post_models-3d-upload)
160
+
161
+ ### Unzoom
162
+ UNDER CONSTRUCTION
163
+
164
+ ### Dataset
165
+ UNDER CONSTRUCTION
20
166
 
21
167
  ## Development
22
168
 
23
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
169
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
24
170
 
25
- 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).
171
+ To install this gem onto your local machine, run `bundle exec rake install`.
172
+
173
+ ### Warning
174
+
175
+ If you have an `LEONARDOAI_ACCESS_TOKEN` in your `ENV`, running the specs will use this to run the specs against the actual API, which will be slow and cost you money - 2 cents or more! Remove it from your environment with `unset` or similar if you just want to run the specs against the stored VCR responses.
176
+
177
+ ## Release
178
+
179
+ First run the specs without VCR so they actually hit the API. This will cost 2 cents or more. Set LEONARDOAI_ACCESS_TOKEN in your environment or pass it in like this:
180
+
181
+ ```
182
+ LEONARDOAI_ACCESS_TOKEN=123abc bundle exec rspec
183
+ ```
184
+
185
+ Then update the version number in `version.rb`, update `CHANGELOG.md`, run `bundle install` to update Gemfile.lock, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
186
 
27
187
  ## Contributing
28
188
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby-leonardoai. 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/[USERNAME]/ruby-leonardoai/blob/main/CODE_OF_CONDUCT.md).
189
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/royalgiant/ruby-leonardoai>. 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/royalgiant/ruby-leonardoai/blob/main/CODE_OF_CONDUCT.md).
30
190
 
31
191
  ## License
32
192
 
@@ -34,5 +194,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
34
194
 
35
195
  ## Code of Conduct
36
196
 
37
- Everyone interacting in the Ruby::Leonardoai project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ruby-leonardoai/blob/main/CODE_OF_CONDUCT.md).
38
- # ruby-leonardoai
197
+ Everyone interacting in the Ruby LeonardoAI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/royalgiant/ruby-leonardoai/blob/main/CODE_OF_CONDUCT.md).
198
+
199
+ ## Influences
200
+ Project heavily influenced by [https://github.com/alexrudall/ruby-openai](https://github.com/alexrudall/ruby-openai). Great project, go give them a star!
@@ -27,5 +27,9 @@ module LeonardoAI
27
27
  def generations
28
28
  @generations ||= LeonardoAI::Generations.new(client: self)
29
29
  end
30
+
31
+ def models
32
+ @models ||= LeonardoAI::Models.new(client: self)
33
+ end
30
34
  end
31
35
  end
@@ -8,16 +8,32 @@ module LeonardoAI
8
8
  @client.json_post(path: "/generations", parameters: parameters)
9
9
  end
10
10
 
11
- def edit(parameters: {})
12
- @client.multipart_post(path: "/edits", parameters: open_files(parameters))
11
+ def get_generation(id:)
12
+ @client.get(path: "/generations/#{id}")
13
13
  end
14
14
 
15
- private
15
+ def delete_generation(id:)
16
+ @client.delete(path: "/generations/#{id}")
17
+ end
18
+
19
+ def get_user_generations(user_id:)
20
+ @client.get(path: "/generations/user/#{user_id}")
21
+ end
22
+
23
+ def generate_texture_generation(parameters: {})
24
+ @client.json_post(path: "/generations-texture", parameters: parameters)
25
+ end
26
+
27
+ def get_texture_generation_by_model_id(model_id:)
28
+ @client.get(path: "/generations-texture/model/#{model_id}")
29
+ end
30
+
31
+ def get_texture_generation_by_id(id:)
32
+ @client.get(path: "/generations-texture/model/#{id}")
33
+ end
16
34
 
17
- def open_files(parameters)
18
- parameters = parameters.merge(image: File.open(parameters[:image]))
19
- parameters = parameters.merge(mask: File.open(parameters[:mask])) if parameters[:mask]
20
- parameters
35
+ def delete_texture_generation(id:)
36
+ @client.delete(path: "/generations-texture/#{id}")
21
37
  end
22
38
  end
23
39
  end
@@ -0,0 +1,39 @@
1
+ module LeonardoAI
2
+ class Models
3
+ def initialize(client: nil)
4
+ @client = client
5
+ end
6
+
7
+ def upload_3d_model(parameters: {})
8
+ @client.json_post(path: "/models-3d/upload", parameters: parameters)
9
+ end
10
+
11
+ def get_3d_models_by_user_id(user_id:, offset: 0, limit: 10)
12
+ @client.get(path: "/models-3d/user/#{user_id}?offset=#{offset}&limit=#{limit}")
13
+ end
14
+
15
+ def get_3d_models_by_id(id:, offset: 0, limit: 10)
16
+ @client.get(path: "/models-3d/#{id}?offset=#{offset}&limit=#{limit}")
17
+ end
18
+
19
+ def delete_3d_model(id:)
20
+ @client.delete(path: "/models-3d/#{id}")
21
+ end
22
+
23
+ def train(parameters: {})
24
+ @client.json_post(path: "/models", parameters: parameters)
25
+ end
26
+
27
+ def get_custom_models_by_id(id:)
28
+ @client.get(path: "/models/#{id}")
29
+ end
30
+
31
+ def delete_models_by_id(id:)
32
+ @client.delete(path: "/models/#{id}")
33
+ end
34
+
35
+ def get_platform_models(offset: 0, limit: 10)
36
+ @client.get(path: "/platformModels?offset=#{offset}&limit=#{limit}")
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module LeonardoAI
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/leonardoai.rb CHANGED
@@ -3,6 +3,7 @@ require "faraday/multipart"
3
3
  require_relative "leonardoai/http"
4
4
  require_relative "leonardoai/client"
5
5
  require_relative "leonardoai/generations"
6
+ require_relative "leonardoai/models"
6
7
  require_relative "leonardoai/version"
7
8
 
8
9
  module LeonardoAI
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-leonardoai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2023-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -60,6 +60,7 @@ files:
60
60
  - lib/leonardoai/compatibility.rb
61
61
  - lib/leonardoai/generations.rb
62
62
  - lib/leonardoai/http.rb
63
+ - lib/leonardoai/models.rb
63
64
  - lib/leonardoai/version.rb
64
65
  - lib/ruby/leonardoai.rb
65
66
  - ruby-leonardoai.gemspec