leoandruby 0.4.5 → 0.5.3
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 +4 -4
- data/CHANGELOG.md +53 -0
- data/README.md +23 -3
- data/lib/leoandruby/client.rb +46 -9
- data/lib/leoandruby/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3108cca83586240d0b714c41e37b521f53505dedfd2410eb310cd53e81008a40
|
4
|
+
data.tar.gz: 5d4070cf2d3fe87c7ccdbd0b3faf80e4350bb1ef4c8e39f5256583585ab70fe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a294f8fabede70c00c5af41614083b7263b31dd4d1fcf1bcdaa3f3f2c4c9dd6f5fd2d9aad291723a0147b51fc243af632217f5f1438586694de8de24cdebcabc
|
7
|
+
data.tar.gz: 8e5cac2eec85b83f2a2637c9e333c628ab7fa3731dc89ed43d9ec8e8d2e25225150dc603dbba6fb851408580fd4d4bcf8566e15e2bb8a5d0b794e9f40dcb9d0a
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,57 @@
|
|
1
1
|
# Changelog
|
2
|
+
|
3
|
+
## [0.5.3] - 2024-04-29
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- Expanded `generate_image` method to support new parameters from Leonardo.ai's PhotoReal v2 API:
|
7
|
+
- `negative_prompt`
|
8
|
+
- `presetStyle`
|
9
|
+
- `photoRealVersion`
|
10
|
+
- Introduced intelligent default values for key generation parameters:
|
11
|
+
- Defaults to **Kino XL** model if no `model_id` is provided.
|
12
|
+
- Defaults `alchemy` to `true`.
|
13
|
+
- Defaults `photoReal` to `true`.
|
14
|
+
- Defaults `photoRealVersion` to `"v2"`.
|
15
|
+
- Defaults `presetStyle` to `"DYNAMIC"`.
|
16
|
+
- Added internal constant `DEFAULT_PHOTO_REAL_MODEL_ID` for clarity and maintainability.
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
- Improved `handle_response` method to parse and log detailed Leonardo.ai error responses.
|
20
|
+
- Enhanced error reporting to Rails logs for faster and more accurate debugging.
|
21
|
+
- Introduced validation to raise informative `ArgumentError` if `prompt`, `height`, or `width` are missing when generating an image.
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
- Ensured `negative_prompt` is correctly handled as an optional parameter during image generation.
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
## [0.5.2] - 2025-04-29
|
31
|
+
|
32
|
+
### Added
|
33
|
+
- Improved API error handling for Leonardo.ai failures.
|
34
|
+
- More detailed error logs to assist Rails diagnosis.
|
35
|
+
|
36
|
+
### Fixed
|
37
|
+
- Minor consistency improvements.
|
38
|
+
|
39
|
+
## [0.5.1] - 2025-04-28
|
40
|
+
|
41
|
+
### Added
|
42
|
+
- Enhanced error handling with detailed API response messages
|
43
|
+
- Improved documentation for troubleshooting common API errors
|
44
|
+
- Added support for model-specific parameter validation
|
45
|
+
|
46
|
+
### Changed
|
47
|
+
- Updated error handling to include API response body in error messages
|
48
|
+
- Improved parameter validation for model-specific requirements
|
49
|
+
|
50
|
+
### Fixed
|
51
|
+
- Resolved issues with model ID validation
|
52
|
+
- Fixed parameter handling for model-specific constraints
|
53
|
+
- Addressed compatibility issues with Leonardo.ai API updates
|
54
|
+
|
2
55
|
## [0.4.5] - 2025-04-28
|
3
56
|
### Added
|
4
57
|
- _Describe new features here._
|
data/README.md
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
- Webhook support to handle asynchronous image generation results.
|
15
15
|
- Rails generator for setting up webhook integration effortlessly.
|
16
16
|
- Simple and intuitive Ruby interface for interacting with the Leonardo.ai API.
|
17
|
+
- Advanced image generation features including Alchemy, PhotoReal, and preset styles.
|
17
18
|
|
18
19
|
---
|
19
20
|
|
@@ -70,12 +71,27 @@ generation_response = client.generate_image(
|
|
70
71
|
model_id: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
|
71
72
|
width: 512,
|
72
73
|
height: 512,
|
73
|
-
num_images: 1 # Optional, defaults to 1 if not specified
|
74
|
+
num_images: 1, # Optional, defaults to 1 if not specified
|
75
|
+
alchemy: true, # Optional, enables Alchemy feature
|
76
|
+
photo_real: true, # Optional, enables PhotoReal feature
|
77
|
+
photo_real_strength: 0.5, # Optional, controls PhotoReal effect strength (0.0 to 1.0)
|
78
|
+
preset_style: 'CINEMATIC' # Optional, applies preset styles
|
74
79
|
)
|
75
80
|
|
76
81
|
generation_id = generation_response['sdGenerationJob']['generationId']
|
77
82
|
```
|
78
83
|
|
84
|
+
### Advanced Image Generation Options
|
85
|
+
|
86
|
+
The `generate_image` method supports several advanced options to enhance your image generation:
|
87
|
+
|
88
|
+
- `alchemy`: Enable/disable the Alchemy feature for enhanced image quality
|
89
|
+
- `photo_real`: Enable/disable the PhotoReal feature for photorealistic results
|
90
|
+
- `photo_real_strength`: Control the strength of the PhotoReal effect (0.0 to 1.0)
|
91
|
+
- `preset_style`: Apply preset styles like 'CINEMATIC', 'ANIME', 'CREATIVE', etc.
|
92
|
+
|
93
|
+
All advanced options are optional and can be used in combination to achieve the desired result.
|
94
|
+
|
79
95
|
### 3. List Available Models
|
80
96
|
|
81
97
|
You can fetch a list of all available platform models using the `list_models` method:
|
@@ -100,7 +116,7 @@ puts image_response
|
|
100
116
|
|
101
117
|
## Webhook Integration (Rails)
|
102
118
|
|
103
|
-
LeoAndRuby supports asynchronous image generation through Leonardo.ai
|
119
|
+
LeoAndRuby supports asynchronous image generation through Leonardo.ai's webhook feature. This allows your application to automatically process results when the image generation is complete.
|
104
120
|
|
105
121
|
### Generate a Webhook Controller
|
106
122
|
|
@@ -147,7 +163,11 @@ generation_response = client.generate_image(
|
|
147
163
|
model_id: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
|
148
164
|
width: 1024,
|
149
165
|
height: 768,
|
150
|
-
num_images: 1 # Optional, defaults to 1 if not specified
|
166
|
+
num_images: 1, # Optional, defaults to 1 if not specified
|
167
|
+
alchemy: true, # Enable Alchemy for enhanced quality
|
168
|
+
photo_real: true, # Enable PhotoReal for photorealistic results
|
169
|
+
photo_real_strength: 0.7, # Set PhotoReal strength
|
170
|
+
preset_style: 'CINEMATIC' # Apply cinematic style
|
151
171
|
)
|
152
172
|
|
153
173
|
generation_id = generation_response['sdGenerationJob']['generationId']
|
data/lib/leoandruby/client.rb
CHANGED
@@ -1,16 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "net/http"
|
2
4
|
require "json"
|
3
5
|
require "uri"
|
4
6
|
|
5
7
|
module LeoAndRuby
|
6
8
|
class Client
|
7
|
-
API_BASE_URL = "https://cloud.leonardo.ai/api/rest/v1"
|
9
|
+
API_BASE_URL = "https://cloud.leonardo.ai/api/rest/v1"
|
10
|
+
DEFAULT_PHOTO_REAL_MODEL_ID = "aa77f04e-3eec-4034-9c07-d0f619684628"
|
8
11
|
|
9
12
|
def initialize(api_key)
|
10
13
|
@api_key = api_key
|
11
14
|
end
|
12
15
|
|
13
|
-
def generate_image(
|
16
|
+
def generate_image(
|
17
|
+
prompt:, height:, width:,
|
18
|
+
model_id: nil,
|
19
|
+
negative_prompt: nil,
|
20
|
+
alchemy: true,
|
21
|
+
preset_style: "DYNAMIC",
|
22
|
+
photo_real: true,
|
23
|
+
photo_real_version: "v2",
|
24
|
+
num_images: 1
|
25
|
+
)
|
26
|
+
raise ArgumentError, "Prompt must be provided" if prompt.nil? || prompt.strip.empty?
|
27
|
+
raise ArgumentError, "Height must be provided" if height.nil?
|
28
|
+
raise ArgumentError, "Width must be provided" if width.nil?
|
29
|
+
|
30
|
+
model_id ||= DEFAULT_PHOTO_REAL_MODEL_ID
|
31
|
+
|
14
32
|
uri = URI("#{API_BASE_URL}/generations")
|
15
33
|
request = Net::HTTP::Post.new(uri)
|
16
34
|
request["Accept"] = "application/json"
|
@@ -20,14 +38,16 @@ module LeoAndRuby
|
|
20
38
|
body = {
|
21
39
|
prompt: prompt,
|
22
40
|
modelId: model_id,
|
23
|
-
width: width,
|
24
41
|
height: height,
|
25
|
-
|
42
|
+
width: width,
|
43
|
+
num_images: num_images,
|
44
|
+
alchemy: alchemy,
|
45
|
+
presetStyle: preset_style,
|
46
|
+
photoReal: photo_real,
|
47
|
+
photoRealVersion: photo_real_version
|
26
48
|
}
|
27
|
-
|
28
|
-
body[:
|
29
|
-
body[:photoRealStrength] = photo_real_strength unless photo_real_strength.nil?
|
30
|
-
body[:presetStyle] = preset_style unless preset_style.nil?
|
49
|
+
|
50
|
+
body[:negative_prompt] = negative_prompt unless negative_prompt.nil?
|
31
51
|
|
32
52
|
request.body = body.to_json
|
33
53
|
|
@@ -71,7 +91,24 @@ module LeoAndRuby
|
|
71
91
|
when Net::HTTPSuccess
|
72
92
|
JSON.parse(response.body)
|
73
93
|
else
|
74
|
-
|
94
|
+
begin
|
95
|
+
error_body = JSON.parse(response.body)
|
96
|
+
error_message = if error_body.is_a?(Hash)
|
97
|
+
error_body["message"] || error_body["error"] || error_body.to_s
|
98
|
+
else
|
99
|
+
error_body.to_s
|
100
|
+
end
|
101
|
+
rescue JSON::ParserError
|
102
|
+
error_message = response.body
|
103
|
+
end
|
104
|
+
|
105
|
+
full_error = <<~ERROR
|
106
|
+
Leonardo.ai API Error:
|
107
|
+
HTTP Status: #{response.code} #{response.message}
|
108
|
+
Response Body: #{error_message}
|
109
|
+
ERROR
|
110
|
+
|
111
|
+
raise full_error.strip
|
75
112
|
end
|
76
113
|
end
|
77
114
|
end
|
data/lib/leoandruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leoandruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard HW Baldwin
|
@@ -24,9 +24,8 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6.0'
|
27
|
-
description: LeoAndRuby
|
28
|
-
|
29
|
-
interface for creating, managing, and retrieving AI-generated images.
|
27
|
+
description: LeoAndRuby integrates with the Leonardo.ai API, enabling seamless AI-powered
|
28
|
+
image generation in Ruby and Rails applications with simple, intuitive interfaces.
|
30
29
|
email:
|
31
30
|
- richard@empireofaustralia.com
|
32
31
|
executables: []
|
@@ -54,13 +53,15 @@ metadata:
|
|
54
53
|
homepage_uri: https://github.com/RWKotulski/LeoAndRuby
|
55
54
|
source_code_uri: https://github.com/RWKotulski/LeoAndRuby
|
56
55
|
changelog_uri: https://github.com/RWKotulski/LeoAndRuby/CHANGELOG.md
|
56
|
+
documentation_uri: https://rubydoc.info/gems/leoandruby
|
57
|
+
bug_tracker_uri: https://github.com/RWKotulski/LeoAndRuby/issues
|
57
58
|
features: |
|
58
59
|
- Generate stunning AI-powered images with minimal configuration.
|
59
60
|
- Simple Ruby interface for interacting with the Leonardo.ai API.
|
60
|
-
- Supports asynchronous workflows with polling
|
61
|
-
- Fully configurable with
|
62
|
-
- Easily integrates into Ruby and Rails applications.
|
61
|
+
- Supports asynchronous workflows with polling or webhook callbacks.
|
62
|
+
- Fully configurable with API key environment variables.
|
63
63
|
- Webhook support with Rails generator for seamless integration.
|
64
|
+
- Rails 6+ compatible.
|
64
65
|
post_install_message:
|
65
66
|
rdoc_options: []
|
66
67
|
require_paths:
|