runapi-gpt-image 0.2.5 → 0.2.7
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/README.md +8 -6
- data/lib/runapi/gpt_image/client.rb +5 -6
- data/lib/runapi/gpt_image/contract_gen.rb +47 -0
- data/lib/runapi/gpt_image/resources/edit_image.rb +1 -23
- data/lib/runapi/gpt_image/resources/text_to_image.rb +1 -18
- data/lib/runapi/gpt_image/types.rb +5 -7
- data/lib/runapi/gpt_image.rb +1 -0
- metadata +11 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aefd21d6faae0bc4b3b8d5233eeef9015c8377a2aba2e2ab0414aeae082ce8bd
|
|
4
|
+
data.tar.gz: 80a91ab1e6a9066e61cac383a2e241396b09274052c8db4f234d35d44d322d10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6eadbfd617f632ed1ef9c989884b80782a6fe3ca5ac64ec5d9e6f48e515d7d51d5ba6ec8d4f6bd1c2a7cba62949575872eb00be0eb53901b05327a48c8ff0213
|
|
7
|
+
data.tar.gz: 3083b5683b15cf97eba4ae9c7a5cef84b49f6ab16bfe4a9112f136a59b84d57a83ade4df34b18354882d901c2b308c953e81d4bb6aa71533cc300372b7aa6936
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# GPT Image
|
|
1
|
+
# GPT Image Ruby SDK for RunAPI
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The GPT Image Ruby SDK is the language-specific package for GPT Image on RunAPI. Use this package for image generation, image editing, and creative production workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Ruby.
|
|
4
4
|
|
|
5
|
-
This
|
|
5
|
+
This README is the Ruby package guide inside the public `gpt-image-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-image; for API reference, use https://runapi.ai/docs#gpt-image; for SDK docs, use https://runapi.ai/docs#sdk-gpt-image.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -16,17 +16,19 @@ gem install runapi-gpt-image
|
|
|
16
16
|
require "runapi-gpt-image"
|
|
17
17
|
|
|
18
18
|
client = RunApi::GptImage::Client.new
|
|
19
|
-
task = client.
|
|
19
|
+
task = client.text_to_image.create(
|
|
20
20
|
# Pass the GPT Image JSON request body from https://runapi.ai/docs#gpt-image.
|
|
21
21
|
)
|
|
22
|
-
status = client.
|
|
22
|
+
status = client.text_to_image.get(task.id)
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Use `create` when you want to submit a task and return quickly, `get` when you need the latest task state, and `run` when a script should create and poll until completion. In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
|
|
26
26
|
|
|
27
|
+
RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
|
|
28
|
+
|
|
27
29
|
## Language notes
|
|
28
30
|
|
|
29
|
-
Use Ruby keyword arguments and the `RunApi::GptImage` error classes when building image jobs, Rails workers, or scripts. The available resources
|
|
31
|
+
Use Ruby keyword arguments and the `RunApi::GptImage` error classes when building image jobs, Rails workers, or scripts. The available resources are `text_to_image` and `edit_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
|
30
32
|
|
|
31
33
|
## Links
|
|
32
34
|
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module GptImage
|
|
5
|
-
# GPT Image 1.5
|
|
5
|
+
# GPT Image 1.5 generation and editing API client.
|
|
6
|
+
#
|
|
7
|
+
# Both aspect_ratio and quality are required for all operations.
|
|
6
8
|
#
|
|
7
9
|
# @example
|
|
8
10
|
# client = RunApi::GptImage::Client.new(api_key: "your-api-key")
|
|
@@ -18,17 +20,14 @@ module RunApi
|
|
|
18
20
|
# prompt: "Transform into oil painting",
|
|
19
21
|
# source_image_urls: ["https://cdn.runapi.ai/public/samples/photo.jpg"]
|
|
20
22
|
# )
|
|
21
|
-
class Client
|
|
23
|
+
class Client < RunApi::Core::Client
|
|
22
24
|
# @return [Resources::TextToImage] Text-to-image generation operations.
|
|
23
25
|
attr_reader :text_to_image
|
|
24
26
|
# @return [Resources::EditImage] Image edit operations.
|
|
25
27
|
attr_reader :edit_image
|
|
26
28
|
|
|
27
29
|
def initialize(api_key: nil, **options)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
client_options = Core::ClientOptions.new(api_key: @api_key, **options)
|
|
31
|
-
http = client_options.http_client || Core::HttpClient.new(client_options)
|
|
30
|
+
super
|
|
32
31
|
@text_to_image = Resources::TextToImage.new(http)
|
|
33
32
|
@edit_image = Resources::EditImage.new(http)
|
|
34
33
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RunApi
|
|
4
|
+
module GptImage
|
|
5
|
+
CONTRACT = {
|
|
6
|
+
"edit-image" => {
|
|
7
|
+
"models" => ["gpt-image-1.5"],
|
|
8
|
+
"fields_by_model" => {
|
|
9
|
+
"gpt-image-1.5" => {
|
|
10
|
+
"aspect_ratio" => {
|
|
11
|
+
"enum" => ["1:1", "2:3", "3:2"],
|
|
12
|
+
"required" => true
|
|
13
|
+
},
|
|
14
|
+
"prompt" => {
|
|
15
|
+
"required" => true
|
|
16
|
+
},
|
|
17
|
+
"quality" => {
|
|
18
|
+
"enum" => ["medium", "high"],
|
|
19
|
+
"required" => true
|
|
20
|
+
},
|
|
21
|
+
"source_image_urls" => {
|
|
22
|
+
"required" => true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"text-to-image" => {
|
|
28
|
+
"models" => ["gpt-image-1.5"],
|
|
29
|
+
"fields_by_model" => {
|
|
30
|
+
"gpt-image-1.5" => {
|
|
31
|
+
"aspect_ratio" => {
|
|
32
|
+
"enum" => ["1:1", "2:3", "3:2"],
|
|
33
|
+
"required" => true
|
|
34
|
+
},
|
|
35
|
+
"prompt" => {
|
|
36
|
+
"required" => true
|
|
37
|
+
},
|
|
38
|
+
"quality" => {
|
|
39
|
+
"enum" => ["medium", "high"],
|
|
40
|
+
"required" => true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}.freeze
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -31,7 +31,7 @@ module RunApi
|
|
|
31
31
|
# @return [RunApi::GptImage::Types::EditImageResponse] task creation result with id
|
|
32
32
|
def create(**params)
|
|
33
33
|
params = compact_params(params)
|
|
34
|
-
|
|
34
|
+
validate_contract!(CONTRACT["edit-image"], params)
|
|
35
35
|
request(:post, ENDPOINT, body: params)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -42,28 +42,6 @@ module RunApi
|
|
|
42
42
|
def get(id)
|
|
43
43
|
request(:get, "#{ENDPOINT}/#{id}")
|
|
44
44
|
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
def validate_params!(params)
|
|
49
|
-
raise Core::ValidationError, "model is required" unless param(params, :model)
|
|
50
|
-
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
51
|
-
|
|
52
|
-
model = param(params, :model)
|
|
53
|
-
unless Types::EDIT_MODELS.include?(model)
|
|
54
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::EDIT_MODELS.join(", ")}"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
urls = param(params, :source_image_urls)
|
|
58
|
-
if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
|
|
59
|
-
raise Core::ValidationError, "source_image_urls is required for image editing"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
|
|
63
|
-
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
64
|
-
raise Core::ValidationError, "quality is required" unless param(params, :quality)
|
|
65
|
-
validate_optional!(params, :quality, Types::QUALITY_VALUES)
|
|
66
|
-
end
|
|
67
45
|
end
|
|
68
46
|
end
|
|
69
47
|
end
|
|
@@ -31,7 +31,7 @@ module RunApi
|
|
|
31
31
|
# @return [RunApi::GptImage::Types::TextToImageResponse] task creation result with id
|
|
32
32
|
def create(**params)
|
|
33
33
|
params = compact_params(params)
|
|
34
|
-
|
|
34
|
+
validate_contract!(CONTRACT["text-to-image"], params)
|
|
35
35
|
request(:post, ENDPOINT, body: params)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -42,23 +42,6 @@ module RunApi
|
|
|
42
42
|
def get(id)
|
|
43
43
|
request(:get, "#{ENDPOINT}/#{id}")
|
|
44
44
|
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
def validate_params!(params)
|
|
49
|
-
raise Core::ValidationError, "model is required" unless param(params, :model)
|
|
50
|
-
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
51
|
-
|
|
52
|
-
model = param(params, :model)
|
|
53
|
-
unless Types::GENERATION_MODELS.include?(model)
|
|
54
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::GENERATION_MODELS.join(", ")}"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
|
|
58
|
-
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
59
|
-
raise Core::ValidationError, "quality is required" unless param(params, :quality)
|
|
60
|
-
validate_optional!(params, :quality, Types::QUALITY_VALUES)
|
|
61
|
-
end
|
|
62
45
|
end
|
|
63
46
|
end
|
|
64
47
|
end
|
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module GptImage
|
|
5
|
+
# Type definitions and constants for GPT Image 1.5.
|
|
6
|
+
# Both aspect_ratio and quality are required for all operations.
|
|
5
7
|
module Types
|
|
6
|
-
|
|
7
|
-
GENERATION_MODELS = MODELS
|
|
8
|
-
EDIT_MODELS = MODELS
|
|
9
|
-
|
|
10
|
-
ASPECT_RATIOS = %w[1:1 2:3 3:2].freeze
|
|
11
|
-
QUALITY_VALUES = %w[medium high].freeze
|
|
12
|
-
|
|
8
|
+
# A single generated image with its CDN URL.
|
|
13
9
|
class Image < RunApi::Core::BaseModel
|
|
14
10
|
optional :url, String
|
|
15
11
|
end
|
|
16
12
|
|
|
13
|
+
# Generation result. +images+ is populated once +status+ is +"completed"+.
|
|
17
14
|
class TextToImageResponse < RunApi::Core::TaskResponse
|
|
18
15
|
required :id, String
|
|
19
16
|
optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
|
|
@@ -21,6 +18,7 @@ module RunApi
|
|
|
21
18
|
optional :error, String
|
|
22
19
|
end
|
|
23
20
|
|
|
21
|
+
# Edit response -- same shape as generation.
|
|
24
22
|
EditImageResponse = TextToImageResponse
|
|
25
23
|
|
|
26
24
|
# Narrowed response returned by `run()` methods once polling observes
|
data/lib/runapi/gpt_image.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runapi-gpt-image
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RunAPI
|
|
@@ -15,18 +15,18 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.2.
|
|
18
|
+
version: 0.2.7
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.2.
|
|
26
|
-
description: The
|
|
27
|
-
on RunAPI. Use this
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
version: 0.2.7
|
|
26
|
+
description: The GPT Image Ruby SDK is the language-specific package for GPT Image
|
|
27
|
+
on RunAPI. Use this package for image generation, image editing, and creative production
|
|
28
|
+
workflows when your application needs request bodies, task status lookup, and consistent
|
|
29
|
+
RunAPI errors in Ruby.
|
|
30
30
|
email:
|
|
31
31
|
- contact@runapi.ai
|
|
32
32
|
executables: []
|
|
@@ -39,6 +39,7 @@ files:
|
|
|
39
39
|
- lib/runapi-gpt_image.rb
|
|
40
40
|
- lib/runapi/gpt_image.rb
|
|
41
41
|
- lib/runapi/gpt_image/client.rb
|
|
42
|
+
- lib/runapi/gpt_image/contract_gen.rb
|
|
42
43
|
- lib/runapi/gpt_image/resources/edit_image.rb
|
|
43
44
|
- lib/runapi/gpt_image/resources/text_to_image.rb
|
|
44
45
|
- lib/runapi/gpt_image/types.rb
|
|
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/gpt-image
|
|
|
46
47
|
licenses:
|
|
47
48
|
- Apache-2.0
|
|
48
49
|
metadata:
|
|
50
|
+
runapi_slug: gpt-image
|
|
49
51
|
homepage_uri: https://runapi.ai/models/gpt-image
|
|
50
52
|
documentation_uri: https://github.com/runapi-ai/gpt-image-sdk/blob/main/ruby/README.md
|
|
51
53
|
source_code_uri: https://github.com/runapi-ai/gpt-image-sdk
|
|
54
|
+
bug_tracker_uri: https://github.com/runapi-ai/gpt-image-sdk/issues
|
|
52
55
|
changelog_uri: https://github.com/runapi-ai/gpt-image-sdk/blob/main/CHANGELOG.md
|
|
53
56
|
rdoc_options: []
|
|
54
57
|
require_paths:
|
|
@@ -66,5 +69,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
66
69
|
requirements: []
|
|
67
70
|
rubygems_version: 4.0.10
|
|
68
71
|
specification_version: 4
|
|
69
|
-
summary: GPT Image
|
|
72
|
+
summary: GPT Image Ruby SDK for RunAPI
|
|
70
73
|
test_files: []
|