runapi-seedream 0.2.1 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d88d27e25fb0b43a13eed24f12e6822d3132e012bd3ee881549e34ef73972cea
4
- data.tar.gz: b486a1e417fc2a6c7cfed7f90b1ddf4391acb6d04e436ed21292c7de5a20797e
3
+ metadata.gz: fd5375e0156b01735780ac14365797062e03a0e0659b2fa18077b8b00103d7a0
4
+ data.tar.gz: 2a3501a778307978b225a90234903ae77ce518b3d6cb206604cb5efa72be4f03
5
5
  SHA512:
6
- metadata.gz: d84a60f6f59dc1ae44fd22b64b9ff6ff84aa25000788082ee68e5cd6ecb0a6dd515bbcdaba343f249a03af111587d33a98b85cf7a0a54985e8dead4e01a1c7aa
7
- data.tar.gz: 67ff779b1d23ee0ec88a441910330c98912f029ff4b286f35ffcb1a428661dac1b3a2951f1d5c18cbeaaa8f0487db9b9adce76cf69e130166bfdbf844b55db83
6
+ metadata.gz: 00a681e2011e9a77015c55036e537aaa40f0d451142f1b2cd0582e91dd500c24599f17be6b2f226a46f986c6ac2c406fd0241b2fc6a22e309c930185f49e874d
7
+ data.tar.gz: e6e1ac147c0b246d308571e541e6aa5f5782e7c5fb2bff7bcd51385646af17893f8537a1999d237e0e0337700e814fd31e546506a37e97e2fca48ca26cc6f93e
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Seedream API Ruby SDK for RunAPI
2
+
3
+ The seedream api Ruby SDK is the language-specific package for Seedream on RunAPI. Use this seedream api package for text-to-image, image editing, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
+
5
+ This seedream api 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
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-seedream
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-seedream"
17
+
18
+ client = RunApi::Seedream::Client.new
19
+ task = client.text_to_image.create(
20
+ model: "seedream-v4-text-to-image",
21
+ prompt: "A precise product render of a glass teapot on white marble",
22
+ aspect_ratio: "16:9",
23
+ output_resolution: "2k",
24
+ output_count: 3
25
+ )
26
+ status = client.text_to_image.get(task.id)
27
+ ```
28
+
29
+ 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.
30
+
31
+ ## Language notes
32
+
33
+ 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.
34
+
35
+ ## Links
36
+
37
+ - Model page: https://runapi.ai/models/seedream
38
+ - SDK docs: https://runapi.ai/docs#sdk-seedream
39
+ - Product docs: https://runapi.ai/docs#seedream
40
+ - Pricing and rate limits: https://runapi.ai/models/seedream/v4-text-to-image
41
+ - Full catalog: https://runapi.ai/models
42
+ - Repository: https://github.com/runapi-ai/seedream-sdk
43
+
44
+ ## License
45
+
46
+ Licensed under the Apache License, Version 2.0.
@@ -3,7 +3,7 @@
3
3
  module RunApi
4
4
  module Seedream
5
5
  class Client
6
- attr_reader :text_to_image
6
+ attr_reader :text_to_image, :edit_image
7
7
 
8
8
  def initialize(api_key: nil, **options)
9
9
  @api_key = Core::Auth.resolve_api_key(api_key)
@@ -11,6 +11,7 @@ module RunApi
11
11
  client_options = Core::ClientOptions.new(api_key: @api_key, **options)
12
12
  http = client_options.http_client || Core::HttpClient.new(client_options)
13
13
  @text_to_image = Resources::TextToImage.new(http)
14
+ @edit_image = Resources::EditImage.new(http)
14
15
  end
15
16
  end
16
17
  end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Seedream
5
+ module Resources
6
+ class EditImage
7
+ include RunApi::Core::ResourceHelpers
8
+
9
+ ENDPOINT = "/api/v1/seedream/edit_image"
10
+ RESPONSE_CLASS = Types::EditImageResponse
11
+ COMPLETED_RESPONSE_CLASS = Types::CompletedEditImageResponse
12
+ PROMPT_MAX_LENGTH = 3000
13
+ V4_PROMPT_MAX_LENGTH = 5000
14
+ PROMPT_MIN_LENGTH_LITE = 3
15
+ V4_OUTPUT_COUNT_RANGE = (1..6)
16
+
17
+ def initialize(http)
18
+ @http = http
19
+ end
20
+
21
+ def run(**params)
22
+ task = create(**params)
23
+ poll_until_complete { get(task.id) }
24
+ end
25
+
26
+ def create(**params)
27
+ params = compact_params(params)
28
+ validate_params!(params)
29
+ request(:post, ENDPOINT, body: params)
30
+ end
31
+
32
+ def get(id)
33
+ request(:get, "#{ENDPOINT}/#{id}")
34
+ end
35
+
36
+ private
37
+
38
+ def validate_params!(params)
39
+ model = param(params, :model)
40
+ raise Core::ValidationError, "model is required" unless model
41
+ unless Types::EDIT_MODELS.include?(model)
42
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::EDIT_MODELS.join(", ")}"
43
+ end
44
+
45
+ prompt = param(params, :prompt)
46
+ raise Core::ValidationError, "prompt is required" unless prompt.is_a?(String) && !prompt.empty?
47
+ max_length = Types::V4_MODELS.include?(model) ? V4_PROMPT_MAX_LENGTH : PROMPT_MAX_LENGTH
48
+ raise Core::ValidationError, "prompt must be at most #{max_length} characters" if prompt.length > max_length
49
+ if Types::LITE_MODELS.include?(model) && prompt.length < PROMPT_MIN_LENGTH_LITE
50
+ raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{PROMPT_MAX_LENGTH} characters"
51
+ end
52
+
53
+ raise Core::ValidationError, "source_image_urls is required" unless field_present?(params, :source_image_urls)
54
+
55
+ if Types::V4_MODELS.include?(model)
56
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
57
+ validate_optional!(params, :output_resolution, Types::V4_OUTPUT_RESOLUTIONS)
58
+ validate_integer_range!(params, :output_count, V4_OUTPUT_COUNT_RANGE)
59
+ validate_integer!(params, :seed)
60
+ else
61
+ validate_required!(params, :aspect_ratio)
62
+ validate_required!(params, :output_quality)
63
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
64
+ validate_optional!(params, :output_quality, Types::OUTPUT_QUALITIES)
65
+ end
66
+ end
67
+
68
+ def validate_required!(params, key)
69
+ raise Core::ValidationError, "#{key} is required" unless field_present?(params, key)
70
+ end
71
+
72
+ def field_present?(params, key)
73
+ value = param(params, key)
74
+ return false if value.nil?
75
+ return value.any? if value.is_a?(Array)
76
+ return !value.empty? if value.respond_to?(:empty?)
77
+
78
+ true
79
+ end
80
+
81
+ def validate_integer!(params, key)
82
+ value = param(params, key)
83
+ return if value.nil?
84
+ return if value.is_a?(Integer)
85
+
86
+ raise Core::ValidationError, "#{key} must be an integer"
87
+ end
88
+
89
+ def validate_integer_range!(params, key, range)
90
+ value = param(params, key)
91
+ return if value.nil?
92
+
93
+ return if value.is_a?(Integer) && range.cover?(value)
94
+
95
+ raise Core::ValidationError, "#{key} must be between #{range.first} and #{range.last}"
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -10,7 +10,9 @@ module RunApi
10
10
  RESPONSE_CLASS = Types::TextToImageResponse
11
11
  COMPLETED_RESPONSE_CLASS = Types::CompletedTextToImageResponse
12
12
  PROMPT_MAX_LENGTH = 3000
13
+ V4_PROMPT_MAX_LENGTH = 5000
13
14
  PROMPT_MIN_LENGTH_LITE = 3
15
+ V4_OUTPUT_COUNT_RANGE = (1..6)
14
16
 
15
17
  def initialize(http)
16
18
  @http = http
@@ -36,28 +38,32 @@ module RunApi
36
38
  def validate_params!(params)
37
39
  model = param(params, :model)
38
40
  raise Core::ValidationError, "model is required" unless model
39
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::MODELS.join(", ")}" unless Types::MODELS.include?(model)
41
+ unless Types::TEXT_TO_IMAGE_MODELS.include?(model)
42
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
43
+ end
40
44
 
41
45
  prompt = param(params, :prompt)
42
46
  raise Core::ValidationError, "prompt is required" unless prompt.is_a?(String) && !prompt.empty?
43
- raise Core::ValidationError, "prompt must be at most #{PROMPT_MAX_LENGTH} characters" if prompt.length > PROMPT_MAX_LENGTH
47
+ max_length = Types::V4_MODELS.include?(model) ? V4_PROMPT_MAX_LENGTH : PROMPT_MAX_LENGTH
48
+ raise Core::ValidationError, "prompt must be at most #{max_length} characters" if prompt.length > max_length
44
49
  if Types::LITE_MODELS.include?(model) && prompt.length < PROMPT_MIN_LENGTH_LITE
45
50
  raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{PROMPT_MAX_LENGTH} characters"
46
51
  end
47
52
 
48
- validate_required!(params, :aspect_ratio)
49
- validate_required!(params, :quality)
50
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
51
- validate_optional!(params, :quality, Types::QUALITIES)
52
-
53
- if Types::IMAGE_MODELS.include?(model)
54
- raise Core::ValidationError, "image_urls is required" unless field_present?(params, :image_urls)
55
- elsif field_present?(params, :image_urls)
56
- raise Core::ValidationError, "image_urls is not supported for #{model}"
53
+ if Types::V4_MODELS.include?(model)
54
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
55
+ validate_optional!(params, :output_resolution, Types::V4_OUTPUT_RESOLUTIONS)
56
+ validate_integer_range!(params, :output_count, V4_OUTPUT_COUNT_RANGE)
57
+ validate_integer!(params, :seed)
58
+ else
59
+ validate_required!(params, :aspect_ratio)
60
+ validate_required!(params, :output_quality)
61
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
62
+ validate_optional!(params, :output_quality, Types::OUTPUT_QUALITIES)
57
63
  end
58
64
 
59
- if field_present?(params, :nsfw_checker) && !Types::LITE_MODELS.include?(model)
60
- raise Core::ValidationError, "nsfw_checker is not supported for #{model}"
65
+ if field_present?(params, :source_image_urls)
66
+ raise Core::ValidationError, "source_image_urls is not supported for #{model}"
61
67
  end
62
68
  end
63
69
 
@@ -73,6 +79,23 @@ module RunApi
73
79
 
74
80
  true
75
81
  end
82
+
83
+ def validate_integer!(params, key)
84
+ value = param(params, key)
85
+ return if value.nil?
86
+ return if value.is_a?(Integer)
87
+
88
+ raise Core::ValidationError, "#{key} must be an integer"
89
+ end
90
+
91
+ def validate_integer_range!(params, key, range)
92
+ value = param(params, key)
93
+ return if value.nil?
94
+
95
+ return if value.is_a?(Integer) && range.cover?(value)
96
+
97
+ raise Core::ValidationError, "#{key} must be between #{range.first} and #{range.last}"
98
+ end
76
99
  end
77
100
  end
78
101
  end
@@ -7,12 +7,17 @@ module RunApi
7
7
  seedream-4.5-text-to-image
8
8
  seedream-4.5-edit
9
9
  seedream-5-lite-text-to-image
10
- seedream-5-lite-image-to-image
10
+ seedream-5-lite-edit
11
+ seedream-v4-text-to-image
12
+ seedream-v4-edit
11
13
  ].freeze
12
- IMAGE_MODELS = %w[seedream-4.5-edit seedream-5-lite-image-to-image].freeze
13
- LITE_MODELS = %w[seedream-5-lite-text-to-image seedream-5-lite-image-to-image].freeze
14
+ TEXT_TO_IMAGE_MODELS = %w[seedream-4.5-text-to-image seedream-5-lite-text-to-image seedream-v4-text-to-image].freeze
15
+ EDIT_MODELS = %w[seedream-4.5-edit seedream-5-lite-edit seedream-v4-edit].freeze
16
+ LITE_MODELS = %w[seedream-5-lite-text-to-image seedream-5-lite-edit].freeze
17
+ V4_MODELS = %w[seedream-v4-text-to-image seedream-v4-edit].freeze
14
18
  ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 2:3 3:2 21:9].freeze
15
- QUALITIES = %w[basic high].freeze
19
+ OUTPUT_QUALITIES = %w[basic high].freeze
20
+ V4_OUTPUT_RESOLUTIONS = %w[1k 2k 4k].freeze
16
21
 
17
22
  class Image < RunApi::Core::BaseModel
18
23
  optional :url, String
@@ -21,16 +26,20 @@ module RunApi
21
26
  class TextToImageResponse < RunApi::Core::TaskResponse
22
27
  required :id, String
23
28
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
24
- optional :images, [ -> { Image } ]
29
+ optional :images, [-> { Image }]
25
30
  optional :error, String
26
31
  end
27
32
 
33
+ EditImageResponse = TextToImageResponse
34
+
28
35
  # Narrowed response returned by `text_to_image.run()` once polling observes
29
36
  # `status: "completed"`. `images` is required so consumers never have to
30
37
  # null-check it on a successful task.
31
38
  class CompletedTextToImageResponse < TextToImageResponse
32
- required :images, [ -> { Image } ]
39
+ required :images, [-> { Image }]
33
40
  end
41
+
42
+ CompletedEditImageResponse = CompletedTextToImageResponse
34
43
  end
35
44
  end
36
45
  end
@@ -3,6 +3,7 @@
3
3
  require "runapi/core"
4
4
  require_relative "seedream/types"
5
5
  require_relative "seedream/resources/text_to_image"
6
+ require_relative "seedream/resources/edit_image"
6
7
  require_relative "seedream/client"
7
8
 
8
9
  module RunApi
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.1
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,25 +15,31 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.1'
18
+ version: 0.2.5
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.1'
26
- description: RunAPI Seedream SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.5
26
+ description: The seedream api Ruby SDK is the language-specific package for Seedream
27
+ on RunAPI. Use this seedream api package for text-to-image, image editing, and creative
28
+ production flows when your application needs JSON request bodies, task status lookup,
29
+ and consistent RunAPI errors in Ruby.
27
30
  email:
28
31
  - contact@runapi.ai
29
32
  executables: []
30
33
  extensions: []
31
- extra_rdoc_files: []
34
+ extra_rdoc_files:
35
+ - README.md
32
36
  files:
33
37
  - LICENSE
38
+ - README.md
34
39
  - lib/runapi-seedream.rb
35
40
  - lib/runapi/seedream.rb
36
41
  - lib/runapi/seedream/client.rb
42
+ - lib/runapi/seedream/resources/edit_image.rb
37
43
  - lib/runapi/seedream/resources/text_to_image.rb
38
44
  - lib/runapi/seedream/types.rb
39
45
  homepage: https://runapi.ai/models/seedream
@@ -41,7 +47,7 @@ licenses:
41
47
  - Apache-2.0
42
48
  metadata:
43
49
  homepage_uri: https://runapi.ai/models/seedream
44
- documentation_uri: https://runapi.ai/models/seedream
50
+ documentation_uri: https://github.com/runapi-ai/seedream-sdk/blob/main/ruby/README.md
45
51
  source_code_uri: https://github.com/runapi-ai/seedream-sdk
46
52
  changelog_uri: https://github.com/runapi-ai/seedream-sdk/blob/main/CHANGELOG.md
47
53
  rdoc_options: []
@@ -58,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
64
  - !ruby/object:Gem::Version
59
65
  version: '0'
60
66
  requirements: []
61
- rubygems_version: 4.0.6
67
+ rubygems_version: 4.0.10
62
68
  specification_version: 4
63
- summary: Seedream API SDKs for JavaScript, Ruby, and Go on RunAPI.
69
+ summary: Seedream API Ruby SDK for RunAPI
64
70
  test_files: []