runapi-z-image 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bea99a991310241002079dae6a3aea540b513c960b6d46d3b32d5fce8c8938f4
4
+ data.tar.gz: 91ba976ea7f03c85255e1e6015c03ede5895f6a676c5fb5a6f98d8939f0febc8
5
+ SHA512:
6
+ metadata.gz: 2462ee93947f3e2cd73e6ca39fd450f4a68ea8b149ed9299b32f33143968156eb0514e4333a4a652c6356784156739d46969fa5b5d2b72aeb4e6c399a255c300
7
+ data.tar.gz: 3d277812633afae9fbc75c7ce27af11cfe7c54b758fdecbf3a466dbacdc03e2886bdc3b10166042df92beefde3c3dc944acfdb065602448c0ca989c58500e0ba
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module ZImage
5
+ class Client
6
+ attr_reader :text_to_image
7
+
8
+ def initialize(api_key: nil, **options)
9
+ @api_key = Core::Auth.resolve_api_key(api_key)
10
+
11
+ client_options = Core::ClientOptions.new(api_key: @api_key, **options)
12
+ http = client_options.http_client || Core::HttpClient.new(client_options)
13
+ @text_to_image = Resources::TextToImage.new(http)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module ZImage
5
+ module Resources
6
+ class TextToImage
7
+ include RunApi::Core::ResourceHelpers
8
+
9
+ ENDPOINT = "/api/v1/z_image/text_to_image"
10
+
11
+ RESPONSE_CLASS = Types::TextToImageResponse
12
+ COMPLETED_RESPONSE_CLASS = Types::CompletedTextToImageResponse
13
+
14
+ def initialize(http)
15
+ @http = http
16
+ end
17
+
18
+ def run(**params)
19
+ task = create(**params)
20
+ poll_until_complete { get(task.id) }
21
+ end
22
+
23
+ def create(**params)
24
+ params = compact_params(params)
25
+ validate_params!(params)
26
+ request(:post, ENDPOINT, body: params)
27
+ end
28
+
29
+ def get(id)
30
+ request(:get, "#{ENDPOINT}/#{id}")
31
+ end
32
+
33
+ private
34
+
35
+ def validate_params!(params)
36
+ raise Core::ValidationError, "model is required" unless param(params, :model)
37
+ raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
38
+ raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
39
+
40
+ model = param(params, :model)
41
+ unless Types::MODELS.include?(model)
42
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::MODELS.join(", ")}"
43
+ end
44
+
45
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module ZImage
5
+ module Types
6
+ MODELS = %w[z-image].freeze
7
+ ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16].freeze
8
+
9
+ class Image < RunApi::Core::BaseModel
10
+ optional :url, String
11
+ end
12
+
13
+ class TextToImageResponse < RunApi::Core::TaskResponse
14
+ required :id, String
15
+ optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
16
+ optional :images, [ -> { Image } ]
17
+ optional :error, String
18
+ end
19
+
20
+ class CompletedTextToImageResponse < TextToImageResponse
21
+ required :images, [ -> { Image } ]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "runapi/core"
4
+ require_relative "z_image/types"
5
+ require_relative "z_image/resources/text_to_image"
6
+ require_relative "z_image/client"
7
+
8
+ module RunApi
9
+ module ZImage
10
+ AuthenticationError = RunApi::Core::AuthenticationError
11
+ RateLimitError = RunApi::Core::RateLimitError
12
+ InsufficientCreditsError = RunApi::Core::InsufficientCreditsError
13
+ NotFoundError = RunApi::Core::NotFoundError
14
+ ValidationError = RunApi::Core::ValidationError
15
+ TaskFailedError = RunApi::Core::TaskFailedError
16
+ TaskTimeoutError = RunApi::Core::TaskTimeoutError
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "runapi/z_image"
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runapi-z-image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RunAPI
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: runapi-core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.1'
26
+ description: RunAPI Z-Image SDK for JavaScript, Ruby, and Go
27
+ email:
28
+ - contact@runapi.ai
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/runapi-z_image.rb
34
+ - lib/runapi/z_image.rb
35
+ - lib/runapi/z_image/client.rb
36
+ - lib/runapi/z_image/resources/text_to_image.rb
37
+ - lib/runapi/z_image/types.rb
38
+ homepage: https://runapi.ai/models/z-image
39
+ licenses:
40
+ - Apache-2.0
41
+ metadata:
42
+ homepage_uri: https://runapi.ai/models/z-image
43
+ documentation_uri: https://runapi.ai/models/z-image
44
+ source_code_uri: https://github.com/runapi-ai/z-image-sdk
45
+ changelog_uri: https://github.com/runapi-ai/z-image-sdk/blob/main/CHANGELOG.md
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.1.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 4.0.6
61
+ specification_version: 4
62
+ summary: Z-Image API SDKs for JavaScript, Ruby, and Go on RunAPI.
63
+ test_files: []