runapi-qwen-2 0.2.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c78ff54d710cf9de225f0f6abab5f57503946872e382bf780dd7084d630801a
4
- data.tar.gz: 93ca839ada0fc05d7c99fcbed4cf023e1c837163266968da9691769e2f241e99
3
+ metadata.gz: 1f3700e2cf81d87fa6bf94631a0f6d153cbc481a5b978f1f6a684f2986a8ebda
4
+ data.tar.gz: 948da5705c89ac0e4cab9b06c6a89e36426615d9b1e8656095a04e0ee2450dbc
5
5
  SHA512:
6
- metadata.gz: 9b753024a71658d987ec33b0524ef2cdf7d437c5ae0604b612be932b6d9bcec63dd90722b07d2e22088aad31bf4a58345a97696ab0da5a956eab585002fe097d
7
- data.tar.gz: a61c665168372a5b982ff68f5eea4243c70480cea9bac062645107f4dd08825b677c6bc421379951e334c609dac6d813e09c8ad8c013e3ac89c3b35ba48b70db
6
+ metadata.gz: d23d2d3fd38f3a16f49214ad0f122dbed63504eb61eaa463e41fa584a4a93efe7e61d2027997d996b8fb2d51d04edcbea50e12964e8b3a5c5f584f6cf86ecdcc
7
+ data.tar.gz: 981e76b782d1584f10e782be8d45e38a3a267d7f0adc8d47f799f01eaf0a16a3809278b42ffead6a04ae356aee77b114d8acc5a1bb2f91f5dafdce23f695fb89
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Qwen Image API Ruby SDK for RunAPI
2
+
3
+ The qwen image api Ruby SDK is the language-specific package for Qwen 2 on RunAPI. Use this qwen image 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 qwen image api README is the Ruby package guide inside the public `qwen2-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/qwen-2; for API reference, use https://runapi.ai/docs#qwen-2; for SDK docs, use https://runapi.ai/docs#sdk-qwen-2.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-qwen2
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-qwen2"
17
+
18
+ client = RunApi::Qwen2::Client.new
19
+ task = client.generations.create(
20
+ # Pass the Qwen 2 JSON request body from https://runapi.ai/docs#qwen-2.
21
+ )
22
+ status = client.generations.get(task.id)
23
+ ```
24
+
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
+
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
+
29
+ ## Language notes
30
+
31
+ Use Ruby keyword arguments and the `RunApi::Qwen2` error classes when building image jobs, Rails workers, or scripts. The available resources include generations, image to images, and edits. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
32
+
33
+ ## Links
34
+
35
+ - Model page: https://runapi.ai/models/qwen-2
36
+ - SDK docs: https://runapi.ai/docs#sdk-qwen-2
37
+ - Product docs: https://runapi.ai/docs#qwen-2
38
+ - Pricing and rate limits: https://runapi.ai/models/qwen-2/text-to-image
39
+ - Provider comparison: https://runapi.ai/providers/alibaba
40
+ - Full catalog: https://runapi.ai/models
41
+ - Repository: https://github.com/runapi-ai/qwen2-sdk
42
+
43
+ ## License
44
+
45
+ Licensed under the Apache License, Version 2.0.
@@ -2,26 +2,31 @@
2
2
 
3
3
  module RunApi
4
4
  module Qwen2
5
- # Qwen2 text-to-image, image-to-image, and edit-image API client.
5
+ # Qwen 2 image generation, remixing, and editing API client.
6
+ #
7
+ # Three operations: pure text-to-image generation, remix (prompt-guided
8
+ # variation of a source image with configurable strength), and edit
9
+ # (targeted modifications to a source image).
6
10
  #
7
11
  # @example
8
12
  # client = RunApi::Qwen2::Client.new(api_key: "your-api-key")
9
13
  # result = client.edit_image.run(
10
- # model: "qwen-2-image-edit",
14
+ # model: "qwen-2-edit-image",
11
15
  # prompt: "Replace the background with a neon-lit city skyline",
12
- # image_url: "https://example.com/input.jpg"
16
+ # source_image_url: "https://cdn.runapi.ai/public/samples/input.jpg"
13
17
  # )
14
- class Client
15
- # @return [Resources::TextToImage, Resources::ImageToImage, Resources::EditImage] Image operations.
16
- attr_reader :text_to_image, :image_to_image, :edit_image
18
+ class Client < RunApi::Core::Client
19
+ # @return [Resources::TextToImage] Generate images from text prompts.
20
+ attr_reader :text_to_image
21
+ # @return [Resources::RemixImage] Create prompt-guided variations with adjustable strength (0 = faithful, 1 = creative).
22
+ attr_reader :remix_image
23
+ # @return [Resources::EditImage] Apply targeted edits to a source image using natural-language prompts.
24
+ attr_reader :edit_image
17
25
 
18
26
  def initialize(api_key: nil, **options)
19
- @api_key = Core::Auth.resolve_api_key(api_key)
20
-
21
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
22
- http = client_options.http_client || Core::HttpClient.new(client_options)
27
+ super
23
28
  @text_to_image = Resources::TextToImage.new(http)
