getimg_client 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df68c244073fbc74c6cb913c4b9208c40a2d136d226a1974dec6addae2bc4682
4
- data.tar.gz: 641715c9f551b30eb44f06252be3ded05df990676e5260cff8e89893d3b0ca77
3
+ metadata.gz: 49df7df20de9d97f5bc96e06eb517c007f55101e61b56c6d33d4878687f13249
4
+ data.tar.gz: 4dc36a54730384489acb5068e24e55fd272186f1c6cafb610272f05b777e522c
5
5
  SHA512:
6
- metadata.gz: 5249e227172db1f03aeced82d4a8f6429b1ad75c6eaa2c51d0285000e0f324b9b14ef833bc638949dd35e3aef03d1ab99c93049a0de65bebe57c58d8f9d35f97
7
- data.tar.gz: dec0e93875f2d227ac3a7128b57d7e65f7f3d8b334f7f4c379f7a4cb87b1c6aa0672789979b950a65cd5f96bc6fabb2fb0cf9f613d8596147b8449dffbb7b9dd
6
+ metadata.gz: c2a3a252131ecfca467e4ca97704a6d1d86d3ac4d0f8840a9f18c03a2686b5bdff4322ddf09e697d6cc765e5cd743579580c6be70c2b6a6a0df0c1c51aa9781d
7
+ data.tar.gz: 586153f30ac2646900cd7e0ad87d531ec1151ea53c5a7dd3271f0120774531f1df2f6ad1ee608a47ab8020a9e223ed42171932a0e66f3845725dfff1e790271e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GetimgClient
1
+ # GetimgClient [![Gem Version](https://badge.fury.io/rb/getimg_client.svg)](https://badge.fury.io/rb/getimg_client)
2
2
 
3
3
  ## Introduction
4
4
  GetimgClient is a Ruby gem designed to interact with the Getimg.ai API, enabling users to generate, manipulate, and enhance images using various AI models. This gem simplifies the process of making API requests to Getimg.ai, allowing for seamless integration of image generation and manipulation capabilities into your Ruby applications.
@@ -83,7 +83,7 @@ If an HTTP error occurs, the error message will include both the HTTP status and
83
83
  The provided `model` option will determine the model use, and contribute to the client's inference of the desired endpoint. Models can be the string `id` listed online at [the GetImg dashboard](https://dashboard.getimg.ai/models) or retrieved using the `GetimgClient.models` method. Equally, you can use symbols instead. For example, `:realistic_vision_v5_1` will translate to `'realistic-vision-v5-1'`
84
84
 
85
85
  ## Essential
86
- Getimg offers the "essential" checkpoints, which perform more abstract Stable Diffusion operations based on the provided prompt. Note that *:essential* and *:essential_v2* will *not* be listed in the model listing, as these are not in fact actual models, nor valid "model" value at the API's end.
86
+ Getimg offers the "essential" checkpoints, which perform more abstract Stable Diffusion operations based on the provided prompt. Note that *:essential* and *:essential_v2* will *not* be listed in the model listing, as these are not in fact actual models, nor valid "model" values at the API's end.
87
87
  In order to route a request to Essential or Essential V2 however, you can provide *:essential* or *:essential_v2* as a model argument in *#generate_image*.
88
88
 
89
89
  ## Latent Consistency Models (LCM)
