generate_image 1.1.2.2 → 2.0.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 +4 -4
- data/.env.example +6 -0
- data/.github/workflows/ci.yml +23 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +44 -0
- data/CLAUDE.md +25 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -21
- data/README.md +165 -85
- data/Rakefile +6 -0
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/generate_image-1.1.2.2.gem +0 -0
- data/generate_image.gemspec +37 -0
- data/lib/generate_image/client.rb +201 -0
- data/lib/generate_image/configuration.rb +27 -0
- data/lib/generate_image/errors.rb +31 -0
- data/lib/generate_image/http.rb +215 -0
- data/lib/generate_image/models.rb +30 -0
- data/lib/generate_image/response.rb +54 -0
- data/lib/generate_image/version.rb +5 -3
- data/lib/generate_image.rb +21 -46
- data/scripts/gem-docker.cmd +5 -0
- data/scripts/gem-docker.ps1 +83 -0
- metadata +53 -50
- data/spec/generate_image_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e70209150d3dca1a233b163e8d93db0d2251aa27252dd11a095549f51028652e
|
|
4
|
+
data.tar.gz: 31a17a9edd81b26e3d481b069c878c866072a80fc802e4b8af40c8b15954af89
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40a6e474de330720930bf1295ce9c7122611886dbeef1b7a021fa7339e2b35e03a23c77237a3de29de10827930ac7e049ab86c39c48d5f55ba64f268efea165a
|
|
7
|
+
data.tar.gz: 4918a9fec6f0fc57483ffe5940ad1a3bbee3810683b19fc065b19dbf6a523d2e2ce4f06114dfc7016d77ff830a6f1ca42ef8608c493d6c5ecefb0ffab28c1337
|
data/.env.example
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Copy to .env (do not commit .env). Used by scripts/gem-docker.ps1 for `push` only.
|
|
2
|
+
# RubyGems: https://rubygems.org/profile/edit → API key → paste here
|
|
3
|
+
GEM_HOST_API_KEY=rubygems_YOUR_KEY_HERE
|
|
4
|
+
|
|
5
|
+
# Optional: one-time MFA code for non-interactive push (never store long-term)
|
|
6
|
+
# GEM_HOST_OTP_CODE=123456
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master, develop]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
ruby-version: ["3.1", "3.2", "3.3"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
19
|
+
bundler-cache: true
|
|
20
|
+
- name: Bundle install
|
|
21
|
+
run: bundle install
|
|
22
|
+
- name: RSpec
|
|
23
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2026-04-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `GenerateImage.configure` for global defaults (`api_key`, `default_model`, `base_url`, `default_size`, `default_quality`, `default_output_format`, timeouts, `max_retries`).
|
|
13
|
+
- `GenerateImage::Client#generate` — `POST /v1/images/generations` with GPT Image models (`gpt-image-1`, `gpt-image-1.5`, `gpt-image-1-mini`) and DALL·E 2/3.
|
|
14
|
+
- `GenerateImage::Client#edit` — `POST /v1/images/edits` with multipart uploads (`image`, optional `mask`).
|
|
15
|
+
- `GenerateImage::Response` with `#url`, `#b64`, `#images`, `#usage`, `#model`, `#raw`, `#to_h` (legacy-shaped hash).
|
|
16
|
+
- Error types: `AuthenticationError`, `RateLimitError`, `ApiError`, `ValidationError`; `RequestFailed` aliases `ApiError` for rescues.
|
|
17
|
+
- Retries on HTTP 429 using `Retry-After` (up to `configuration.max_retries`).
|
|
18
|
+
- RSpec suite with WebMock.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **Default model** is `gpt-image-1` (was DALL·E 2–era `image-alpha-001`).
|
|
23
|
+
- **Default size** is `1024x1024` (was `512x512`).
|
|
24
|
+
- Preferred API key env var is **`OPENAI_API_KEY`**; **`DALL_E_API_KEY`** remains a fallback.
|
|
25
|
+
|
|
26
|
+
### Removed
|
|
27
|
+
|
|
28
|
+
- Runtime dependencies on `sinatra`, `openai`, and pinned `json` / `net-http` (stdlib `net/http` + `json` only).
|
|
29
|
+
|
|
30
|
+
### Deprecated
|
|
31
|
+
|
|
32
|
+
- `Client#generate_image` — use `#generate`; emits a deprecation warning on stderr.
|
|
33
|
+
|
|
34
|
+
### Migration
|
|
35
|
+
|
|
36
|
+
- Replace `client.generate_image("prompt", opts)` with `client.generate("prompt", **opts)` and use `Response` (`#url` / `#b64`) or `#to_h` for a v1-like hash.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## [1.x]
|
|
41
|
+
|
|
42
|
+
Earlier releases targeted the legacy Images API with DALL·E 2 defaults. OpenAI has announced sunset timelines for older image models; prefer GPT Image models in new code.
|
|
43
|
+
|
|
44
|
+
[2.0.0]: https://github.com/merouaneamqor/generate_image/releases
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# generate_image — AI assistant notes
|
|
2
|
+
|
|
3
|
+
Ruby gem: **OpenAI Images API** client (`/v1/images/generations`, `/v1/images/edits`). Stdlib only (`Net::HTTP`, `json`). **Ruby >= 3.1**.
|
|
4
|
+
|
|
5
|
+
## Layout
|
|
6
|
+
|
|
7
|
+
| Path | Role |
|
|
8
|
+
|------|------|
|
|
9
|
+
| `lib/generate_image.rb` | Entry; `GenerateImage.configure` |
|
|
10
|
+
| `lib/generate_image/client.rb` | `#generate`, `#edit`, deprecated `#generate_image` |
|
|
11
|
+
| `lib/generate_image/http.rb` | JSON POST, multipart POST, 429 retry |
|
|
12
|
+
| `lib/generate_image/configuration.rb` | Keys, defaults, timeouts |
|
|
13
|
+
| `lib/generate_image/models.rb` | Model/size constants |
|
|
14
|
+
| `lib/generate_image/response.rb` | Parsed API response |
|
|
15
|
+
| `lib/generate_image/errors.rb` | Error hierarchy |
|
|
16
|
+
|
|
17
|
+
## Conventions
|
|
18
|
+
|
|
19
|
+
- Do not add heavy runtime deps; keep generation HTTP in `HTTP`, validation in `Client`.
|
|
20
|
+
- Preserve backward compat: `DALL_E_API_KEY` fallback, `RequestFailed` alias, `#generate_image` delegation.
|
|
21
|
+
- API key: never log or persist keys; read from config or env only.
|
|
22
|
+
|
|
23
|
+
## Checks
|
|
24
|
+
|
|
25
|
+
From gem root: `bundle install` then `bundle exec rspec`.
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at marouane.amqor6@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
generate_image (1.1.2.2)
|
|
5
|
+
json (~> 2.6.3)
|
|
6
|
+
net-http (~> 0.3.2)
|
|
7
|
+
openai (~> 0.3.0)
|
|
8
|
+
sinatra (~> 3.0.5)
|
|
9
|
+
|
|
10
|
+
GEM
|
|
11
|
+
remote: https://rubygems.org/
|
|
12
|
+
specs:
|
|
13
|
+
diff-lcs (1.5.0)
|
|
14
|
+
json (2.6.3)
|
|
15
|
+
mustermann (3.0.0)
|
|
16
|
+
ruby2_keywords (~> 0.0.1)
|
|
17
|
+
net-http (0.3.2)
|
|
18
|
+
uri
|
|
19
|
+
openai (0.3.0)
|
|
20
|
+
rack (2.2.6.2)
|
|
21
|
+
rack-protection (3.0.5)
|
|
22
|
+
rack
|
|
23
|
+
rake (12.3.3)
|
|
24
|
+
rspec (3.12.0)
|
|
25
|
+
rspec-core (~> 3.12.0)
|
|
26
|
+
rspec-expectations (~> 3.12.0)
|
|
27
|
+
rspec-mocks (~> 3.12.0)
|
|
28
|
+
rspec-core (3.12.1)
|
|
29
|
+
rspec-support (~> 3.12.0)
|
|
30
|
+
rspec-expectations (3.12.2)
|
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
32
|
+
rspec-support (~> 3.12.0)
|
|
33
|
+
rspec-mocks (3.12.3)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.12.0)
|
|
36
|
+
rspec-support (3.12.0)
|
|
37
|
+
ruby2_keywords (0.0.5)
|
|
38
|
+
sinatra (3.0.5)
|
|
39
|
+
mustermann (~> 3.0)
|
|
40
|
+
rack (~> 2.2, >= 2.2.4)
|
|
41
|
+
rack-protection (= 3.0.5)
|
|
42
|
+
tilt (~> 2.0)
|
|
43
|
+
tilt (2.0.11)
|
|
44
|
+
uri (0.12.0)
|
|
45
|
+
|
|
46
|
+
PLATFORMS
|
|
47
|
+
ruby
|
|
48
|
+
|
|
49
|
+
DEPENDENCIES
|
|
50
|
+
generate_image!
|
|
51
|
+
rake (~> 12.0)
|
|
52
|
+
rspec (~> 3.0)
|
|
53
|
+
|
|
54
|
+
BUNDLED WITH
|
|
55
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 AMQOR Merouane
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2026 AMQOR Merouane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,85 +1,165 @@
|
|
|
1
|
-
# GenerateImage
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
# GenerateImage
|
|
2
|
+
|
|
3
|
+
Lightweight **Ruby** client for the **OpenAI Images API**: image generation (`POST /v1/images/generations`) and edits (`POST /v1/images/edits`). Uses only the standard library (`Net::HTTP`, `JSON`). **Ruby >= 3.1**.
|
|
4
|
+
|
|
5
|
+
> **Deprecation / sunset (OpenAI):** DALL·E 2 and DALL·E 3 are scheduled for **sunset on May 12, 2026**. Prefer **GPT Image** models (`gpt-image-1`, `gpt-image-1.5`, `gpt-image-1-mini`) for new integrations. This gem defaults to `gpt-image-1`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add to your Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem "generate_image", "~> 2.0"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bundle install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
Set **`OPENAI_API_KEY`** (recommended). The legacy **`DALL_E_API_KEY`** is still read as a fallback if `OPENAI_API_KEY` is unset.
|
|
24
|
+
|
|
25
|
+
Optional global defaults:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require "generate_image"
|
|
29
|
+
|
|
30
|
+
GenerateImage.configure do |c|
|
|
31
|
+
c.api_key = ENV["OPENAI_API_KEY"]
|
|
32
|
+
c.default_model = "gpt-image-1"
|
|
33
|
+
c.base_url = "https://api.openai.com"
|
|
34
|
+
c.default_size = "1024x1024"
|
|
35
|
+
c.default_quality = "auto"
|
|
36
|
+
c.default_output_format = "png"
|
|
37
|
+
c.open_timeout = 30
|
|
38
|
+
c.read_timeout = 120
|
|
39
|
+
c.max_retries = 1 # extra attempts after HTTP 429, honors Retry-After
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You can also pass an API key per client: `GenerateImage::Client.new("sk-...")`.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### Generate (GPT Image)
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
client = GenerateImage::Client.new
|
|
51
|
+
|
|
52
|
+
response = client.generate("A ruby gemstone on velvet, product photo")
|
|
53
|
+
|
|
54
|
+
response.b64 # first image base64 (typical for GPT Image)
|
|
55
|
+
response.url # first HTTPS URL when API returns URLs
|
|
56
|
+
response.images # => [{ b64_json: "..." }] or [{ url: "..." }], ...
|
|
57
|
+
response.usage # token usage hash or nil
|
|
58
|
+
response.model # model used
|
|
59
|
+
response.raw # full parsed JSON Hash
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Common options (passed as keyword args):
|
|
63
|
+
|
|
64
|
+
| Option | GPT Image | DALL·E 3 |
|
|
65
|
+
|--------|-----------|----------|
|
|
66
|
+
| `model` | `gpt-image-1`, `gpt-image-1.5`, `gpt-image-1-mini` | `dall-e-3` |
|
|
67
|
+
| `n` | 1–10 | 1 only |
|
|
68
|
+
| `size` | `auto`, `1024x1024`, `1536x1024`, `1024x1536` | `1024x1024`, `1792x1024`, `1024x1792` |
|
|
69
|
+
| `quality` | `auto`, `high`, `medium`, `low` | `standard`, `hd` |
|
|
70
|
+
| `output_format` | `png`, `jpeg`, `webp` | (API returns URLs by default; use `response_format`) |
|
|
71
|
+
| `background` | `transparent`, `opaque`, `auto` | — |
|
|
72
|
+
| `response_format` | `url`, `b64_json` if you need to force format | often `url` |
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
client.generate(
|
|
76
|
+
"Minimal logo",
|
|
77
|
+
model: "gpt-image-1-mini",
|
|
78
|
+
size: "1024x1024",
|
|
79
|
+
quality: "high",
|
|
80
|
+
output_format: "png",
|
|
81
|
+
background: "transparent",
|
|
82
|
+
n: 2
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Generate (DALL·E 3)
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
client.generate(
|
|
90
|
+
"Sunset over the Atlantic",
|
|
91
|
+
model: "dall-e-3",
|
|
92
|
+
size: "1792x1024",
|
|
93
|
+
quality: "hd",
|
|
94
|
+
response_format: "url"
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Edit / inpainting
|
|
99
|
+
|
|
100
|
+
Multipart request with at least **`image:`** (path string, `Pathname`, `IO`, or `StringIO`) and **`prompt:`**.
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
client.edit(
|
|
104
|
+
image: "input.png",
|
|
105
|
+
prompt: "Add soft studio lighting",
|
|
106
|
+
model: "gpt-image-1",
|
|
107
|
+
size: "1024x1024",
|
|
108
|
+
quality: "auto",
|
|
109
|
+
mask: "mask.png" # optional
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Additional GPT Image–oriented options: `output_format`, `background`, `input_fidelity` (`high` / `low`), `response_format`, `user`.
|
|
114
|
+
|
|
115
|
+
### Errors
|
|
116
|
+
|
|
117
|
+
| Exception | When |
|
|
118
|
+
|-----------|------|
|
|
119
|
+
| `GenerateImage::AuthenticationError` | 401 / missing API key |
|
|
120
|
+
| `GenerateImage::RateLimitError` | 429 (retried according to `max_retries` and `Retry-After`) |
|
|
121
|
+
| `GenerateImage::ApiError` | Other non-success HTTP responses (`#status_code`, `#body`) |
|
|
122
|
+
| `GenerateImage::ValidationError` | Invalid prompt, model/size/n combination, etc. |
|
|
123
|
+
|
|
124
|
+
`GenerateImage::RequestFailed` is an alias for `ApiError` for compatibility with rescues from v1.x.
|
|
125
|
+
|
|
126
|
+
## Backward compatibility (v1.x)
|
|
127
|
+
|
|
128
|
+
- `client.generate_image(text, options_hash)` still works but **prints a deprecation warning** and returns a legacy-shaped `Hash` (`:image_url` or `:image_base64`) via `Response#to_h`.
|
|
129
|
+
- Legacy keys: `num_images` → `n`, `response_format: "base64"` → `b64_json` for the API.
|
|
130
|
+
|
|
131
|
+
Prefer:
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
response = client.generate("A cat")
|
|
135
|
+
response.url || response.b64
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Migration from 1.x
|
|
139
|
+
|
|
140
|
+
1. Bump Ruby to **3.1+** and gem to **~> 2.0**.
|
|
141
|
+
2. Set **`OPENAI_API_KEY`** (keep `DALL_E_API_KEY` temporarily if needed).
|
|
142
|
+
3. Replace `generate_image(...)` with `generate(...)` and read `Response` fields instead of only a Hash.
|
|
143
|
+
4. Update defaults mentally: model is **`gpt-image-1`**, size **`1024x1024`**, not DALL·E 2 `512x512` / `image-alpha-001`.
|
|
144
|
+
5. Plan for **DALL·E 2/3 sunset (May 12, 2026)** — move prompts to GPT Image models.
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
bundle install
|
|
150
|
+
bundle exec rspec
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Interactive console:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
bin/console
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Contributing
|
|
160
|
+
|
|
161
|
+
Issues and pull requests are welcome on the [GitHub repository](https://github.com/merouaneamqor/generate_image).
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT. See [LICENSE.txt](LICENSE.txt).
|
data/Rakefile
ADDED
data/bin/console
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "generate_image"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "generate_image"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
IFS=$'\n\t'
|
|
4
|
-
set -vx
|
|
5
|
-
|
|
6
|
-
bundle install
|
|
7
|
-
|
|
8
|
-
# Do any other automated setup that you need to do here
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
IFS=$'\n\t'
|
|
4
|
+
set -vx
|
|
5
|
+
|
|
6
|
+
bundle install
|
|
7
|
+
|
|
8
|
+
# Do any other automated setup that you need to do here
|
|
Binary file
|