runapi-ideogram-v3 0.2.4 → 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: fa5a4f6c6c74bfc6cdaa9bf20a9ee5e32e5d29767cc55fe832176dd39fcc941c
4
- data.tar.gz: adeccc0f2be866d773397005f46603736545f864d4a8a8e16c72e3c06bce0ea1
3
+ metadata.gz: fc1b721eb9666ebffa9d974a30ffb4f015b4d69ca74ead610686c17b6b0bcff2
4
+ data.tar.gz: 786042996e23818cdb4bc76eb869812176acd99415210cff8ddd68bdb16bea17
5
5
  SHA512:
6
- metadata.gz: b694267f9dab0786be2f1aa5dbc365aaa4b174bd320356f8f456dd7b7acd8e06ddd24dc1021547945da86e74a2148112797a55762e208379cc2a16b44887674f
7
- data.tar.gz: 02704e5b9736501d2a8ef2d55447d947643843407c1e75f565e7f085cb2388956d00368c33cb3aa98c7af778c17597571bffd6b6be22d52294fb0c9092e635f7
6
+ metadata.gz: 8f266081742ba4681706682f442ede15030f87414320db93931a0ecf01bc4c93de779b8bbdf373bd82c0c9a5476aade094f3e53c53bd20c2c606f37974a64496
7
+ data.tar.gz: 67f3908f740aea4409b719a265b019d5da5fdd538ff5e2ddd4b02173ec5b7c01b22c452ead216da9f663c1717996a9b381696d3447e8fff8b0e1d87f08c8d1cc
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Ideogram API Ruby SDK for RunAPI
2
+
3
+ The ideogram api Ruby SDK is the language-specific package for Ideogram V3 on RunAPI. Use this ideogram api package for text-to-image, character reference generation, edit, remix, reframe, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
+
5
+ This ideogram api README is the Ruby package guide inside the public `ideogram-v3-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/ideogram-v3; for API reference, use https://runapi.ai/docs#ideogram-v3; for SDK docs, use https://runapi.ai/docs#sdk-ideogram-v3.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-ideogram-v3
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-ideogram-v3"
17
+
18
+ client = RunApi::IdeogramV3::Client.new
19
+ task = client.text_to_image.create(
20
+ model: "ideogram-v3-text-to-image",
21
+ prompt: "A cinematic lakeside at twilight with neon reeds"
22
+ )
23
+ status = client.text_to_image.get(task.id)
24
+ ```
25
+
26
+ 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.
27
+
28
+ ## Language notes
29
+
30
+ Use Ruby keyword arguments and the `RunApi::IdeogramV3` error classes when building image jobs, Rails workers, or scripts. The available resources are `text_to_image`, `edit_image`, `remix_image`, and `reframe_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
31
+
32
+ ## Links
33
+
34
+ - Model page: https://runapi.ai/models/ideogram-v3
35
+ - SDK docs: https://runapi.ai/docs#sdk-ideogram-v3
36
+ - Product docs: https://runapi.ai/docs#ideogram-v3
37
+ - Pricing and rate limits: https://runapi.ai/models/ideogram-v3/text-to-image
38
+ - Provider comparison: https://runapi.ai/providers/ideogram
39
+ - Full catalog: https://runapi.ai/models
40
+ - Repository: https://github.com/runapi-ai/ideogram-v3-sdk
41
+
42
+ ## License
43
+
44
+ Licensed under the Apache License, Version 2.0.
@@ -14,7 +14,8 @@ module RunApi
14
14
  # @return [Resources::TextToImage] Text-to-image operations.
15
15
  # @return [Resources::EditImage] Inpaint-with-mask operations.
16
16
  # @return [Resources::RemixImage] Image remix operations.
17
- attr_reader :text_to_image, :edit_image, :remix_image
17
+ # @return [Resources::ReframeImage] Image reframe operations.
18
+ attr_reader :text_to_image, :edit_image, :remix_image, :reframe_image
18
19
 
19
20
  def initialize(api_key: nil, **options)
20
21
  @api_key = Core::Auth.resolve_api_key(api_key)
@@ -24,6 +25,7 @@ module RunApi
24
25
  @text_to_image = Resources::TextToImage.new(http)
25
26
  @edit_image = Resources::EditImage.new(http)
26
27
  @remix_image = Resources::RemixImage.new(http)
28
+ @reframe_image = Resources::ReframeImage.new(http)
27
29
  end
28
30
  end
29
31
  end
@@ -36,8 +36,8 @@ module RunApi
36
36
  def validate_params!(params)
37
37
  model = param(params, :model)
38
38
  raise Core::ValidationError, "model is required" unless model
39
- unless model == Types::EDIT_MODEL
40
- raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::EDIT_MODEL}"
39
+ unless [Types::EDIT_MODEL, Types::CHARACTER_EDIT_MODEL].include?(model)
40
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::EDIT_MODEL} or #{Types::CHARACTER_EDIT_MODEL}"
41
41
  end
42
42
 
43
43
  prompt = param(params, :prompt)
@@ -46,10 +46,29 @@ module RunApi
46
46
  raise Core::ValidationError, "prompt must be at most #{PROMPT_MAX_LENGTH} characters"
47
47
  end
48
48
 
49
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
49
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
50
50
  raise Core::ValidationError, "mask_url is required" unless param(params, :mask_url)
51
51
 
52
52
  validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
53
+ validate_character_fields!(params, model)
54
+ end
55
+
56
+ def validate_character_fields!(params, model)
57
+ refs = param(params, :reference_image_urls)
58
+ if model == Types::CHARACTER_EDIT_MODEL
59
+ raise Core::ValidationError, "reference_image_urls is required" unless refs.is_a?(Array) && refs.any?
60
+ validate_optional!(params, :style, Types::CHARACTER_STYLES)
61
+ elsif refs || param(params, :style)
62
+ raise Core::ValidationError, "character edit fields are not supported for #{model}"
63
+ end
64
+ validate_output_count!(params)
65
+ end
66
+
67
+ def validate_output_count!(params)
68
+ return unless (output_count = param(params, :output_count))
69
+ return if Types::OUTPUT_COUNTS.include?(output_count)
70
+
71
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
53
72
  end
54
73
  end
55
74
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module IdeogramV3
5
+ module Resources
6
+ # Reframe an input image (model: ideogram-v3-reframe).
7
+ class ReframeImage
8
+ include RunApi::Core::ResourceHelpers
9
+
10
+ ENDPOINT = "/api/v1/ideogram_v3/reframe_image"
11
+ RESPONSE_CLASS = Types::IdeogramResponse
12
+ COMPLETED_RESPONSE_CLASS = Types::CompletedIdeogramResponse
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
+ model = param(params, :model)
37
+ raise Core::ValidationError, "model is required" unless model
38
+ unless model == Types::REFRAME_MODEL
39
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::REFRAME_MODEL}"
40
+ end
41
+
42
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
43
+ raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
44
+
45
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
46
+ validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
47
+ validate_optional!(params, :style, Types::STYLES)
48
+ validate_output_count!(params)
49
+ end
50
+
51
+ def validate_output_count!(params)
52
+ return unless (output_count = param(params, :output_count))
53
+ return if Types::OUTPUT_COUNTS.include?(output_count)
54
+
55
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -12,6 +12,7 @@ module RunApi
12
12
  COMPLETED_RESPONSE_CLASS = Types::CompletedIdeogramResponse
13
13
  PROMPT_MAX_LENGTH = 5000
14
14
  STRENGTH_MIN = 0.01
15
+ CHARACTER_REMIX_STRENGTH_MIN = 0.1
15
16
  STRENGTH_MAX = 1.0
16
17
 
17
18
  def initialize(http)
@@ -38,8 +39,8 @@ module RunApi
38
39
  def validate_params!(params)
39
40
  model = param(params, :model)
40
41
  raise Core::ValidationError, "model is required" unless model
41
- unless model == Types::REMIX_MODEL
42
- raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::REMIX_MODEL}"
42
+ unless [Types::REMIX_MODEL, Types::CHARACTER_REMIX_MODEL].include?(model)
43
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::REMIX_MODEL} or #{Types::CHARACTER_REMIX_MODEL}"
43
44
  end
44
45
 
45
46
  prompt = param(params, :prompt)
@@ -48,25 +49,37 @@ module RunApi
48
49
  raise Core::ValidationError, "prompt must be at most #{PROMPT_MAX_LENGTH} characters"
49
50
  end
50
51
 
51
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
52
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
52
53
 
53
54
  validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
54
- validate_optional!(params, :style, Types::STYLES)
55
- validate_optional!(params, :image_size, Types::IMAGE_SIZES)
55
+ style_values = (model == Types::CHARACTER_REMIX_MODEL) ? Types::CHARACTER_STYLES : Types::STYLES
56
+ validate_optional!(params, :style, style_values)
57
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
58
+ validate_character_fields!(params, model)
56
59
 
57
- if (num_images = param(params, :num_images))
58
- unless Types::NUM_IMAGES.include?(num_images.to_s)
59
- raise Core::ValidationError, "Invalid num_images: #{num_images}. Must be one of: #{Types::NUM_IMAGES.join(", ")}"
60
+ if (output_count = param(params, :output_count))
61
+ unless Types::OUTPUT_COUNTS.include?(output_count)
62
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
60
63
  end
61
64
  end
62
65
 
63
66
  if (strength = param(params, :strength))
64
67
  numeric = Float(strength, exception: false)
65
- if numeric.nil? || numeric < STRENGTH_MIN || numeric > STRENGTH_MAX
66
- raise Core::ValidationError, "strength must be between #{STRENGTH_MIN} and #{STRENGTH_MAX}"
68
+ min = (model == Types::CHARACTER_REMIX_MODEL) ? CHARACTER_REMIX_STRENGTH_MIN : STRENGTH_MIN
69
+ if numeric.nil? || numeric < min || numeric > STRENGTH_MAX
70
+ raise Core::ValidationError, "strength must be between #{min} and #{STRENGTH_MAX}"
67
71
  end
68
72
  end
69
73
  end
74
+
75
+ def validate_character_fields!(params, model)
76
+ refs = param(params, :reference_image_urls)
77
+ if model == Types::CHARACTER_REMIX_MODEL
78
+ raise Core::ValidationError, "reference_image_urls is required" unless refs.is_a?(Array) && refs.any?
79
+ elsif refs || param(params, :style_reference_image_urls) || param(params, :reference_mask_urls)
80
+ raise Core::ValidationError, "character remix fields are not supported for #{model}"
81
+ end
82
+ end
70
83
  end
71
84
  end
72
85
  end
@@ -36,8 +36,8 @@ module RunApi
36
36
  def validate_params!(params)
37
37
  model = param(params, :model)
38
38
  raise Core::ValidationError, "model is required" unless model
39
- unless model == Types::GENERATION_MODEL
40
- raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::GENERATION_MODEL}"
39
+ unless [Types::GENERATION_MODEL, Types::CHARACTER_MODEL].include?(model)
40
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::GENERATION_MODEL} or #{Types::CHARACTER_MODEL}"
41
41
  end
42
42
 
43
43
  prompt = param(params, :prompt)
@@ -47,8 +47,28 @@ module RunApi
47
47
  end
48
48
 
49
49
  validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
50
- validate_optional!(params, :style, Types::STYLES)
51
- validate_optional!(params, :image_size, Types::IMAGE_SIZES)
50
+ style_values = (model == Types::CHARACTER_MODEL) ? Types::CHARACTER_STYLES : Types::STYLES
51
+ validate_optional!(params, :style, style_values)
52
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
53
+ validate_character_refs!(params, model)
54
+ validate_output_count!(params)
55
+ end
56
+
57
+ def validate_character_refs!(params, model)
58
+ refs = param(params, :reference_image_urls)
59
+ if model == Types::CHARACTER_MODEL
60
+ raise Core::ValidationError, "reference_image_urls is required" unless refs.is_a?(Array) && refs.any?
61
+ elsif refs
62
+ raise Core::ValidationError, "reference_image_urls is not supported for #{model}"
63
+ end
64
+ end
65
+
66
+ def validate_output_count!(params)
67
+ output_count = param(params, :output_count)
68
+ return unless output_count
69
+ return if Types::OUTPUT_COUNTS.include?(output_count)
70
+
71
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
52
72
  end
53
73
  end
54
74
  end
@@ -6,13 +6,16 @@ module RunApi
6
6
  GENERATION_MODEL = "ideogram-v3-text-to-image"
7
7
  EDIT_MODEL = "ideogram-v3-edit"
8
8
  REMIX_MODEL = "ideogram-v3-remix"
9
+ CHARACTER_MODEL = "ideogram-v3-character"
10
+ CHARACTER_EDIT_MODEL = "ideogram-v3-character-edit"
11
+ CHARACTER_REMIX_MODEL = "ideogram-v3-character-remix"
12
+ REFRAME_MODEL = "ideogram-v3-reframe"
9
13
 
10
- RENDERING_SPEEDS = %w[TURBO BALANCED QUALITY].freeze
11
- STYLES = %w[AUTO GENERAL REALISTIC DESIGN].freeze
12
- IMAGE_SIZES = %w[
13
- square square_hd portrait_4_3 portrait_16_9 landscape_4_3 landscape_16_9
14
- ].freeze
15
- NUM_IMAGES = %w[1 2 3 4].freeze
14
+ RENDERING_SPEEDS = %w[turbo balanced quality].freeze
15
+ STYLES = %w[auto general realistic design].freeze
16
+ CHARACTER_STYLES = %w[auto realistic fiction].freeze
17
+ ASPECT_RATIOS = %w[1:1 3:4 9:16 4:3 16:9].freeze
18
+ OUTPUT_COUNTS = [1, 2, 3, 4].freeze
16
19
 
17
20
  class Image < RunApi::Core::BaseModel
18
21
  optional :url, String
@@ -21,13 +24,13 @@ module RunApi
21
24
  class IdeogramResponse < RunApi::Core::TaskResponse
22
25
  required :id, String
23
26
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
24
- optional :images, [ -> { Image } ]
27
+ optional :images, [-> { Image }]
25
28
  optional :error, String
26
29
  end
27
30
 
28
31
  # Narrowed response returned by `run()` once polling sees `status: "completed"`.
29
32
  class CompletedIdeogramResponse < IdeogramResponse
30
- required :images, [ -> { Image } ]
33
+ required :images, [-> { Image }]
31
34
  end
32
35
  end
33
36
  end
@@ -5,6 +5,7 @@ require_relative "ideogram_v3/types"
5
5
  require_relative "ideogram_v3/resources/text_to_image"
6
6
  require_relative "ideogram_v3/resources/edit_image"
7
7
  require_relative "ideogram_v3/resources/remix_image"
8
+ require_relative "ideogram_v3/resources/reframe_image"
8
9
  require_relative "ideogram_v3/client"
9
10
 
10
11
  module RunApi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-ideogram-v3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,26 +15,32 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.4
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.2.4
26
- description: RunAPI Ideogram V3 SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.5
26
+ description: The ideogram api Ruby SDK is the language-specific package for Ideogram
27
+ V3 on RunAPI. Use this ideogram api package for text-to-image, character reference
28
+ generation, edit, remix, reframe, and creative production flows when your application
29
+ needs JSON request bodies, task 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-ideogram_v3.rb
35
40
  - lib/runapi/ideogram_v3.rb
36
41
  - lib/runapi/ideogram_v3/client.rb
37
42
  - lib/runapi/ideogram_v3/resources/edit_image.rb
43
+ - lib/runapi/ideogram_v3/resources/reframe_image.rb
38
44
  - lib/runapi/ideogram_v3/resources/remix_image.rb
39
45
  - lib/runapi/ideogram_v3/resources/text_to_image.rb
40
46
  - lib/runapi/ideogram_v3/types.rb
@@ -43,7 +49,7 @@ licenses:
43
49
  - Apache-2.0
44
50
  metadata:
45
51
  homepage_uri: https://runapi.ai/models/ideogram-v3
46
- documentation_uri: https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/README.md
52
+ documentation_uri: https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/ruby/README.md
47
53
  source_code_uri: https://github.com/runapi-ai/ideogram-v3-sdk
48
54
  changelog_uri: https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/CHANGELOG.md
49
55
  rdoc_options: []
@@ -62,5 +68,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
68
  requirements: []
63
69
  rubygems_version: 4.0.10
64
70
  specification_version: 4
65
- summary: Ideogram V3 API SDKs for JavaScript, Ruby, and Go on RunAPI.
71
+ summary: Ideogram API Ruby SDK for RunAPI
66
72
  test_files: []