runapi-seedream 0.2.7 → 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 +8 -4
- data/lib/runapi/seedream/contract_gen.rb +200 -0
- data/lib/runapi/seedream/resources/edit_image.rb +18 -49
- data/lib/runapi/seedream/resources/text_to_image.rb +15 -50
- data/lib/runapi/seedream/types.rb +10 -15
- data/lib/runapi/seedream.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: 4e82b3b45f3ff8bc900025adeb9a0390aa67962cc89b301f71fbddfd38c4fe09
|
|
4
|
+
data.tar.gz: 2092d13fd4d8d1cb37f27e78b6c8423fa7d58e75bcd0588ede104e5a8e8e2004
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 775b36a48e102429084935f74046ee88703eaed8a1b69e86c1e100de6798166291857e211ba5f317e12a5db2a3aba89b1924c26b1d92508020110ae20583d36d
|
|
7
|
+
data.tar.gz: 315298e9ecd87fc3ac4209357364a3465944d8607d2cdddb5b03d1e76b46b551ed2fb00133f1a9e974f1e16b562c67e438c5ce16e16492611f60afa8948033d9
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Seedream
|
|
1
|
+
# Seedream Ruby SDK for RunAPI
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Seedream Ruby SDK is the language-specific package for Seedream 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 `seedream-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/seedream; for API reference, use https://runapi.ai/docs#seedream; for SDK docs, use https://runapi.ai/docs#sdk-seedream.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ gem install runapi-seedream
|
|
|
13
13
|
## Quick start
|
|
14
14
|
|
|
15
15
|
```ruby
|
|
16
|
-
require "runapi
|
|
16
|
+
require "runapi/seedream"
|
|
17
17
|
|
|
18
18
|
client = RunApi::Seedream::Client.new
|
|
19
19
|
task = client.text_to_image.create(
|
|
@@ -30,6 +30,10 @@ Use `create` when you want to submit a task and return quickly, `get` when you n
|
|
|
30
30
|
|
|
31
31
|
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.
|
|
32
32
|
|
|
33
|
+
## Seedream 5 Pro
|
|
34
|
+
|
|
35
|
+
Use `seedream-5-pro-text-to-image` for generation and `seedream-5-pro-edit` for image editing. Both accept `output_quality`, optional `output_format`, and optional content safety checking; editing accepts up to 10 source image URLs.
|
|
36
|
+
|
|
33
37
|
## Language notes
|
|
34
38
|
|
|
35
39
|
Use Ruby keyword arguments and the `RunApi::Seedream` error classes when building image jobs, Rails workers, or scripts. The package exposes `text_to_image` for text models and `edit_image` for editing models. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RunApi
|
|
4
|
+
module Seedream
|
|
5
|
+
CONTRACT = {
|
|
6
|
+
"edit-image" => {
|
|
7
|
+
"models" => ["seedream-4.5-edit", "seedream-5-lite-edit", "seedream-5-pro-edit", "seedream-v4-edit"],
|
|
8
|
+
"fields_by_model" => {
|
|
9
|
+
"seedream-4.5-edit" => {
|
|
10
|
+
"aspect_ratio" => {
|
|
11
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
|
|
12
|
+
"required" => true
|
|
13
|
+
},
|
|
14
|
+
"output_count" => {
|
|
15
|
+
"type" => "integer"
|
|
16
|
+
},
|
|
17
|
+
"output_quality" => {
|
|
18
|
+
"enum" => ["basic", "high"],
|
|
19
|
+
"required" => true
|
|
20
|
+
},
|
|
21
|
+
"seed" => {
|
|
22
|
+
"type" => "integer"
|
|
23
|
+
},
|
|
24
|
+
"source_image_urls" => {
|
|
25
|
+
"required" => true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"seedream-5-lite-edit" => {
|
|
29
|
+
"aspect_ratio" => {
|
|
30
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
|
|
31
|
+
"required" => true
|
|
32
|
+
},
|
|
33
|
+
"output_count" => {
|
|
34
|
+
"type" => "integer"
|
|
35
|
+
},
|
|
36
|
+
"output_format" => {
|
|
37
|
+
"enum" => ["png", "jpeg"]
|
|
38
|
+
},
|
|
39
|
+
"output_quality" => {
|
|
40
|
+
"enum" => ["basic", "high"],
|
|
41
|
+
"required" => true
|
|
42
|
+
},
|
|
43
|
+
"seed" => {
|
|
44
|
+
"type" => "integer"
|
|
45
|
+
},
|
|
46
|
+
"source_image_urls" => {
|
|
47
|
+
"required" => true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"seedream-5-pro-edit" => {
|
|
51
|
+
"aspect_ratio" => {
|
|
52
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
|
|
53
|
+
"required" => true
|
|
54
|
+
},
|
|
55
|
+
"output_format" => {
|
|
56
|
+
"enum" => ["png", "jpeg"]
|
|
57
|
+
},
|
|
58
|
+
"output_quality" => {
|
|
59
|
+
"enum" => ["basic", "high"],
|
|
60
|
+
"required" => true
|
|
61
|
+
},
|
|
62
|
+
"prompt" => {
|
|
63
|
+
"required" => true,
|
|
64
|
+
"min" => 3,
|
|
65
|
+
"max" => 5000,
|
|
66
|
+
"length" => true
|
|
67
|
+
},
|
|
68
|
+
"source_image_urls" => {
|
|
69
|
+
"required" => true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"seedream-v4-edit" => {
|
|
73
|
+
"aspect_ratio" => {
|
|
74
|
+
"enum" => ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16", "21:9"]
|
|
75
|
+
},
|
|
76
|
+
"output_count" => {
|
|
77
|
+
"enum" => [1, 2, 3, 4, 5, 6],
|
|
78
|
+
"type" => "integer"
|
|
79
|
+
},
|
|
80
|
+
"output_resolution" => {
|
|
81
|
+
"enum" => ["1k", "2k", "4k"]
|
|
82
|
+
},
|
|
83
|
+
"seed" => {
|
|
84
|
+
"type" => "integer"
|
|
85
|
+
},
|
|
86
|
+
"source_image_urls" => {
|
|
87
|
+
"required" => true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"rules" => [{
|
|
92
|
+
"when" => {
|
|
93
|
+
"model" => "seedream-4.5-edit"
|
|
94
|
+
},
|
|
95
|
+
"forbidden" => ["output_format"]
|
|
96
|
+
}, {
|
|
97
|
+
"when" => {
|
|
98
|
+
"model" => "seedream-5-pro-edit"
|
|
99
|
+
},
|
|
100
|
+
"forbidden" => ["output_resolution", "output_count", "seed"]
|
|
101
|
+
}, {
|
|
102
|
+
"when" => {
|
|
103
|
+
"model" => "seedream-v4-edit"
|
|
104
|
+
},
|
|
105
|
+
"forbidden" => ["output_format"]
|
|
106
|
+
}]
|
|
107
|
+
},
|
|
108
|
+
"text-to-image" => {
|
|
109
|
+
"models" => ["seedream-4.5-text-to-image", "seedream-5-lite-text-to-image", "seedream-5-pro-text-to-image", "seedream-v4-text-to-image"],
|
|
110
|
+
"fields_by_model" => {
|
|
111
|
+
"seedream-4.5-text-to-image" => {
|
|
112
|
+
"aspect_ratio" => {
|
|
113
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
|
|
114
|
+
"required" => true
|
|
115
|
+
},
|
|
116
|
+
"output_count" => {
|
|
117
|
+
"type" => "integer"
|
|
118
|
+
},
|
|
119
|
+
"output_quality" => {
|
|
120
|
+
"enum" => ["basic", "high"],
|
|
121
|
+
"required" => true
|
|
122
|
+
},
|
|
123
|
+
"seed" => {
|
|
124
|
+
"type" => "integer"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"seedream-5-lite-text-to-image" => {
|
|
128
|
+
"aspect_ratio" => {
|
|
129
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
|
|
130
|
+
"required" => true
|
|
131
|
+
},
|
|
132
|
+
"output_count" => {
|
|
133
|
+
"type" => "integer"
|
|
134
|
+
},
|
|
135
|
+
"output_format" => {
|
|
136
|
+
"enum" => ["png", "jpeg"]
|
|
137
|
+
},
|
|
138
|
+
"output_quality" => {
|
|
139
|
+
"enum" => ["basic", "high"],
|
|
140
|
+
"required" => true
|
|
141
|
+
},
|
|
142
|
+
"seed" => {
|
|
143
|
+
"type" => "integer"
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"seedream-5-pro-text-to-image" => {
|
|
147
|
+
"aspect_ratio" => {
|
|
148
|
+
"enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
|
|
149
|
+
"required" => true
|
|
150
|
+
},
|
|
151
|
+
"output_format" => {
|
|
152
|
+
"enum" => ["png", "jpeg"]
|
|
153
|
+
},
|
|
154
|
+
"output_quality" => {
|
|
155
|
+
"enum" => ["basic", "high"],
|
|
156
|
+
"required" => true
|
|
157
|
+
},
|
|
158
|
+
"prompt" => {
|
|
159
|
+
"required" => true,
|
|
160
|
+
"min" => 3,
|
|
161
|
+
"max" => 5000,
|
|
162
|
+
"length" => true
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"seedream-v4-text-to-image" => {
|
|
166
|
+
"aspect_ratio" => {
|
|
167
|
+
"enum" => ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16", "21:9"]
|
|
168
|
+
},
|
|
169
|
+
"output_count" => {
|
|
170
|
+
"enum" => [1, 2, 3, 4, 5, 6],
|
|
171
|
+
"type" => "integer"
|
|
172
|
+
},
|
|
173
|
+
"output_resolution" => {
|
|
174
|
+
"enum" => ["1k", "2k", "4k"]
|
|
175
|
+
},
|
|
176
|
+
"seed" => {
|
|
177
|
+
"type" => "integer"
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"rules" => [{
|
|
182
|
+
"when" => {
|
|
183
|
+
"model" => "seedream-4.5-text-to-image"
|
|
184
|
+
},
|
|
185
|
+
"forbidden" => ["output_format"]
|
|
186
|
+
}, {
|
|
187
|
+
"when" => {
|
|
188
|
+
"model" => "seedream-5-pro-text-to-image"
|
|
189
|
+
},
|
|
190
|
+
"forbidden" => ["output_resolution", "output_count", "seed"]
|
|
191
|
+
}, {
|
|
192
|
+
"when" => {
|
|
193
|
+
"model" => "seedream-v4-text-to-image"
|
|
194
|
+
},
|
|
195
|
+
"forbidden" => ["output_format"]
|
|
196
|
+
}]
|
|
197
|
+
}
|
|
198
|
+
}.freeze
|
|
199
|
+
end
|
|
200
|
+
end
|
|
@@ -5,7 +5,7 @@ module RunApi
|
|
|
5
5
|
module Resources
|
|
6
6
|
# Seedream image editing resource.
|
|
7
7
|
# Modifies source images according to a text prompt.
|
|
8
|
-
# V4
|
|
8
|
+
# 5 Pro and V4 accept up to 10 source images; 4.5 and 5-Lite accept up to 14.
|
|
9
9
|
class EditImage
|
|
10
10
|
include RunApi::Core::ResourceHelpers
|
|
11
11
|
|
|
@@ -15,70 +15,48 @@ module RunApi
|
|
|
15
15
|
PROMPT_MAX_LENGTH = 3000
|
|
16
16
|
V4_PROMPT_MAX_LENGTH = 5000
|
|
17
17
|
PROMPT_MIN_LENGTH_LITE = 3
|
|
18
|
-
V4_OUTPUT_COUNT_RANGE = (1..6)
|
|
19
18
|
|
|
20
19
|
def initialize(http)
|
|
21
20
|
@http = http
|
|
22
21
|
end
|
|
23
22
|
|
|
24
|
-
def run(**params)
|
|
25
|
-
task = create(**params)
|
|
26
|
-
poll_until_complete { get(task.id) }
|
|
23
|
+
def run(options: nil, **params)
|
|
24
|
+
task = create(options: options, **params)
|
|
25
|
+
poll_until_complete { get(task.id, options: options) }
|
|
27
26
|
end
|
|
28
27
|
|
|
29
|
-
def create(**params)
|
|
28
|
+
def create(options: nil, **params)
|
|
30
29
|
params = compact_params(params)
|
|
31
30
|
validate_params!(params)
|
|
32
|
-
request(:post, ENDPOINT, body: params)
|
|
31
|
+
request(:post, ENDPOINT, body: params, options: options)
|
|
33
32
|
end
|
|
34
33
|
|
|
35
|
-
def get(id)
|
|
36
|
-
request(:get, "#{ENDPOINT}/#{id}")
|
|
34
|
+
def get(id, options: nil)
|
|
35
|
+
request(:get, "#{ENDPOINT}/#{id}", options: options)
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
private
|
|
40
39
|
|
|
41
40
|
def validate_params!(params)
|
|
41
|
+
validate_contract!(CONTRACT["edit-image"], params)
|
|
42
|
+
|
|
42
43
|
model = param(params, :model)
|
|
43
|
-
raise Core::ValidationError, "model is required" unless model
|
|
44
|
-
unless Types::EDIT_MODELS.include?(model)
|
|
45
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::EDIT_MODELS.join(", ")}"
|
|
46
|
-
end
|
|
47
44
|
|
|
48
45
|
prompt = param(params, :prompt)
|
|
49
46
|
raise Core::ValidationError, "prompt is required" unless prompt.is_a?(String) && !prompt.empty?
|
|
50
|
-
max_length = Types::
|
|
47
|
+
max_length = Types::LONG_PROMPT_MODELS.include?(model) ? V4_PROMPT_MAX_LENGTH : PROMPT_MAX_LENGTH
|
|
51
48
|
raise Core::ValidationError, "prompt must be at most #{max_length} characters" if prompt.length > max_length
|
|
52
|
-
if Types::
|
|
53
|
-
raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{
|
|
49
|
+
if Types::MINIMUM_THREE_PROMPT_MODELS.include?(model) && prompt.length < PROMPT_MIN_LENGTH_LITE
|
|
50
|
+
raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{max_length} characters"
|
|
54
51
|
end
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if
|
|
59
|
-
|
|
60
|
-
validate_optional!(params, :output_resolution, Types::V4_OUTPUT_RESOLUTIONS)
|
|
61
|
-
validate_integer_range!(params, :output_count, V4_OUTPUT_COUNT_RANGE)
|
|
62
|
-
validate_integer!(params, :seed)
|
|
63
|
-
else
|
|
64
|
-
validate_required!(params, :aspect_ratio)
|
|
65
|
-
validate_required!(params, :output_quality)
|
|
66
|
-
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
67
|
-
validate_optional!(params, :output_quality, Types::OUTPUT_QUALITIES)
|
|
53
|
+
source_image_urls = param(params, :source_image_urls)
|
|
54
|
+
source_image_max = Types::TEN_SOURCE_IMAGE_MODELS.include?(model) ? 10 : 14
|
|
55
|
+
if source_image_urls.is_a?(Array) && source_image_urls.length > source_image_max
|
|
56
|
+
raise Core::ValidationError, "source_image_urls accepts at most #{source_image_max} images"
|
|
68
57
|
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def validate_required!(params, key)
|
|
72
|
-
raise Core::ValidationError, "#{key} is required" unless field_present?(params, key)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def field_present?(params, key)
|
|
76
|
-
value = param(params, key)
|
|
77
|
-
return false if value.nil?
|
|
78
|
-
return value.any? if value.is_a?(Array)
|
|
79
|
-
return !value.empty? if value.respond_to?(:empty?)
|
|
80
58
|
|
|
81
|
-
|
|
59
|
+
validate_integer!(params, :seed) if Types::V4_MODELS.include?(model)
|
|
82
60
|
end
|
|
83
61
|
|
|
84
62
|
def validate_integer!(params, key)
|
|
@@ -88,15 +66,6 @@ module RunApi
|
|
|
88
66
|
|
|
89
67
|
raise Core::ValidationError, "#{key} must be an integer"
|
|
90
68
|
end
|
|
91
|
-
|
|
92
|
-
def validate_integer_range!(params, key, range)
|
|
93
|
-
value = param(params, key)
|
|
94
|
-
return if value.nil?
|
|
95
|
-
|
|
96
|
-
return if value.is_a?(Integer) && range.cover?(value)
|
|
97
|
-
|
|
98
|
-
raise Core::ValidationError, "#{key} must be between #{range.first} and #{range.last}"
|
|
99
|
-
end
|
|
100
69
|
end
|
|
101
70
|
end
|
|
102
71
|
end
|
|
@@ -4,8 +4,8 @@ module RunApi
|
|
|
4
4
|
module Seedream
|
|
5
5
|
module Resources
|
|
6
6
|
# Seedream text-to-image generation resource.
|
|
7
|
-
# Field requirements vary by model: 4.5/5-
|
|
8
|
-
# output_quality; V4 uses output_resolution and supports seed/output_count.
|
|
7
|
+
# Field requirements vary by model: 4.5/5-Lite/5 Pro require aspect_ratio
|
|
8
|
+
# and output_quality; V4 uses output_resolution and supports seed/output_count.
|
|
9
9
|
class TextToImage
|
|
10
10
|
include RunApi::Core::ResourceHelpers
|
|
11
11
|
|
|
@@ -15,74 +15,48 @@ module RunApi
|
|
|
15
15
|
PROMPT_MAX_LENGTH = 3000
|
|
16
16
|
V4_PROMPT_MAX_LENGTH = 5000
|
|
17
17
|
PROMPT_MIN_LENGTH_LITE = 3
|
|
18
|
-
V4_OUTPUT_COUNT_RANGE = (1..6)
|
|
19
18
|
|
|
20
19
|
def initialize(http)
|
|
21
20
|
@http = http
|
|
22
21
|
end
|
|
23
22
|
|
|
24
|
-
def run(**params)
|
|
25
|
-
task = create(**params)
|
|
26
|
-
poll_until_complete { get(task.id) }
|
|
23
|
+
def run(options: nil, **params)
|
|
24
|
+
task = create(options: options, **params)
|
|
25
|
+
poll_until_complete { get(task.id, options: options) }
|
|
27
26
|
end
|
|
28
27
|
|
|
29
|
-
def create(**params)
|
|
28
|
+
def create(options: nil, **params)
|
|
30
29
|
params = compact_params(params)
|
|
31
30
|
validate_params!(params)
|
|
32
|
-
request(:post, ENDPOINT, body: params)
|
|
31
|
+
request(:post, ENDPOINT, body: params, options: options)
|
|
33
32
|
end
|
|
34
33
|
|
|
35
|
-
def get(id)
|
|
36
|
-
request(:get, "#{ENDPOINT}/#{id}")
|
|
34
|
+
def get(id, options: nil)
|
|
35
|
+
request(:get, "#{ENDPOINT}/#{id}", options: options)
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
private
|
|
40
39
|
|
|
41
40
|
def validate_params!(params)
|
|
41
|
+
validate_contract!(CONTRACT["text-to-image"], params)
|
|
42
|
+
|
|
42
43
|
model = param(params, :model)
|
|
43
|
-
raise Core::ValidationError, "model is required" unless model
|
|
44
|
-
unless Types::TEXT_TO_IMAGE_MODELS.include?(model)
|
|
45
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
|
|
46
|
-
end
|
|
47
44
|
|
|
48
45
|
prompt = param(params, :prompt)
|
|
49
46
|
raise Core::ValidationError, "prompt is required" unless prompt.is_a?(String) && !prompt.empty?
|
|
50
|
-
max_length = Types::
|
|
47
|
+
max_length = Types::LONG_PROMPT_MODELS.include?(model) ? V4_PROMPT_MAX_LENGTH : PROMPT_MAX_LENGTH
|
|
51
48
|
raise Core::ValidationError, "prompt must be at most #{max_length} characters" if prompt.length > max_length
|
|
52
|
-
if Types::
|
|
53
|
-
raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{
|
|
49
|
+
if Types::MINIMUM_THREE_PROMPT_MODELS.include?(model) && prompt.length < PROMPT_MIN_LENGTH_LITE
|
|
50
|
+
raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{max_length} characters"
|
|
54
51
|
end
|
|
55
52
|
|
|
56
|
-
if Types::V4_MODELS.include?(model)
|
|
57
|
-
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
58
|
-
validate_optional!(params, :output_resolution, Types::V4_OUTPUT_RESOLUTIONS)
|
|
59
|
-
validate_integer_range!(params, :output_count, V4_OUTPUT_COUNT_RANGE)
|
|
60
|
-
validate_integer!(params, :seed)
|
|
61
|
-
else
|
|
62
|
-
validate_required!(params, :aspect_ratio)
|
|
63
|
-
validate_required!(params, :output_quality)
|
|
64
|
-
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
65
|
-
validate_optional!(params, :output_quality, Types::OUTPUT_QUALITIES)
|
|
66
|
-
end
|
|
53
|
+
validate_integer!(params, :seed) if Types::V4_MODELS.include?(model)
|
|
67
54
|
|
|
68
55
|
if field_present?(params, :source_image_urls)
|
|
69
56
|
raise Core::ValidationError, "source_image_urls is not supported for #{model}"
|
|
70
57
|
end
|
|
71
58
|
end
|
|
72
59
|
|
|
73
|
-
def validate_required!(params, key)
|
|
74
|
-
raise Core::ValidationError, "#{key} is required" unless field_present?(params, key)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def field_present?(params, key)
|
|
78
|
-
value = param(params, key)
|
|
79
|
-
return false if value.nil?
|
|
80
|
-
return value.any? if value.is_a?(Array)
|
|
81
|
-
return !value.empty? if value.respond_to?(:empty?)
|
|
82
|
-
|
|
83
|
-
true
|
|
84
|
-
end
|
|
85
|
-
|
|
86
60
|
def validate_integer!(params, key)
|
|
87
61
|
value = param(params, key)
|
|
88
62
|
return if value.nil?
|
|
@@ -90,15 +64,6 @@ module RunApi
|
|
|
90
64
|
|
|
91
65
|
raise Core::ValidationError, "#{key} must be an integer"
|
|
92
66
|
end
|
|
93
|
-
|
|
94
|
-
def validate_integer_range!(params, key, range)
|
|
95
|
-
value = param(params, key)
|
|
96
|
-
return if value.nil?
|
|
97
|
-
|
|
98
|
-
return if value.is_a?(Integer) && range.cover?(value)
|
|
99
|
-
|
|
100
|
-
raise Core::ValidationError, "#{key} must be between #{range.first} and #{range.last}"
|
|
101
|
-
end
|
|
102
67
|
end
|
|
103
68
|
end
|
|
104
69
|
end
|
|
@@ -3,24 +3,19 @@
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Seedream
|
|
5
5
|
# Seedream type constants and response models.
|
|
6
|
-
# Model families differ in supported params: 4.5/5-
|
|
7
|
-
# and output_quality;
|
|
6
|
+
# Model families differ in supported params: 4.5/5-Lite/5 Pro require
|
|
7
|
+
# aspect_ratio and output_quality; 5-Lite/5 Pro also support output_format; V4 uses
|
|
8
|
+
# output_resolution and supports seed/output_count.
|
|
8
9
|
module Types
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
seedream-5-lite-text-to-image
|
|
13
|
-
seedream-5-lite-edit
|
|
14
|
-
seedream-v4-text-to-image
|
|
15
|
-
seedream-v4-edit
|
|
16
|
-
].freeze
|
|
17
|
-
TEXT_TO_IMAGE_MODELS = %w[seedream-4.5-text-to-image seedream-5-lite-text-to-image seedream-v4-text-to-image].freeze
|
|
18
|
-
EDIT_MODELS = %w[seedream-4.5-edit seedream-5-lite-edit seedream-v4-edit].freeze
|
|
10
|
+
# Model groupings used by bespoke prompt-length selection (a per-model rule
|
|
11
|
+
# the contract cannot express). Model membership and field enums are
|
|
12
|
+
# validated by the generated CONTRACT.
|
|
19
13
|
LITE_MODELS = %w[seedream-5-lite-text-to-image seedream-5-lite-edit].freeze
|
|
14
|
+
PRO_MODELS = %w[seedream-5-pro-text-to-image seedream-5-pro-edit].freeze
|
|
20
15
|
V4_MODELS = %w[seedream-v4-text-to-image seedream-v4-edit].freeze
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
LONG_PROMPT_MODELS = (PRO_MODELS + V4_MODELS).freeze
|
|
17
|
+
MINIMUM_THREE_PROMPT_MODELS = (LITE_MODELS + PRO_MODELS).freeze
|
|
18
|
+
TEN_SOURCE_IMAGE_MODELS = %w[seedream-5-pro-edit seedream-v4-edit].freeze
|
|
24
19
|
|
|
25
20
|
class Image < RunApi::Core::BaseModel
|
|
26
21
|
optional :url, String
|
data/lib/runapi/seedream.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runapi-seedream
|
|
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.13
|
|
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.13
|
|
26
|
+
description: The Seedream Ruby SDK is the language-specific package for Seedream on
|
|
27
|
+
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-seedream.rb
|
|
40
40
|
- lib/runapi/seedream.rb
|
|
41
41
|
- lib/runapi/seedream/client.rb
|
|
42
|
+
- lib/runapi/seedream/contract_gen.rb
|
|
42
43
|
- lib/runapi/seedream/resources/edit_image.rb
|
|
43
44
|
- lib/runapi/seedream/resources/text_to_image.rb
|
|
44
45
|
- lib/runapi/seedream/types.rb
|
|
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/seedream
|
|
|
46
47
|
licenses:
|
|
47
48
|
- Apache-2.0
|
|
48
49
|
metadata:
|
|
50
|
+
runapi_slug: seedream
|
|
49
51
|
homepage_uri: https://runapi.ai/models/seedream
|
|
50
52
|
documentation_uri: https://github.com/runapi-ai/seedream-sdk/blob/main/ruby/README.md
|
|
51
53
|
source_code_uri: https://github.com/runapi-ai/seedream-sdk
|
|
54
|
+
bug_tracker_uri: https://github.com/runapi-ai/seedream-sdk/issues
|
|
52
55
|
changelog_uri: https://github.com/runapi-ai/seedream-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: Seedream
|
|
72
|
+
summary: Seedream Ruby SDK for RunAPI
|
|
70
73
|
test_files: []
|