24
- @image_to_image = Resources::ImageToImage.new(http)
29
+ @remix_image = Resources::RemixImage.new(http)
25
30
  @edit_image = Resources::EditImage.new(http)
26
31
  end
27
32
  end
@@ -48,14 +48,14 @@ module RunApi
48
48
  def validate_params!(params)
49
49
  raise Core::ValidationError, "model is required" unless param(params, :model)
50
50
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
51
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
51
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
52
52
 
53
53
  model = param(params, :model)
54
54
  unless Types::EDIT_MODELS.include?(model)
55
55
  raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::EDIT_MODELS.join(", ")}"
56
56
  end
57
57
 
58
- validate_optional!(params, :image_size, Types::IMAGE_SIZES)
58
+ validate_optional!(params, :aspect_ratio, Types::EDIT_IMAGE_ASPECT_RATIOS)
59
59
  validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
60
60
  end
61
61
  end
@@ -3,42 +3,42 @@
3
3
  module RunApi
4
4
  module Qwen2
5
5
  module Resources
6
- # Qwen2 image-to-image resource. Transforms images with natural-language prompts.
7
- class ImageToImage
6
+ # Qwen2 remix-image resource. Creates prompt-guided variations from a source image.
7
+ class RemixImage
8
8
  include RunApi::Core::ResourceHelpers
9
9
 
10
- ENDPOINT = "/api/v1/qwen_2/image_to_image"
10
+ ENDPOINT = "/api/v1/qwen_2/remix_image"
11
11
 
12
- RESPONSE_CLASS = Types::ImageToImageResponse
13
- COMPLETED_RESPONSE_CLASS = Types::CompletedImageToImageResponse
12
+ RESPONSE_CLASS = Types::RemixImageResponse
13
+ COMPLETED_RESPONSE_CLASS = Types::CompletedRemixImageResponse
14
14
 
15
15
  def initialize(http)
16
16
  @http = http
17
17
  end
18
18
 
19
- # Transform an image and wait until complete.
19
+ # Remix an image and wait until complete.
20
20
  #
21
- # @param params [Hash] image-to-image parameters
22
- # @return [RunApi::Qwen2::Types::CompletedImageToImageResponse] completed image-to-image result
21
+ # @param params [Hash] remix-image parameters
22
+ # @return [RunApi::Qwen2::Types::CompletedRemixImageResponse] completed remix-image result
23
23
  def run(**params)
24
24
  task = create(**params)
25
25
  poll_until_complete { get(task.id) }
26
26
  end
27
27
 
28
- # Create an image-to-image task.
28
+ # Create a remix-image task.
29
29
  #
30
- # @param params [Hash] image-to-image parameters
31
- # @return [RunApi::Qwen2::Types::ImageToImageResponse] task creation result with id
30
+ # @param params [Hash] remix-image parameters
31
+ # @return [RunApi::Qwen2::Types::RemixImageResponse] task creation result with id
32
32
  def create(**params)
33
33
  params = compact_params(params)
34
34
  validate_params!(params)
35
35
  request(:post, ENDPOINT, body: params)
36
36
  end
37
37
 
38
- # Get image-to-image status by task ID.
38
+ # Get remix-image status by task ID.
39
39
  #
40
40
  # @param id [String] task ID
41
- # @return [RunApi::Qwen2::Types::ImageToImageResponse] current image-to-image status
41
+ # @return [RunApi::Qwen2::Types::RemixImageResponse] current remix-image status
42
42
  def get(id)
43
43
  request(:get, "#{ENDPOINT}/#{id}")
44
44
  end
@@ -48,11 +48,11 @@ module RunApi
48
48
  def validate_params!(params)
49
49
  raise Core::ValidationError, "model is required" unless param(params, :model)
50
50
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
51
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
51
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
52
52
 
53
53
  model = param(params, :model)
54
- unless Types::IMAGE_TO_IMAGE_MODELS.include?(model)
55
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::IMAGE_TO_IMAGE_MODELS.join(", ")}"
54
+ unless Types::REMIX_IMAGE_MODELS.include?(model)
55
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::REMIX_IMAGE_MODELS.join(", ")}"
56
56
  end
57
57
 
58
58
  validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
@@ -53,7 +53,7 @@ module RunApi
53
53
  raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
54
54
  end
55
55
 
56
- validate_optional!(params, :image_size, Types::QWEN_IMAGE_SIZES)
56
+ validate_optional!(params, :aspect_ratio, Types::TEXT_TO_IMAGE_ASPECT_RATIOS)
57
57
  validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
58
58
  end
59
59
  end
@@ -3,39 +3,46 @@
3
3
  module RunApi
4
4
  module Qwen2
5
5
  module Types
6
- MODELS = %w[qwen-2-image-edit qwen-2-text-to-image qwen-2-image-to-image].freeze
7
- EDIT_MODELS = %w[qwen-2-image-edit].freeze
6
+ # All Qwen 2 model variants, each dedicated to a single operation type.
7
+ MODELS = %w[qwen-2-edit-image qwen-2-text-to-image qwen-2-remix-image].freeze
8
+ EDIT_MODELS = %w[qwen-2-edit-image].freeze
8
9
  TEXT_TO_IMAGE_MODELS = %w[qwen-2-text-to-image].freeze