@@ -158,7 +158,21 @@ puts result["image"]
158
158
  ```
159
159
 
160
160
  ## Logging
161
- Request logging will automatically be enabled, if the **RAILS_ENV** environment variable is set to "development"
161
+ GetimgClient supports logging request details for debugging and development purposes. The logging behavior depends on the environment and configuration:
162
+
163
+ Rails Development Environment: If the **RAILS_ENV** environment variable is set to "development" and Rails is defined, logs will be sent to the Rails logger.
164
+
165
+ **GETIMG_LOG** Environment Variable: If the GETIMG_LOG environment variable is set, logs will be printed to the standard output.
166
+
167
+ #### Log output example
168
+ ```text
169
+ Generating image with the following details:
170
+ Prompt: A scenic landscape
171
+ Model: stable-diffusion-v1-5
172
+ Requested Pipeline: text-to-image
173
+ Endpoint URI: https://api.getimg.ai/v1/stable-diffusion/text-to-image
174
+ Options: {width: 512, height: 512}
175
+ ```
162
176
 
163
177
  ## Unit Testing
164
178
  The gem includes unit tests using Minitest. Integration tests make real API calls and will incur usage fees. Ensure your API key is set in the environment before running tests.
data/lib/getimg_client.rb CHANGED
@@ -43,7 +43,7 @@ class GetimgClient
43
43
 
44
44
  # Convert model to appropriate ID format
45
45
  model_id = model.to_s.gsub('_', '-')
46
- if model_id === 'essential' || model_id === 'essential-v2'
46
+ if %w[essential essential-v2].include?(model_id)
47
47
  model_info = models[model_id] || { name: model_id, pipelines: ['text-to-image'] }
48
48
  else
49
49
  model_info = models[model_id] || raise(ArgumentError, "Unknown model: #{model}")
@@ -75,16 +75,8 @@ class GetimgClient
75
75
  # Ensure scale is an integer if present
76
76
  options[:scale] = options[:scale].to_i if options[:scale]
77
77
 
78
- # Logging request details in development environment
79
- if ENV['RAILS_ENV'] == 'development'
80
- puts "Generating image with the following details:"
81
- puts "Prompt: #{prompt}"
82
- puts "Model: #{model_id}"
83
- puts "Requested Pipeline: #{requested_pipeline}"
84
- puts "Endpoint URI: #{uri}"
85
- truncated_options = options.transform_values { |v| v.is_a?(String) && v.length > 50 ? "#{v[0, 50]}..." : v }
86
- puts "Options: #{truncated_options}"
87
- end
78
+ # Log the request details
79
+ log_request_details(prompt, model_id, requested_pipeline, uri, options)
88
80
 
89
81
  # Create and send the request
90
82
  request = create_request(uri, prompt, model: model_id, **options)
@@ -105,6 +97,25 @@ class GetimgClient
105
97
 
106
98
  private
107
99
 
100
+ # Log request details
101
+ def self.log_request_details(prompt, model_id, requested_pipeline, uri, options)
102
+ log_message = <<~LOG
103
+ Generating image with the following details:
104
+ Prompt: #{prompt}
105
+ Model: #{model_id}
106
+ Requested Pipeline: #{requested_pipeline}
107
+ Endpoint URI: #{uri}
108
+ Options: #{options.transform_values { |v| v.is_a?(String) && v.length > 50 ? "#{v[0, 50]}..." : v }}
109
+ LOG
110
+
111
+ if ENV['RAILS_ENV'] === 'development' && defined?(Rails) && Rails.logger
112
+ Rails.logger.info(log_message)
113
+ end
114
+ if ENV['GETIMG_LOG']
115
+ puts log_message
116
+ end
117
+ end
118
+
108
119
  # Determine the requested method based on provided image paths, controlnet, and model_info
109
120
  def self.method_requested(base_image, mask_image_path, controlnet, model_info)
110
121
  return :controlnet if controlnet
@@ -1,4 +1,5 @@
1
1
  require_relative "../test_helper"
2
+ require 'stringio'
2
3
 
3
4
  class GetimgClientIntegrationTest < Minitest::Test
4
5
  def setup
@@ -63,6 +64,35 @@ class GetimgClientIntegrationTest < Minitest::Test
63
64
  save_image(result["image"], "test_generate_text_to_image_essential")
64
65
  end
65
66
 
67
+ def test_logging_to_rails_logger
68
+ skip "Rails not defined, skipping Rails logger test" unless defined?(Rails) && ENV['RAILS_ENV'] === 'development'
69
+
70
+ original_logger = Rails.logger
71
+ log_output = StringIO.new
72
+ Rails.logger = Logger.new(log_output)
73
+
74
+ GetimgClient.generate_image("A scenic landscape", model: :stable_diffusion_v1_5, width: 512, height: 512)
75
+
76
+ assert_includes log_output.string, "Generating image with the following details:"
77
+ assert_includes log_output.string, "Prompt: A scenic landscape"
78
+
79
+ Rails.logger = original_logger
80
+ end
81
+
82
+ def test_logging_to_puts
83
+ ENV['GETIMG_LOG'] = '1'
84
+ log_output = StringIO.new
85
+ $stdout = log_output
86
+
87
+ GetimgClient.generate_image("A scenic landscape", model: :stable_diffusion_v1_5, width: 512, height: 512)
88
+
89
+ assert_includes log_output.string, "Generating image with the following details:"
90
+ assert_includes log_output.string, "Prompt: A scenic landscape"
91
+
92
+ $stdout = STDOUT
93
+ ENV.delete('GETIMG_LOG')
94
+ end
95
+
66
96
  private
67
97
 
68
98
  def save_image(base64_image, filename)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getimg_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melvin Sommer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-18 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest