leoandruby 0.5.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b34c1559fe749345dcc2d19aaacbfc516f2f8331cd09ae1827e28e619cf77f96
4
- data.tar.gz: bd88053ecbf601f70a18e69179cd115d0731d5cb245589a0e900211e136df60e
3
+ metadata.gz: 3108cca83586240d0b714c41e37b521f53505dedfd2410eb310cd53e81008a40
4
+ data.tar.gz: 5d4070cf2d3fe87c7ccdbd0b3faf80e4350bb1ef4c8e39f5256583585ab70fe3
5
5
  SHA512:
6
- metadata.gz: ad61649bfe11f022c5e6be239bacc1474d2d86dc31cb995c8212d8b5180c4e185b6ac5c2e010ea9906c007bf77aa9755c7e9729de3a9370b7924472cfc329e20
7
- data.tar.gz: c19db98f3abd4d3fe4f6bedd0a8cc66a8f2fda55b21f3cb3a2596cbe4078b06688d79c97e09cd1aae0ae0d8c6e96a6b40b5b7b75f9800607fd3ff0aba7380658
6
+ metadata.gz: a294f8fabede70c00c5af41614083b7263b31dd4d1fcf1bcdaa3f3f2c4c9dd6f5fd2d9aad291723a0147b51fc243af632217f5f1438586694de8de24cdebcabc
7
+ data.tar.gz: 8e5cac2eec85b83f2a2637c9e333c628ab7fa3731dc89ed43d9ec8e8d2e25225150dc603dbba6fb851408580fd4d4bcf8566e15e2bb8a5d0b794e9f40dcb9d0a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
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
+
3
30
  ## [0.5.2] - 2025-04-29
4
31
 
5
32
  ### Added
@@ -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".freeze
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(prompt:, model_id:, width:, height:, num_images: 1, alchemy: nil, photo_real: nil, photo_real_strength: nil, preset_style: nil)
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
- num_images: num_images
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
- body[:alchemy] = alchemy unless alchemy.nil?
28
- body[:photoReal] = photo_real unless photo_real.nil?
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
 
@@ -88,9 +108,7 @@ module LeoAndRuby
88
108
  Response Body: #{error_message}
89
109
  ERROR
90
110
 
91
- Rails.logger.error(full_error) if defined?(Rails)
92
111
  raise full_error.strip
93
-
94
112
  end
95
113
  end
96
114
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LeoAndRuby
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard HW Baldwin