runapi-flux-2 0.2.6 → 0.2.8
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 +6 -6
- data/lib/runapi/flux_2/contract_gen.rb +72 -0
- data/lib/runapi/flux_2/resources/remix_image.rb +8 -30
- data/lib/runapi/flux_2/resources/text_to_image.rb +8 -23
- data/lib/runapi/flux_2/types.rb +1 -13
- data/lib/runapi/flux_2.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: d544661cb2f60b5ce01db31957bbd31c34aceba21b784ded8afe989327a7b27b
|
|
4
|
+
data.tar.gz: cbeaa074da2d18d81869030cd38f2f505a71705a95b740ae18aecc3e364850c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7590f860d80b15991edd473001b6a537dcf74c763574e27bed6aa6d02c487d07f1c3324681fc4c873cbb4b7ed8578588a32f88ae2d93a69b65c5a0ab2d5a2f22
|
|
7
|
+
data.tar.gz: e4a8ff221b6d0234bf99a537d2500f132a6c3092e6a83a3813a1c6d1c1f130bf96ab0e52fdf8a4bd36da5a133ff022b8c14a4d91d5ab7d7faf6b58aa9eeca892
|
data/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Flux API Ruby SDK for RunAPI
|
|
1
|
+
# Flux 2 API Ruby SDK for RunAPI
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Flux 2 Ruby SDK is the language-specific package for Flux 2 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 `flux-2-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/flux-2; for API reference, use https://runapi.ai/docs#flux-2; for SDK docs, use https://runapi.ai/docs#sdk-flux-2.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
gem install runapi-
|
|
10
|
+
gem install runapi-flux-2
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
@@ -27,7 +27,7 @@ status = client.text_to_image.get(task.id)
|
|
|
27
27
|
remix = client.remix_image.create(
|
|
28
28
|
model: "flux-2-pro-remix-image",
|
|
29
29
|
prompt: "Turn this product shot into a warm editorial photo",
|
|
30
|
-
source_image_urls: ["https://
|
|
30
|
+
source_image_urls: ["https://cdn.runapi.ai/public/samples/image.jpg"],
|
|
31
31
|
aspect_ratio: "auto"
|
|
32
32
|
)
|
|
33
33
|
```
|
|
@@ -38,7 +38,7 @@ RunAPI-generated file URLs are temporary. Download and store generated images, v
|
|
|
38
38
|
|
|
39
39
|
## Language notes
|
|
40
40
|
|
|
41
|
-
Use Ruby keyword arguments and the `RunApi::Flux2` error classes when building image jobs, Rails workers, or scripts. The available resources
|
|
41
|
+
Use Ruby keyword arguments and the `RunApi::Flux2` error classes when building image jobs, Rails workers, or scripts. The available resources are `text_to_image` and `remix_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
|
42
42
|
|
|
43
43
|
## Links
|
|
44
44
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RunApi
|
|
4
|
+
module Flux2
|
|
5
|
+
CONTRACT = {
|
|
6
|
+
"remix-image" => {
|
|
7
|
+
"models" => ["flux-2-flex-remix-image", "flux-2-pro-remix-image"],
|
|
8
|
+
"fields_by_model" => {
|
|
9
|
+
"flux-2-flex-remix-image" => {
|
|
10
|
+
"aspect_ratio" => {
|
|
11
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3", "auto"]
|
|
12
|
+
},
|
|
13
|
+
"output_resolution" => {
|
|
14
|
+
"enum" => ["1k", "2k"]
|
|
15
|
+
},
|
|
16
|
+
"prompt" => {
|
|
17
|
+
"required" => true
|
|
18
|
+
},
|
|
19
|
+
"source_image_urls" => {
|
|
20
|
+
"required" => true,
|
|
21
|
+
"min_items" => 1,
|
|
22
|
+
"max_items" => 8
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"flux-2-pro-remix-image" => {
|
|
26
|
+
"aspect_ratio" => {
|
|
27
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3", "auto"]
|
|
28
|
+
},
|
|
29
|
+
"output_resolution" => {
|
|
30
|
+
"enum" => ["1k", "2k"]
|
|
31
|
+
},
|
|
32
|
+
"prompt" => {
|
|
33
|
+
"required" => true
|
|
34
|
+
},
|
|
35
|
+
"source_image_urls" => {
|
|
36
|
+
"required" => true,
|
|
37
|
+
"min_items" => 1,
|
|
38
|
+
"max_items" => 8
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"text-to-image" => {
|
|
44
|
+
"models" => ["flux-2-flex-text-to-image", "flux-2-pro-text-to-image"],
|
|
45
|
+
"fields_by_model" => {
|
|
46
|
+
"flux-2-flex-text-to-image" => {
|
|
47
|
+
"aspect_ratio" => {
|
|
48
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
|
|
49
|
+
},
|
|
50
|
+
"output_resolution" => {
|
|
51
|
+
"enum" => ["1k", "2k"]
|
|
52
|
+
},
|
|
53
|
+
"prompt" => {
|
|
54
|
+
"required" => true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"flux-2-pro-text-to-image" => {
|
|
58
|
+
"aspect_ratio" => {
|
|
59
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
|
|
60
|
+
},
|
|
61
|
+
"output_resolution" => {
|
|
62
|
+
"enum" => ["1k", "2k"]
|
|
63
|
+
},
|
|
64
|
+
"prompt" => {
|
|
65
|
+
"required" => true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}.freeze
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -17,41 +17,19 @@ module RunApi
|
|
|
17
17
|
@http = http
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def run(**params)
|
|
21
|
-
task = create(**params)
|
|
22
|
-
poll_until_complete { get(task.id) }
|
|
20
|
+
def run(options: nil, **params)
|
|
21
|
+
task = create(options: options, **params)
|
|
22
|
+
poll_until_complete { get(task.id, options: options) }
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def create(**params)
|
|
25
|
+
def create(options: nil, **params)
|
|
26
26
|
params = compact_params(params)
|
|
27
|
-
|
|
28
|
-
request(:post, ENDPOINT, body: params)
|
|
27
|
+
validate_contract!(CONTRACT["remix-image"], params)
|
|
28
|
+
request(:post, ENDPOINT, body: params, options: options)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def get(id)
|
|
32
|
-
request(:get, "#{ENDPOINT}/#{id}")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def validate_params!(params)
|
|
38
|
-
model = param(params, :model)
|
|
39
|
-
raise Core::ValidationError, "model is required" unless model
|
|
40
|
-
unless Types::REMIX_MODELS.include?(model)
|
|
41
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::REMIX_MODELS.join(", ")}"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
prompt = param(params, :prompt)
|
|
45
|
-
raise Core::ValidationError, "prompt is required" unless prompt
|
|
46
|
-
|
|
47
|
-
validate_optional!(params, :aspect_ratio, Types::REMIX_ASPECT_RATIOS)
|
|
48
|
-
validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
|
|
49
|
-
validate_source_image_urls!(params)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def validate_source_image_urls!(params)
|
|
53
|
-
urls = param(params, :source_image_urls)
|
|
54
|
-
raise Core::ValidationError, "source_image_urls is required" if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
|
|
31
|
+
def get(id, options: nil)
|
|
32
|
+
request(:get, "#{ENDPOINT}/#{id}", options: options)
|
|
55
33
|
end
|
|
56
34
|
end
|
|
57
35
|
end
|
|
@@ -21,42 +21,27 @@ module RunApi
|
|
|
21
21
|
#
|
|
22
22
|
# @param params [Hash] text-to-image parameters
|
|
23
23
|
# @return [RunApi::Flux2::Types::CompletedTextToImageResponse] completed text-to-image result
|
|
24
|
-
def run(**params)
|
|
25
|
-
task = create(**params)
|
|
26
|
-
poll_until_complete { get(task.id) }
|
|
24
|
+
def run(options: nil, **params)
|
|
25
|
+
task = create(options: options, **params)
|
|
26
|
+
poll_until_complete { get(task.id, options: options) }
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Create a text-to-image task.
|
|
30
30
|
#
|
|
31
31
|
# @param params [Hash] text-to-image parameters
|
|
32
32
|
# @return [RunApi::Flux2::Types::TextToImageResponse] task creation result with id
|
|
33
|
-
def create(**params)
|
|
33
|
+
def create(options: nil, **params)
|
|
34
34
|
params = compact_params(params)
|
|
35
|
-
|
|
36
|
-
request(:post, ENDPOINT, body: params)
|
|
35
|
+
validate_contract!(CONTRACT["text-to-image"], params)
|
|
36
|
+
request(:post, ENDPOINT, body: params, options: options)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# Get text-to-image status by task ID.
|
|
40
40
|
#
|
|
41
41
|
# @param id [String] task ID
|
|
42
42
|
# @return [RunApi::Flux2::Types::TextToImageResponse] current text-to-image status
|
|
43
|
-
def get(id)
|
|
44
|
-
request(:get, "#{ENDPOINT}/#{id}")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
def validate_params!(params)
|
|
50
|
-
raise Core::ValidationError, "model is required" unless param(params, :model)
|
|
51
|
-
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
52
|
-
|
|
53
|
-
model = param(params, :model)
|
|
54
|
-
unless Types::TEXT_TO_IMAGE_MODELS.include?(model)
|
|
55
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
59
|
-
validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
|
|
43
|
+
def get(id, options: nil)
|
|
44
|
+
request(:get, "#{ENDPOINT}/#{id}", options: options)
|
|
60
45
|
end
|
|
61
46
|
end
|
|
62
47
|
end
|
data/lib/runapi/flux_2/types.rb
CHANGED
|
@@ -2,21 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Flux2
|
|
5
|
-
# Type definitions
|
|
5
|
+
# Type definitions for Flux 2.
|
|
6
6
|
# Each operation has pro (higher fidelity) and flex (faster, lower cost) tiers.
|
|
7
7
|
module Types
|
|
8
|
-
MODELS = %w[
|
|
9
|
-
flux-2-pro-text-to-image flux-2-pro-remix-image
|
|
10
|
-
flux-2-flex-text-to-image flux-2-flex-remix-image
|
|
11
|
-
].freeze
|
|
12
|
-
TEXT_TO_IMAGE_MODELS = %w[flux-2-pro-text-to-image flux-2-flex-text-to-image].freeze
|
|
13
|
-
REMIX_MODELS = %w[flux-2-pro-remix-image flux-2-flex-remix-image].freeze
|
|
14
|
-
|
|
15
|
-
ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 3:2 2:3].freeze
|
|
16
|
-
# Remix adds 'auto' to preserve the source image aspect ratio.
|
|
17
|
-
REMIX_ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 3:2 2:3 auto].freeze
|
|
18
|
-
OUTPUT_RESOLUTIONS = %w[1k 2k].freeze
|
|
19
|
-
|
|
20
8
|
# A single generated image with its CDN URL.
|
|
21
9
|
class Image < RunApi::Core::BaseModel
|
|
22
10
|
optional :url, String
|
data/lib/runapi/flux_2.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runapi-flux-2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.8
|
|
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.14
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
version: 0.2.14
|
|
26
|
+
description: The Flux 2 Ruby SDK is the language-specific package for Flux 2 on RunAPI.
|
|
27
|
+
Use this package for image generation, image editing, and creative production workflows
|
|
28
|
+
when your application needs request bodies, task status lookup, and consistent RunAPI
|
|
29
|
+
errors in Ruby.
|
|
30
30
|
email:
|
|
31
31
|
- contact@runapi.ai
|
|
32
32
|
executables: []
|
|
@@ -39,6 +39,7 @@ files:
|
|
|
39
39
|
- lib/runapi-flux_2.rb
|
|
40
40
|
- lib/runapi/flux_2.rb
|
|
41
41
|
- lib/runapi/flux_2/client.rb
|
|
42
|
+
- lib/runapi/flux_2/contract_gen.rb
|
|
42
43
|
- lib/runapi/flux_2/resources/remix_image.rb
|
|
43
44
|
- lib/runapi/flux_2/resources/text_to_image.rb
|
|
44
45
|
- lib/runapi/flux_2/types.rb
|
|
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/flux-2
|
|
|
46
47
|
licenses:
|
|
47
48
|
- Apache-2.0
|
|
48
49
|
metadata:
|
|
50
|
+
runapi_slug: flux-2
|
|
49
51
|
homepage_uri: https://runapi.ai/models/flux-2
|
|
50
52
|
documentation_uri: https://github.com/runapi-ai/flux-2-sdk/blob/main/ruby/README.md
|
|
51
53
|
source_code_uri: https://github.com/runapi-ai/flux-2-sdk
|
|
54
|
+
bug_tracker_uri: https://github.com/runapi-ai/flux-2-sdk/issues
|
|
52
55
|
changelog_uri: https://github.com/runapi-ai/flux-2-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: Flux API Ruby SDK for RunAPI
|
|
72
|
+
summary: Flux 2 API Ruby SDK for RunAPI
|
|
70
73
|
test_files: []
|