leoandruby 0.1.1 → 0.2.0

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: 149d2e54ecda2eac9a33142240dd62f5b108741e0f5071b0a93a3290fec5ce10
4
- data.tar.gz: 444ff02b5545bfb777847096c83efb9479cafa0951481cf879aa186a01a16c8e
3
+ metadata.gz: 638e39f8fb7c349a1f6bd4c4dbcd548d6a552f826d20bbe7f95d5f9064267ed3
4
+ data.tar.gz: f5fafdb80e01a028eba24a0232f0e2725c3927a4c73daff75f0a75a09fdb1b66
5
5
  SHA512:
6
- metadata.gz: bca73afb65e1f65ab6468b2a6d2b31f04e601bd15284f7528e8d7bfa1ccbca5454ae4da10b958a84cec873bd3043e62f8979b7a2502f6d92bcdbcacd498989a9
7
- data.tar.gz: ed281dbcd565b839151cf828ab0ae31cee02c60355f7b46011b59160670d007f72db87c5f1608b31aa3b67399a217febaf908e2730f8adff2d2119c4b6d371af
6
+ metadata.gz: bf2a5818986f0057e76bf7577a4907334a1eacc47adc718ff28a3afcd1fc846627e5d2d56f7a15b3d4c070f7f67f0dce1ce1050ee90a6bb3a5bf3d164c817b83
7
+ data.tar.gz: '08baacb5984c10741d5264a4ed4f888e560a428ccf3f19bdbfbc62350b64b51da02eb29009d54fa41698b59c9199b8ceabdf5c6c6badf7a186f749c5f6931a3e'
data/CHANGELOG.md CHANGED
@@ -6,4 +6,12 @@
6
6
 
7
7
  ## [0.1.1] - 2024-11-21
8
8
 
9
- - Bug Fixes
9
+ - Bug Fixes
10
+
11
+ ## [0.1.2] - 2024-11-21
12
+
13
+ - Improved: Refactored code to use StandardRB style.
14
+
15
+ ## [0.2.0] - 2024-11-22
16
+
17
+ - Added: New Feature allows user to specify how many images to generate, defaulting to 1.
data/README.md CHANGED
@@ -3,6 +3,9 @@
3
3
 
4
4
  **LeoAndRuby** is a Ruby gem for generating images using the [Leonardo.ai API](https://docs.leonardo.ai/docs/generate-your-first-images). With this gem, you can easily integrate Leonardo.ai's powerful image generation capabilities into your Ruby applications.
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/leoandruby.svg)](https://badge.fury.io/rb/leoandruby)
7
+
8
+
6
9
  ---
7
10
 
8
11
  ## Features
@@ -56,14 +59,15 @@ client = LeoAndRuby::Client.new(api_key)
56
59
 
57
60
  ### 2. Generate an Image
58
61
 
59
- You can generate an image by providing the prompt, model ID, width, and height:
62
+ You can generate an image by providing the prompt, model ID, width, height, and optionally the number of images:
60
63
 
61
64
  ```ruby
62
65
  generation_response = client.generate_image(
63
66
  prompt: 'An oil painting of a cat',
64
67
  model_id: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
65
68
  width: 512,
66
- height: 512
69
+ height: 512,
70
+ num_images: 1 # Optional, defaults to 1 if not specified
67
71
  )
68
72
 
69
73
  generation_id = generation_response['sdGenerationJob']['generationId']
@@ -116,7 +120,8 @@ generation_response = client.generate_image(
116
120
  prompt: 'A futuristic cityscape at sunset',
117
121
  model_id: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
118
122
  width: 1024,
119
- height: 768
123
+ height: 768,
124
+ num_images: 1 # Optional, defaults to 1 if not specified
120
125
  )
121
126
 
122
127
  generation_id = generation_response['sdGenerationJob']['generationId']
@@ -1,27 +1,28 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'uri'
1
+ require "net/http"
2
+ require "json"
3
+ require "uri"
4
4
 
5
5
  module LeoAndRuby
6
6
  class Client
7
- API_BASE_URL = 'https://cloud.leonardo.ai/api/rest/v1'.freeze
7
+ API_BASE_URL = "https://cloud.leonardo.ai/api/rest/v1".freeze
8
8
 
9
9
  def initialize(api_key)
10
10
  @api_key = api_key
11
11
  end
12
12
 
13
- def generate_image(prompt:, model_id:, width:, height:)
13
+ def generate_image(prompt:, model_id:, width:, height:, num_images: 1)
14
14
  uri = URI("#{API_BASE_URL}/generations")
15
15
  request = Net::HTTP::Post.new(uri)
16
- request['Accept'] = 'application/json'
17
- request['Authorization'] = "Bearer #{@api_key}"
18
- request['Content-Type'] = 'application/json'
16
+ request["Accept"] = "application/json"
17
+ request["Authorization"] = "Bearer #{@api_key}"
18
+ request["Content-Type"] = "application/json"
19
19
 
20
20
  request.body = {
21
21
  prompt: prompt,
22
22
  modelId: model_id,
23
23
  width: width,
24
- height: height
24
+ height: height,
25
+ num_images: num_images
25
26
  }.to_json
26
27
 
27
28
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
@@ -34,8 +35,8 @@ module LeoAndRuby
34
35
  def get_generation(generation_id)
35
36
  uri = URI("#{API_BASE_URL}/generations/#{generation_id}")
36
37
  request = Net::HTTP::Get.new(uri)
37
- request['Accept'] = 'application/json'
38
- request['Authorization'] = "Bearer #{@api_key}"
38
+ request["Accept"] = "application/json"
39
+ request["Authorization"] = "Bearer #{@api_key}"
39
40
 
40
41
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
41
42
  http.request(request)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leoandruby
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/leoandruby.rb CHANGED
@@ -1,4 +1,3 @@
1
- #lib/leoandruby.rb
2
-
3
- require_relative 'leoandruby/client'
1
+ # lib/leoandruby.rb
4
2
 
3
+ require_relative "leoandruby/client"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leoandruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard HW Baldwin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-20 00:00:00.000000000 Z
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LeoAndRuby is a Ruby gem for integrating with the Leonardo.ai API, enabling
14
14
  seamless image generation within Ruby applications. It provides a simple and intuitive