runapi-qwen-2 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f3700e2cf81d87fa6bf94631a0f6d153cbc481a5b978f1f6a684f2986a8ebda
4
- data.tar.gz: 948da5705c89ac0e4cab9b06c6a89e36426615d9b1e8656095a04e0ee2450dbc
3
+ metadata.gz: 2956586742f9d0861230f9896d032a1b9525325c3f18107eb3051133041ae180
4
+ data.tar.gz: d4639d731229589fa4e6b389771bbd1219ce62fe8488a86cc4671ef32a034ce3
5
5
  SHA512:
6
- metadata.gz: d23d2d3fd38f3a16f49214ad0f122dbed63504eb61eaa463e41fa584a4a93efe7e61d2027997d996b8fb2d51d04edcbea50e12964e8b3a5c5f584f6cf86ecdcc
7
- data.tar.gz: 981e76b782d1584f10e782be8d45e38a3a267d7f0adc8d47f799f01eaf0a16a3809278b42ffead6a04ae356aee77b114d8acc5a1bb2f91f5dafdce23f695fb89
6
+ metadata.gz: c668a2fbf31074afecc12aac9d4d493afe3fada577f0506f9993268355e2d1f3046f1d6db659812294ab0f71bc4d01c00ddd9a7d252c34b015ca0465f1f42e95
7
+ data.tar.gz: 7f14e473674084d4a1e76b28d28ab3a8703089ab91e9a80bc8310bf3b0e460b3960255ad76d7721098800bff50b9b380779fda48027566d7ea899325956e2fba
data/README.md CHANGED
@@ -1,25 +1,25 @@
1
- # Qwen Image API Ruby SDK for RunAPI
1
+ # Qwen 2 API Ruby SDK for RunAPI
2
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.
3
+ The Qwen 2 Ruby SDK is the language-specific package for Qwen 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 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.
5
+ This README is the Ruby package guide inside the public `qwen-2-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
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- gem install runapi-qwen2
10
+ gem install runapi-qwen-2
11
11
  ```
12
12
 
13
13
  ## Quick start
14
14
 
