runapi-qwen-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7cbfba501dd88b37a82629dee1237753f030d6d92a06faac41f6165985aed21
4
- data.tar.gz: ec3086cde57f139b0621c21c4e33e18a32aefbaf96be7f53c9757ddefb2631a4
3
+ metadata.gz: 2956586742f9d0861230f9896d032a1b9525325c3f18107eb3051133041ae180
4
+ data.tar.gz: d4639d731229589fa4e6b389771bbd1219ce62fe8488a86cc4671ef32a034ce3
5
5
  SHA512:
6
- metadata.gz: c98213aac1b753e131550119533febb83cbf2e7543479750074458085e54d5be05772018d511f0cb3011aa70c55bbe1d53bce4691b410cfdea7758ade3c4f840
7
- data.tar.gz: 7f564584fcde1efed7db34abf0a606d36ca59661b496f449cdf00d8137d9a91c32765e5289e357ed15a58627424dbf0ff91ee1a3335c5c6963045ae388550be8
6
+ metadata.gz: c668a2fbf31074afecc12aac9d4d493afe3fada577f0506f9993268355e2d1f3046f1d6db659812294ab0f71bc4d01c00ddd9a7d252c34b015ca0465f1f42e95
7
+ data.tar.gz: 7f14e473674084d4a1e76b28d28ab3a8703089ab91e9a80bc8310bf3b0e460b3960255ad76d7721098800bff50b9b380779fda48027566d7ea899325956e2fba
data/README.md CHANGED
@@ -1,32 +1,34 @@
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.
26
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
+
27
29
  ## Language notes
28
30
 
29
- 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.
30
32
 
31
33
  ## Links
32
34
 
@@ -2,7 +2,9 @@
2
2
 
3
3
  module RunApi
4
4
  module Qwen2
5
- # Qwen2 text-to-image, remix-image, and edit-image API client.
5
+ # Qwen 2 image generation and editing API client.
6
+ #
7
+ # Text-to-image generation and targeted modifications to source images.
6
8
  #
7
9
  # @example
8
10
  # client = RunApi::Qwen2::Client.new(api_key: "your-api-key")
@@ -11,17 +13,15 @@ module RunApi
11
13
  # prompt: "Replace the background with a neon-lit city skyline",
12
14
  # source_image_url: "https://cdn.runapi.ai/public/samples/input.jpg"
13
15
  # )
14
- class Client
15
- # @return [Resources::TextToImage, Resources::RemixImage, Resources::EditImage] Image operations.
16
- attr_reader :text_to_image, :remix_image, :edit_image
16
+ class Client < RunApi::Core::Client
17
+ # @return [Resources::TextToImage] Generate images from text prompts.
18
+ attr_reader :text_to_image
19
+ # @return [Resources::EditImage] Apply targeted edits to a source image using natural-language prompts.
20
+ attr_reader :edit_image
17
21
 
18
22
  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)
23
+ super
23
24
  @text_to_image = Resources::TextToImage.new(http)
24
- @remix_image = Resources::RemixImage.new(http)
25
25
  @edit_image = Resources::EditImage.new(http)
26
26
  end
27
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,18 +3,12 @@
3
3
  module RunApi
4
4
  module Qwen2
5
5
  module Types
6
- MODELS = %w[qwen-2-edit-image qwen-2-text-to-image qwen-2-remix-image].freeze
7
- EDIT_MODELS = %w[qwen-2-edit-image].freeze
8
- TEXT_TO_IMAGE_MODELS = %w[qwen-2-text-to-image].freeze
9
- REMIX_IMAGE_MODELS = %w[qwen-2-remix-image].freeze
10
- EDIT_IMAGE_ASPECT_RATIOS = %w[1:1 2:3 3:2 3:4 4:3 9:16 16:9 21:9].freeze
11
- TEXT_TO_IMAGE_ASPECT_RATIOS = %w[1:1 3:4 4:3 9:16 16:9].freeze
12
- OUTPUT_FORMATS = %w[jpeg png].freeze
13
-
6
+ # A single generated image result.
14
7
  class Image < RunApi::Core::BaseModel
15
8
  optional :url, String
16
9
  end
17
10
 
11
+ # Shared task result for all Qwen 2 image operations.
18
12
  class ImageTaskResponse < RunApi::Core::TaskResponse
19
13
  required :id, String
20
14
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
@@ -23,17 +17,15 @@ module RunApi
23
17
  end
24
18
 
25
19
  class TextToImageResponse < ImageTaskResponse; end
26
- class RemixImageResponse < ImageTaskResponse; end
27
20
  class EditImageResponse < ImageTaskResponse; end
28
21
 
22
+ # Narrowed responses returned by +run()+ methods once polling observes
23
+ # +status: "completed"+. +images+ is required so consumers never
24
+ # have to null-check it on a successful task.
29
25
  class CompletedTextToImageResponse < TextToImageResponse
30
26
  required :images, [-> { Image }]
31
27
  end
32
28
 
33
- class CompletedRemixImageResponse < RemixImageResponse
34
- required :images, [-> { Image }]
35
- end
36
-
37
29
  class CompletedEditImageResponse < EditImageResponse
38
30
  required :images, [-> { Image }]
39
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.6
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.5
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.5
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