9
- IMAGE_TO_IMAGE_MODELS = %w[qwen-2-image-to-image].freeze
10
- IMAGE_SIZES = %w[1:1 2:3 3:2 3:4 4:3 9:16 16:9 21:9].freeze
11
- QWEN_IMAGE_SIZES = %w[square square_hd portrait_4_3 portrait_16_9 landscape_4_3 landscape_16_9].freeze
10
+ REMIX_IMAGE_MODELS = %w[qwen-2-remix-image].freeze
11
+ # Edit-image aspect ratios include ultra-wide 21:9; narrower set than generation.
12
+ EDIT_IMAGE_ASPECT_RATIOS = %w[1:1 2:3 3:2 3:4 4:3 9:16 16:9 21:9].freeze
13
+ TEXT_TO_IMAGE_ASPECT_RATIOS = %w[1:1 3:4 4:3 9:16 16:9].freeze
12
14
  OUTPUT_FORMATS = %w[jpeg png].freeze
13
15
 
16
+ # A single generated image result.
14
17
  class Image < RunApi::Core::BaseModel
15
18
  optional :url, String
16
19
  end
17
20
 
21
+ # Shared task result for all Qwen 2 image operations.
18
22
  class ImageTaskResponse < RunApi::Core::TaskResponse
19
23
  required :id, String
20
24
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
21
- optional :images, [ -> { Image } ]
25
+ optional :images, [-> { Image }]
22
26
  optional :error, String
23
27
  end
24
28
 
25
29
  class TextToImageResponse < ImageTaskResponse; end
26
- class ImageToImageResponse < ImageTaskResponse; end
30
+ class RemixImageResponse < ImageTaskResponse; end
27
31
  class EditImageResponse < ImageTaskResponse; end
28
32
 
33
+ # Narrowed responses returned by +run()+ methods once polling observes
34
+ # +status: "completed"+. +images+ is required so consumers never
35
+ # have to null-check it on a successful task.
29
36
  class CompletedTextToImageResponse < TextToImageResponse
30
- required :images, [ -> { Image } ]
37
+ required :images, [-> { Image }]
31
38
  end
32
39
 
33
- class CompletedImageToImageResponse < ImageToImageResponse
34
- required :images, [ -> { Image } ]
40
+ class CompletedRemixImageResponse < RemixImageResponse
41
+ required :images, [-> { Image }]
35
42
  end
36
43
 
37
44
  class CompletedEditImageResponse < EditImageResponse
38
- required :images, [ -> { Image } ]
45
+ required :images, [-> { Image }]
39
46
  end
40
47
  end
41
48
  end
data/lib/runapi/qwen_2.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "runapi/core"
4
4
  require_relative "qwen_2/types"
5
5
  require_relative "qwen_2/resources/text_to_image"
6
- require_relative "qwen_2/resources/image_to_image"
6
+ require_relative "qwen_2/resources/remix_image"
7
7
  require_relative "qwen_2/resources/edit_image"
8
8
  require_relative "qwen_2/client"
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-qwen-2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,27 +15,32 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.4
18
+ version: 0.2.6
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.4
26
- description: RunAPI Qwen 2 SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.6
26
+ description: The qwen image api Ruby SDK is the language-specific package for Qwen
27
+ 2 on RunAPI. Use this qwen image api package for text-to-image, image editing, and
28
+ creative production flows when your application needs JSON request bodies, task
29
+ status lookup, 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-qwen_2.rb
35
40
  - lib/runapi/qwen_2.rb
36
41
  - lib/runapi/qwen_2/client.rb
37
42
  - lib/runapi/qwen_2/resources/edit_image.rb
38
- - lib/runapi/qwen_2/resources/image_to_image.rb
43
+ - lib/runapi/qwen_2/resources/remix_image.rb
39
44
  - lib/runapi/qwen_2/resources/text_to_image.rb
40
45
  - lib/runapi/qwen_2/types.rb
41
46
  homepage: https://runapi.ai/models/qwen-2
@@ -43,7 +48,7 @@ licenses:
43
48
  - Apache-2.0
44
49
  metadata:
45
50
  homepage_uri: https://runapi.ai/models/qwen-2
46
- documentation_uri: https://github.com/runapi-ai/qwen-2-sdk/blob/main/README.md
51
+ documentation_uri: https://github.com/runapi-ai/qwen-2-sdk/blob/main/ruby/README.md
47
52
  source_code_uri: https://github.com/runapi-ai/qwen-2-sdk
48
53
  changelog_uri: https://github.com/runapi-ai/qwen-2-sdk/blob/main/CHANGELOG.md
49
54
  rdoc_options: []
@@ -62,5 +67,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
67
  requirements: []
63
68
  rubygems_version: 4.0.10
64
69
  specification_version: 4
65
- summary: Qwen 2 API SDKs for JavaScript, Ruby, and Go on RunAPI.
70
+ summary: Qwen Image API Ruby SDK for RunAPI
66
71
  test_files: []