15
15
  ```ruby
16
- require "runapi-qwen2"
16
+ require "runapi/qwen_2"
17
17
 
18
18
  client = RunApi::Qwen2::Client.new
19
- task = client.generations.create(
19
+ task = client.text_to_image.create(
20
20
  # Pass the Qwen 2 JSON request body from https://runapi.ai/docs#qwen-2.
21
21
  )
22
- status = client.generations.get(task.id)
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.
@@ -28,7 +28,7 @@ RunAPI-generated file URLs are temporary. Download and store generated images, v
28
28
 
29
29
  ## Language notes
30
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.
31
+ Use Ruby keyword arguments and the `RunApi::Qwen2` 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.
32
32
 
33
33
  ## Links
34
34
 
@@ -2,11 +2,9 @@
2
2
 
3
3
  module RunApi
4
4
  module Qwen2
5
- # Qwen 2 image generation, remixing, and editing API client.
5
+ # Qwen 2 image generation and editing API client.
6
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).
7
+ # Text-to-image generation and targeted modifications to source images.
10
8
  #
11
9
  # @example
12
10
  # client = RunApi::Qwen2::Client.new(api_key: "your-api-key")
@@ -18,15 +16,12 @@ module RunApi
18
16
  class Client < RunApi::Core::Client
19
17
  # @return [Resources::TextToImage] Generate images from text prompts.
20
18
  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
19
  # @return [Resources::EditImage] Apply targeted edits to a source image using natural-language prompts.
24
20
  attr_reader :edit_image
25
21
 
26
22
  def initialize(api_key: nil, **options)
27
23
  super
28
24
  @text_to_image = Resources::TextToImage.new(http)
29
- @remix_image = Resources::RemixImage.new(http)
30
25
  @edit_image = Resources::EditImage.new(http)
31
26
  end
32
27
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Qwen2
5
+ CONTRACT = {
6
+ "edit-image" => {
7
+ "models" => ["qwen-2-edit-image"],
8
+ "fields_by_model" => {
9
+ "qwen-2-edit-image" => {
10
+ "aspect_ratio" => {
11
+ "enum" => ["1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", "21:9"]
12
+ },
13
+ "output_format" => {
14
+ "enum" => ["jpeg", "png"]
15
+ },
16
+ "prompt" => {
17
+ "required" => true
18
+ },
19
+ "seed" => {
20
+ "type" => "integer"
21
+ },
22
+ "source_image_url" => {
23
+ "required" => true
24
+ }
25
+ }
26
+ }
27
+ },
28
+ "text-to-image" => {
29
+ "models" => ["qwen-2-text-to-image"],
30
+ "fields_by_model" => {
31
+ "qwen-2-text-to-image" => {
32
+ "aspect_ratio" => {
33
+ "enum" => ["1:1", "3:4", "4:3", "9:16", "16:9"]
34
+ },
35
+ "output_format" => {
36
+ "enum" => ["png", "jpeg"]
37
+ },
38
+ "prompt" => {
39
+ "required" => true
40
+ },
41
+ "seed" => {
42
+ "type" => "integer"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }.freeze
48
+ end
49
+ end
@@ -20,43 +20,27 @@ module RunApi
20
20
  #
21
21
  # @param params [Hash] edit-image parameters
22
22
  # @return [RunApi::Qwen2::Types::CompletedEditImageResponse] completed edit-image result
23
- def run(**params)
24
- task = create(**params)
25
- 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) }
26
26
  end
27
27
 
28
28
  # Create an edit-image task.
29
29
  #
30
30
  # @param params [Hash] edit-image parameters
31
31
  # @return [RunApi::Qwen2::Types::EditImageResponse] task creation result with id
32
- def create(**params)
32
+ def create(options: nil, **params)
33
33
  params = compact_params(params)
34
- validate_params!(params)
35
- request(:post, ENDPOINT, body: params)
34
+ validate_contract!(CONTRACT["edit-image"], params)
35
+ request(:post, ENDPOINT, body: params, options: options)
36
36
  end
37
37
 
38
38
  # Get edit-image status by task ID.
39
39
  #
40
40
  # @param id [String] task ID
41
41
  # @return [RunApi::Qwen2::Types::EditImageResponse] current edit-image status
42
- def get(id)
43
- request(:get, "#{ENDPOINT}/#{id}")
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
- raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
52
-
53
- model = param(params, :model)
54
- unless Types::EDIT_MODELS.include?(model)
55
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::EDIT_MODELS.join(", ")}"
56
- end
57
-
58
- validate_optional!(params, :aspect_ratio, Types::EDIT_IMAGE_ASPECT_RATIOS)
59
- validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
42
+ def get(id, options: nil)
43
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
60
44
  end
61
45
  end
62
46
  end
@@ -20,41 +20,27 @@ module RunApi
20
20
  #
21
21
  # @param params [Hash] text-to-image parameters
22
22
  # @return [RunApi::Qwen2::Types::CompletedTextToImageResponse] completed text-to-image result
23
- def run(**params)
24
- task = create(**params)
25
- 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) }
26
26
  end
27
27
 
28
28
  # Create a text-to-image task.
29
29
  #
30
30
  # @param params [Hash] text-to-image parameters
31
31
  # @return [RunApi::Qwen2::Types::TextToImageResponse] task creation result with id
32
- def create(**params)
32
+ def create(options: nil, **params)
33
33
  params = compact_params(params)
34
- validate_params!(params)
35
- request(:post, ENDPOINT, body: params)
34
+ validate_contract!(CONTRACT["text-to-image"], params)
35
+ request(:post, ENDPOINT, body: params, options: options)
36
36
  end
37
37
 
38
38
  # Get text-to-image status by task ID.
39
39
  #
40
40
  # @param id [String] task ID
41
41
  # @return [RunApi::Qwen2::Types::TextToImageResponse] current text-to-image status
42
- def get(id)
43
- request(:get, "#{ENDPOINT}/#{id}")
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
- model = param(params, :model)
52
- unless Types::TEXT_TO_IMAGE_MODELS.include?(model)
53
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
54
- end
55
-
56
- validate_optional!(params, :aspect_ratio, Types::TEXT_TO_IMAGE_ASPECT_RATIOS)
57
- validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
42
+ def get(id, options: nil)
43
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
58
44
  end
59
45
  end
60
46
  end
@@ -3,16 +3,6 @@
3
3
  module RunApi
4
4
  module Qwen2
5
5
  module Types
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
9
- TEXT_TO_IMAGE_MODELS = %w[qwen-2-text-to-image].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
14
- OUTPUT_FORMATS = %w[jpeg png].freeze
15
-
16
6
  # A single generated image result.
17
7
  class Image < RunApi::Core::BaseModel
18
8
  optional :url, String
@@ -27,7 +17,6 @@ module RunApi
27
17
  end
28
18
 
29
19
  class TextToImageResponse < ImageTaskResponse; end
30
- class RemixImageResponse < ImageTaskResponse; end
31
20
  class EditImageResponse < ImageTaskResponse; end
32
21
 
33
22
  # Narrowed responses returned by +run()+ methods once polling observes
@@ -37,10 +26,6 @@ module RunApi
37
26
  required :images, [-> { Image }]
38
27
  end
39
28
 
40
- class CompletedRemixImageResponse < RemixImageResponse
41
- required :images, [-> { Image }]
42
- end
43
-
44
29
  class CompletedEditImageResponse < EditImageResponse
45
30
  required :images, [-> { Image }]
46
31
  end
data/lib/runapi/qwen_2.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "qwen_2/types"
5
+ require_relative "qwen_2/contract_gen"
5
6
  require_relative "qwen_2/resources/text_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.7
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.6
18
+ version: 0.3.0
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.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.
25
+ version: 0.3.0
26
+ description: The Qwen 2 Ruby SDK is the language-specific package for Qwen 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,17 +39,19 @@ files:
39
39
  - lib/runapi-qwen_2.rb
40
40
  - lib/runapi/qwen_2.rb
41
41
  - lib/runapi/qwen_2/client.rb
42
+ - lib/runapi/qwen_2/contract_gen.rb
42
43
  - lib/runapi/qwen_2/resources/edit_image.rb
43
- - lib/runapi/qwen_2/resources/remix_image.rb
44
44
  - lib/runapi/qwen_2/resources/text_to_image.rb
45
45
  - lib/runapi/qwen_2/types.rb
46
46
  homepage: https://runapi.ai/models/qwen-2
47
47
  licenses:
48
48
  - Apache-2.0
49
49
  metadata:
50
+ runapi_slug: qwen-2
50
51
  homepage_uri: https://runapi.ai/models/qwen-2
51
52
  documentation_uri: https://github.com/runapi-ai/qwen-2-sdk/blob/main/ruby/README.md
52
53
  source_code_uri: https://github.com/runapi-ai/qwen-2-sdk
54
+ bug_tracker_uri: https://github.com/runapi-ai/qwen-2-sdk/issues
53
55
  changelog_uri: https://github.com/runapi-ai/qwen-2-sdk/blob/main/CHANGELOG.md
54
56
  rdoc_options: []
55
57
  require_paths:
@@ -65,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
67
  - !ruby/object:Gem::Version
66
68
  version: '0'
67
69
  requirements: []
68
- rubygems_version: 4.0.10
70
+ rubygems_version: 4.0.17
69
71
  specification_version: 4
70
- summary: Qwen Image API Ruby SDK for RunAPI
72
+ summary: Qwen 2 API Ruby SDK for RunAPI
71
73
  test_files: []
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RunApi
4
- module Qwen2
5
- module Resources
6
- # Qwen2 remix-image resource. Creates prompt-guided variations from a source image.
7
- class RemixImage
8
- include RunApi::Core::ResourceHelpers
9
-
10
- ENDPOINT = "/api/v1/qwen_2/remix_image"
11
-
12
- RESPONSE_CLASS = Types::RemixImageResponse
13
- COMPLETED_RESPONSE_CLASS = Types::CompletedRemixImageResponse
14
-
15
- def initialize(http)
16
- @http = http
17
- end
18
-
19
- # Remix an image and wait until complete.
20
- #
21
- # @param params [Hash] remix-image parameters
22
- # @return [RunApi::Qwen2::Types::CompletedRemixImageResponse] completed remix-image result
23
- def run(**params)
24
- task = create(**params)
25
- poll_until_complete { get(task.id) }
26
- end
27
-
28
- # Create a remix-image task.
29
- #
30
- # @param params [Hash] remix-image parameters
31
- # @return [RunApi::Qwen2::Types::RemixImageResponse] task creation result with id
32
- def create(**params)
33
- params = compact_params(params)
34
- validate_params!(params)
35
- request(:post, ENDPOINT, body: params)
36
- end
37
-
38
- # Get remix-image status by task ID.
39
- #
40
- # @param id [String] task ID
41
- # @return [RunApi::Qwen2::Types::RemixImageResponse] current remix-image status
42
- def get(id)
43
- request(:get, "#{ENDPOINT}/#{id}")
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
- raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
52
-
53
- model = param(params, :model)
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
- end
57
-
58
- validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
59
- end
60
- end
61
- end
62
- end
63
- end