ruby-leonardoai 0.1.3 → 0.1.4

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: d108ed0e36199b2e7841810b31b77e951b1173082f97aa75410de1050aaa6080
4
+ data.tar.gz: c31edd35e33bc9c5a0c9ba2df992f8ce9b8f38698cdd9c48d0789a441f0eb8cd
5
5
  SHA512:
6
- metadata.gz: 3e0ed3ba12d42f629cb319784c6c53b8c911a0c7c1d11d07e6b1485c26293d7a44bd1b1132515adb19207641191589d4733e84bd5cda1e4a83f323611f0c9ff4
7
- data.tar.gz: 5144d1f07fb74fe88ef233255ff8e970e0985facbaa5ab56377188727e84816f740be883f10d8a607a588abe36e6d0e7924ae90a31138a5391ae8a3a9a141c68
6
+ metadata.gz: 9fce8ddb89a37f921531baecab3ee91d95314bc94757acdbab8d140c871b64caa65d961bb1c8929242c1e0d40e075cf64f088a81c73d8e6185969ae3e2ebb159
7
+ data.tar.gz: 2acadd28592ca2cb8131892b853add8193afef93f22f74d00af9060df6c7cbeed8d11cfd761106ab2cb4677a4c2f6e12e552eae51086b97a1df2757d0a878375
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,170 @@
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
+ UNDER CONSTRUCTION
138
+
139
+ ### Unzoom
140
+ UNDER CONSTRUCTION
141
+
142
+ ### Dataset
143
+ UNDER CONSTRUCTION
20
144
 
21
145
  ## Development
22
146
 
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.
147
+ 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
148
 
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).
149
+ To install this gem onto your local machine, run `bundle exec rake install`.
150
+
151
+ ### Warning
152
+
153
+ 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.
154
+
155
+ ## Release
156
+
157
+ 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:
158
+
159
+ ```
160
+ LEONARDOAI_ACCESS_TOKEN=123abc bundle exec rspec
161
+ ```
162
+
163
+ 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
164
 
27
165
  ## Contributing
28
166
 
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).
167
+ 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
168
 
31
169
  ## License
32
170
 
@@ -34,5 +172,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
34
172
 
35
173
  ## Code of Conduct
36
174
 
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
175
+ 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).
176
+
177
+ ## Influences
178
+ Project heavily influenced by [https://github.com/alexrudall/ruby-openai](https://github.com/alexrudall/ruby-openai). Great project, go give them a star!
@@ -1,3 +1,3 @@
1
1
  module LeonardoAI
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Lee