runapi-grok-imagine 0.2.3 → 0.2.5
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 +4 -4
- data/README.md +43 -0
- data/lib/runapi/grok_imagine/client.rb +4 -4
- data/lib/runapi/grok_imagine/resources/{image_to_image.rb → edit_image.rb} +5 -11
- data/lib/runapi/grok_imagine/resources/extensions.rb +7 -7
- data/lib/runapi/grok_imagine/resources/image_to_video.rb +14 -14
- data/lib/runapi/grok_imagine/resources/text_to_video.rb +6 -6
- data/lib/runapi/grok_imagine/resources/upscales.rb +2 -2
- data/lib/runapi/grok_imagine/types.rb +7 -7
- data/lib/runapi/grok_imagine.rb +1 -1
- metadata +13 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a047d16be2aff78876ef12c324ceb1dd91628110f031e10a2eadf82d05dc2f9
|
|
4
|
+
data.tar.gz: 46cb2e7890b52532bc163f092cd6c3742157d510d993f6eb6200d74458cf381e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 529b03b9e38c76f7b752922fb78ca5834c244d1d5ee138a581a6c35676cfbb299af96120deb4bc3fba875ff46af464e6480e66a1fd7a227452852de55bdf5828
|
|
7
|
+
data.tar.gz: 78261dbc81e54c95471e30d15396f8cdfde4b6b52c87ceb95bed106aba320f00ab07daca0ad0300f9a5a4bf51394a05b46c247bc4a71048d38c0cf45187cc16f
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Grok Imagine API Ruby SDK for RunAPI
|
|
2
|
+
|
|
3
|
+
The grok imagine api Ruby SDK is the language-specific package for Grok Imagine on RunAPI. Use this grok imagine 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 grok imagine api README is the Ruby package guide inside the public `grok-imagine-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/grok-imagine; for API reference, use https://runapi.ai/docs#grok-imagine; for SDK docs, use https://runapi.ai/docs#sdk-grok-imagine.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
gem install runapi-grok-imagine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
require "runapi-grok-imagine"
|
|
17
|
+
|
|
18
|
+
client = RunApi::GrokImagine::Client.new
|
|
19
|
+
task = client.text_to_video.create(
|
|
20
|
+
# Pass the Grok Imagine JSON request body from https://runapi.ai/docs#grok-imagine.
|
|
21
|
+
)
|
|
22
|
+
status = client.text_to_video.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
|
+
## Language notes
|
|
28
|
+
|
|
29
|
+
Use Ruby keyword arguments and the `RunApi::GrokImagine` error classes when building image jobs, Rails workers, or scripts. The available resources include text to videos, image to videos, text to images, image to images, extensions, and upscales. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
|
30
|
+
|
|
31
|
+
## Links
|
|
32
|
+
|
|
33
|
+
- Model page: https://runapi.ai/models/grok-imagine
|
|
34
|
+
- SDK docs: https://runapi.ai/docs#sdk-grok-imagine
|
|
35
|
+
- Product docs: https://runapi.ai/docs#grok-imagine
|
|
36
|
+
- Pricing and rate limits: https://runapi.ai/models/grok-imagine/text-to-video
|
|
37
|
+
- Provider comparison: https://runapi.ai/providers/xai
|
|
38
|
+
- Full catalog: https://runapi.ai/models
|
|
39
|
+
- Repository: https://github.com/runapi-ai/grok-imagine-sdk
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -9,7 +9,7 @@ module RunApi
|
|
|
9
9
|
# result = client.text_to_video.run(
|
|
10
10
|
# model: "grok-imagine-text-to-video",
|
|
11
11
|
# prompt: "A drone shot over a neon cityscape",
|
|
12
|
-
#
|
|
12
|
+
# output_resolution: "720p"
|
|
13
13
|
# )
|
|
14
14
|
class Client
|
|
15
15
|
# @return [Resources::TextToVideo]
|
|
@@ -18,8 +18,8 @@ module RunApi
|
|
|
18
18
|
attr_reader :image_to_video
|
|
19
19
|
# @return [Resources::TextToImage]
|
|
20
20
|
attr_reader :text_to_image
|
|
21
|
-
# @return [Resources::
|
|
22
|
-
attr_reader :
|
|
21
|
+
# @return [Resources::EditImage]
|
|
22
|
+
attr_reader :edit_image
|
|
23
23
|
# @return [Resources::Extensions]
|
|
24
24
|
attr_reader :extensions
|
|
25
25
|
# @return [Resources::Upscales]
|
|
@@ -34,7 +34,7 @@ module RunApi
|
|
|
34
34
|
@text_to_video = Resources::TextToVideo.new(http)
|
|
35
35
|
@image_to_video = Resources::ImageToVideo.new(http)
|
|
36
36
|
@text_to_image = Resources::TextToImage.new(http)
|
|
37
|
-
@
|
|
37
|
+
@edit_image = Resources::EditImage.new(http)
|
|
38
38
|
@extensions = Resources::Extensions.new(http)
|
|
39
39
|
@upscales = Resources::Upscales.new(http)
|
|
40
40
|
end
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module GrokImagine
|
|
5
5
|
module Resources
|
|
6
|
-
# Grok-Imagine
|
|
7
|
-
class
|
|
6
|
+
# Grok-Imagine prompt-guided image editing resource.
|
|
7
|
+
class EditImage
|
|
8
8
|
include RunApi::Core::ResourceHelpers
|
|
9
9
|
|
|
10
|
-
ENDPOINT = "/api/v1/grok_imagine/
|
|
10
|
+
ENDPOINT = "/api/v1/grok_imagine/edit_image"
|
|
11
11
|
|
|
12
12
|
RESPONSE_CLASS = Types::ImageTaskResponse
|
|
13
13
|
COMPLETED_RESPONSE_CLASS = Types::CompletedImageTaskResponse
|
|
@@ -34,14 +34,8 @@ module RunApi
|
|
|
34
34
|
private
|
|
35
35
|
|
|
36
36
|
def validate_params!(params)
|
|
37
|
-
raise Core::ValidationError, "model is required" unless param(params, :model) == Types::
|
|
38
|
-
|
|
39
|
-
unless image_urls && !image_urls.empty?
|
|
40
|
-
raise Core::ValidationError, "image_urls is required"
|
|
41
|
-
end
|
|
42
|
-
if image_urls.size > 1
|
|
43
|
-
raise Core::ValidationError, "image_urls supports at most 1 entry"
|
|
44
|
-
end
|
|
37
|
+
raise Core::ValidationError, "model is required" unless param(params, :model) == Types::EDIT_IMAGE_MODEL
|
|
38
|
+
raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
|
|
45
39
|
end
|
|
46
40
|
end
|
|
47
41
|
end
|
|
@@ -4,7 +4,7 @@ module RunApi
|
|
|
4
4
|
module GrokImagine
|
|
5
5
|
module Resources
|
|
6
6
|
# Grok-Imagine video extension resource.
|
|
7
|
-
# Takes a prior grok-imagine video
|
|
7
|
+
# Takes a prior grok-imagine video source_task_id and extends it.
|
|
8
8
|
class Extensions
|
|
9
9
|
include RunApi::Core::ResourceHelpers
|
|
10
10
|
|
|
@@ -35,14 +35,14 @@ module RunApi
|
|
|
35
35
|
private
|
|
36
36
|
|
|
37
37
|
def validate_params!(params)
|
|
38
|
-
raise Core::ValidationError, "
|
|
38
|
+
raise Core::ValidationError, "source_task_id is required" unless param(params, :source_task_id)
|
|
39
39
|
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
40
|
-
raise Core::ValidationError, "
|
|
40
|
+
raise Core::ValidationError, "start_seconds is required" unless param(params, :start_seconds)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
raise Core::ValidationError, "
|
|
44
|
-
unless Types::
|
|
45
|
-
raise Core::ValidationError, "
|
|
42
|
+
extension_duration_seconds = param(params, :extension_duration_seconds)
|
|
43
|
+
raise Core::ValidationError, "extension_duration_seconds is required" unless extension_duration_seconds
|
|
44
|
+
unless Types::EXTENSION_DURATION_SECONDS.include?(extension_duration_seconds)
|
|
45
|
+
raise Core::ValidationError, "extension_duration_seconds must be one of: #{Types::EXTENSION_DURATION_SECONDS.join(", ")}"
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -4,7 +4,7 @@ module RunApi
|
|
|
4
4
|
module GrokImagine
|
|
5
5
|
module Resources
|
|
6
6
|
# Grok-Imagine image-to-video generation resource.
|
|
7
|
-
# Accepts either external
|
|
7
|
+
# Accepts either external source_image_urls or a prior text-to-image source_task_id (+ index).
|
|
8
8
|
class ImageToVideo
|
|
9
9
|
include RunApi::Core::ResourceHelpers
|
|
10
10
|
|
|
@@ -37,20 +37,20 @@ module RunApi
|
|
|
37
37
|
def validate_params!(params)
|
|
38
38
|
raise Core::ValidationError, "model is required" unless param(params, :model) == Types::IMAGE_TO_VIDEO_MODEL
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
source_image_urls = param(params, :source_image_urls)
|
|
41
|
+
source_task_id = param(params, :source_task_id)
|
|
42
42
|
|
|
43
|
-
if
|
|
44
|
-
raise Core::ValidationError, "Provide either
|
|
43
|
+
if source_image_urls && !source_image_urls.empty? && source_task_id
|
|
44
|
+
raise Core::ValidationError, "Provide either source_image_urls or source_task_id, not both"
|
|
45
45
|
end
|
|
46
|
-
if (!
|
|
47
|
-
raise Core::ValidationError, "One of
|
|
46
|
+
if (!source_image_urls || source_image_urls.empty?) && !source_task_id
|
|
47
|
+
raise Core::ValidationError, "One of source_image_urls or source_task_id is required"
|
|
48
48
|
end
|
|
49
|
-
if
|
|
50
|
-
raise Core::ValidationError, "
|
|
49
|
+
if source_image_urls && source_image_urls.size > 1
|
|
50
|
+
raise Core::ValidationError, "source_image_urls supports at most 1 entry"
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
if
|
|
53
|
+
if source_task_id && (index = param(params, :index))
|
|
54
54
|
int = index.to_i
|
|
55
55
|
unless Types::INDEX_RANGE.cover?(int)
|
|
56
56
|
raise Core::ValidationError, "index must be an integer between 0 and 5"
|
|
@@ -58,11 +58,11 @@ module RunApi
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
61
|
-
validate_optional!(params, :
|
|
62
|
-
validate_optional!(params, :
|
|
61
|
+
validate_optional!(params, :motion_style, Types::MOTION_STYLES)
|
|
62
|
+
validate_optional!(params, :output_resolution, Types::RESOLUTIONS)
|
|
63
63
|
|
|
64
|
-
if param(params, :
|
|
65
|
-
raise Core::ValidationError, "
|
|
64
|
+
if param(params, :motion_style).to_s == "spicy" && source_image_urls && !source_image_urls.empty?
|
|
65
|
+
raise Core::ValidationError, "spicy motion_style requires a source_task_id source image."
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
end
|
|
@@ -37,14 +37,14 @@ module RunApi
|
|
|
37
37
|
raise Core::ValidationError, "model is required" unless param(params, :model) == Types::TEXT_TO_VIDEO_MODEL
|
|
38
38
|
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
39
39
|
validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
|
|
40
|
-
validate_optional!(params, :
|
|
41
|
-
validate_optional!(params, :
|
|
40
|
+
validate_optional!(params, :motion_style, Types::MOTION_STYLES)
|
|
41
|
+
validate_optional!(params, :output_resolution, Types::RESOLUTIONS)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
if
|
|
45
|
-
int =
|
|
43
|
+
duration_seconds = param(params, :duration_seconds)
|
|
44
|
+
if duration_seconds
|
|
45
|
+
int = duration_seconds.to_i
|
|
46
46
|
unless Types::DURATION_RANGE.cover?(int)
|
|
47
|
-
raise Core::ValidationError, "
|
|
47
|
+
raise Core::ValidationError, "duration_seconds must be an integer between 6 and 30"
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -4,7 +4,7 @@ module RunApi
|
|
|
4
4
|
module GrokImagine
|
|
5
5
|
module Resources
|
|
6
6
|
# Grok-Imagine video upscale resource.
|
|
7
|
-
# Takes a prior grok-imagine video
|
|
7
|
+
# Takes a prior grok-imagine video source_task_id and upscales it.
|
|
8
8
|
class Upscales
|
|
9
9
|
include RunApi::Core::ResourceHelpers
|
|
10
10
|
|
|
@@ -35,7 +35,7 @@ module RunApi
|
|
|
35
35
|
private
|
|
36
36
|
|
|
37
37
|
def validate_params!(params)
|
|
38
|
-
raise Core::ValidationError, "
|
|
38
|
+
raise Core::ValidationError, "source_task_id is required" unless param(params, :source_task_id)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
end
|
|
@@ -6,13 +6,13 @@ module RunApi
|
|
|
6
6
|
TEXT_TO_VIDEO_MODEL = "grok-imagine-text-to-video"
|
|
7
7
|
IMAGE_TO_VIDEO_MODEL = "grok-imagine-image-to-video"
|
|
8
8
|
TEXT_TO_IMAGE_MODEL = "grok-imagine-text-to-image"
|
|
9
|
-
|
|
9
|
+
EDIT_IMAGE_MODEL = "grok-imagine-edit-image"
|
|
10
10
|
|
|
11
11
|
ASPECT_RATIOS = %w[2:3 3:2 1:1 16:9 9:16].freeze
|
|
12
|
-
|
|
12
|
+
MOTION_STYLES = %w[fun normal spicy].freeze
|
|
13
13
|
RESOLUTIONS = %w[480p 720p].freeze
|
|
14
14
|
DURATION_RANGE = (6..30)
|
|
15
|
-
|
|
15
|
+
EXTENSION_DURATION_SECONDS = [6, 10].freeze
|
|
16
16
|
INDEX_RANGE = (0..5)
|
|
17
17
|
|
|
18
18
|
class MediaUrl < RunApi::Core::BaseModel
|
|
@@ -25,21 +25,21 @@ module RunApi
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
class VideoTaskResponse < AsyncTaskResponse
|
|
28
|
-
optional :videos, [
|
|
28
|
+
optional :videos, [-> { MediaUrl }]
|
|
29
29
|
optional :error, String
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
class CompletedVideoTaskResponse < VideoTaskResponse
|
|
33
|
-
required :videos, [
|
|
33
|
+
required :videos, [-> { MediaUrl }]
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
class ImageTaskResponse < AsyncTaskResponse
|
|
37
|
-
optional :images, [
|
|
37
|
+
optional :images, [-> { MediaUrl }]
|
|
38
38
|
optional :error, String
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
class CompletedImageTaskResponse < ImageTaskResponse
|
|
42
|
-
required :images, [
|
|
42
|
+
required :images, [-> { MediaUrl }]
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
data/lib/runapi/grok_imagine.rb
CHANGED
|
@@ -5,7 +5,7 @@ require_relative "grok_imagine/types"
|
|
|
5
5
|
require_relative "grok_imagine/resources/text_to_video"
|
|
6
6
|
require_relative "grok_imagine/resources/image_to_video"
|
|
7
7
|
require_relative "grok_imagine/resources/text_to_image"
|
|
8
|
-
require_relative "grok_imagine/resources/
|
|
8
|
+
require_relative "grok_imagine/resources/edit_image"
|
|
9
9
|
require_relative "grok_imagine/resources/extensions"
|
|
10
10
|
require_relative "grok_imagine/resources/upscales"
|
|
11
11
|
require_relative "grok_imagine/client"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runapi-grok-imagine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
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.
|
|
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.
|
|
26
|
-
description:
|
|
25
|
+
version: 0.2.5
|
|
26
|
+
description: The grok imagine api Ruby SDK is the language-specific package for Grok
|
|
27
|
+
Imagine on RunAPI. Use this grok imagine api package for text-to-image, image editing,
|
|
28
|
+
and 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-grok_imagine.rb
|
|
35
40
|
- lib/runapi/grok_imagine.rb
|
|
36
41
|
- lib/runapi/grok_imagine/client.rb
|
|
42
|
+
- lib/runapi/grok_imagine/resources/edit_image.rb
|
|
37
43
|
- lib/runapi/grok_imagine/resources/extensions.rb
|
|
38
|
-
- lib/runapi/grok_imagine/resources/image_to_image.rb
|
|
39
44
|
- lib/runapi/grok_imagine/resources/image_to_video.rb
|
|
40
45
|
- lib/runapi/grok_imagine/resources/text_to_image.rb
|
|
41
46
|
- lib/runapi/grok_imagine/resources/text_to_video.rb
|
|
@@ -46,7 +51,7 @@ licenses:
|
|
|
46
51
|
- Apache-2.0
|
|
47
52
|
metadata:
|
|
48
53
|
homepage_uri: https://runapi.ai/models/grok-imagine
|
|
49
|
-
documentation_uri: https://runapi
|
|
54
|
+
documentation_uri: https://github.com/runapi-ai/grok-imagine-sdk/blob/main/ruby/README.md
|
|
50
55
|
source_code_uri: https://github.com/runapi-ai/grok-imagine-sdk
|
|
51
56
|
changelog_uri: https://github.com/runapi-ai/grok-imagine-sdk/blob/main/CHANGELOG.md
|
|
52
57
|
rdoc_options: []
|
|
@@ -65,5 +70,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
65
70
|
requirements: []
|
|
66
71
|
rubygems_version: 4.0.10
|
|
67
72
|
specification_version: 4
|
|
68
|
-
summary: Grok Imagine API
|
|
73
|
+
summary: Grok Imagine API Ruby SDK for RunAPI
|
|
69
74
|
test_files: []
|