runapi-hailuo 0.2.5 → 0.2.7
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 +6 -4
- data/lib/runapi/hailuo/client.rb +14 -6
- data/lib/runapi/hailuo/contract_gen.rb +73 -0
- data/lib/runapi/hailuo/resources/image_to_video.rb +18 -17
- data/lib/runapi/hailuo/resources/text_to_video.rb +18 -9
- data/lib/runapi/hailuo/types.rb +4 -11
- data/lib/runapi/hailuo.rb +1 -0
- metadata +11 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50152f6fb9b5ca8acd27bf0fcd7054b1a72974fa2211362e24a74cf59d871106
|
|
4
|
+
data.tar.gz: cee31f624d2d980f71d7e3a6b1bbcca4f6e3c5c33e02605a9432317d2e2a70e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34ca581e88fd2d260db1fe43e0149c90d53c7f33c9fe53e59b58908a2bf7166f98c2e0e6635fa641c7ebd05b22a216d824a9690a921146a3ba9956e8946e0fd9
|
|
7
|
+
data.tar.gz: 7f0ba801df266b32043dae6f43d2dfa7180c18807f03037c91ea65a9f49e731c1d718ce17269611e4c906c5c3e944af0507c311279a0e086e126cbb1aa1f7844
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Hailuo
|
|
1
|
+
# Hailuo API Ruby SDK for RunAPI
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Hailuo Ruby SDK is the language-specific package for Hailuo on RunAPI. Use this package for video generation, animation, and video editing workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Ruby.
|
|
4
4
|
|
|
5
|
-
This
|
|
5
|
+
This README is the Ruby package guide inside the public `hailuo-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/hailuo; for API reference, use https://runapi.ai/docs#hailuo; for SDK docs, use https://runapi.ai/docs#sdk-hailuo.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -24,9 +24,11 @@ status = client.text_to_video.get(task.id)
|
|
|
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::Hailuo` error classes when building video jobs, Rails workers, or scripts. The available resources
|
|
31
|
+
Use Ruby keyword arguments and the `RunApi::Hailuo` error classes when building video jobs, Rails workers, or scripts. The available resources are `text_to_video` and `image_to_video`. 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
|
|
data/lib/runapi/hailuo/client.rb
CHANGED
|
@@ -2,14 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Hailuo
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
# Hailuo text-to-video and image-to-video generation API client.
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# client = RunApi::Hailuo::Client.new(api_key: "your-api-key")
|
|
9
|
+
# result = client.text_to_video.run(
|
|
10
|
+
# model: "hailuo-02-text-to-video-standard",
|
|
11
|
+
# prompt: "A timelapse of cherry blossoms blooming in a Japanese garden"
|
|
12
|
+
# )
|
|
13
|
+
class Client < RunApi::Core::Client
|
|
14
|
+
# @return [Resources::TextToVideo] Text-to-video generation operations.
|
|
15
|
+
attr_reader :text_to_video
|
|
16
|
+
# @return [Resources::ImageToVideo] Image-to-video generation operations.
|
|
17
|
+
attr_reader :image_to_video
|
|
7
18
|
|
|
8
19
|
def initialize(api_key: nil, **options)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
client_options = Core::ClientOptions.new(api_key: @api_key, **options)
|
|
12
|
-
http = client_options.http_client || Core::HttpClient.new(client_options)
|
|
20
|
+
super
|
|
13
21
|
|
|
14
22
|
@text_to_video = Resources::TextToVideo.new(http)
|
|
15
23
|
@image_to_video = Resources::ImageToVideo.new(http)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RunApi
|
|
4
|
+
module Hailuo
|
|
5
|
+
CONTRACT = {
|
|
6
|
+
"image-to-video" => {
|
|
7
|
+
"models" => ["hailuo-02-image-to-video-pro", "hailuo-02-image-to-video-standard", "hailuo-2.3-image-to-video-pro", "hailuo-2.3-image-to-video-standard"],
|
|
8
|
+
"fields_by_model" => {
|
|
9
|
+
"hailuo-02-image-to-video-pro" => {
|
|
10
|
+
"duration_seconds" => {
|
|
11
|
+
"type" => "integer"
|
|
12
|
+
},
|
|
13
|
+
"first_frame_image_url" => {
|
|
14
|
+
"required" => true
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"hailuo-02-image-to-video-standard" => {
|
|
18
|
+
"duration_seconds" => {
|
|
19
|
+
"enum" => [6, 10],
|
|
20
|
+
"type" => "integer"
|
|
21
|
+
},
|
|
22
|
+
"first_frame_image_url" => {
|
|
23
|
+
"required" => true
|
|
24
|
+
},
|
|
25
|
+
"output_resolution" => {
|
|
26
|
+
"enum" => ["512p", "768p"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"hailuo-2.3-image-to-video-pro" => {
|
|
30
|
+
"duration_seconds" => {
|
|
31
|
+
"enum" => [6, 10],
|
|
32
|
+
"type" => "integer"
|
|
33
|
+
},
|
|
34
|
+
"first_frame_image_url" => {
|
|
35
|
+
"required" => true
|
|
36
|
+
},
|
|
37
|
+
"output_resolution" => {
|
|
38
|
+
"enum" => ["768p", "1080p"]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"hailuo-2.3-image-to-video-standard" => {
|
|
42
|
+
"duration_seconds" => {
|
|
43
|
+
"enum" => [6, 10],
|
|
44
|
+
"type" => "integer"
|
|
45
|
+
},
|
|
46
|
+
"first_frame_image_url" => {
|
|
47
|
+
"required" => true
|
|
48
|
+
},
|
|
49
|
+
"output_resolution" => {
|
|
50
|
+
"enum" => ["768p", "1080p"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"text-to-video" => {
|
|
56
|
+
"models" => ["hailuo-02-text-to-video-pro", "hailuo-02-text-to-video-standard"],
|
|
57
|
+
"fields_by_model" => {
|
|
58
|
+
"hailuo-02-text-to-video-pro" => {
|
|
59
|
+
"duration_seconds" => {
|
|
60
|
+
"type" => "integer"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"hailuo-02-text-to-video-standard" => {
|
|
64
|
+
"duration_seconds" => {
|
|
65
|
+
"enum" => [6, 10],
|
|
66
|
+
"type" => "integer"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}.freeze
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Hailuo
|
|
5
5
|
module Resources
|
|
6
|
+
# Hailuo image-to-video resource.
|
|
7
|
+
# Animate a still image into video guided by a text prompt and first-frame image.
|
|
6
8
|
class ImageToVideo
|
|
7
9
|
include RunApi::Core::ResourceHelpers
|
|
8
10
|
|
|
@@ -15,17 +17,29 @@ module RunApi
|
|
|
15
17
|
@http = http
|
|
16
18
|
end
|
|
17
19
|
|
|
20
|
+
# Generate an image-to-video task and wait until complete.
|
|
21
|
+
#
|
|
22
|
+
# @param params [Hash] image-to-video parameters
|
|
23
|
+
# @return [RunApi::Hailuo::Types::CompletedVideoTaskResponse] completed task with videos
|
|
18
24
|
def run(**params)
|
|
19
25
|
task = create(**params)
|
|
20
26
|
poll_until_complete { get(task.id) }
|
|
21
27
|
end
|
|
22
28
|
|
|
29
|
+
# Create an image-to-video task.
|
|
30
|
+
#
|
|
31
|
+
# @param params [Hash] image-to-video parameters
|
|
32
|
+
# @return [RunApi::Hailuo::Types::VideoTaskResponse] task creation result with id
|
|
23
33
|
def create(**params)
|
|
24
34
|
params = compact_params(params)
|
|
25
35
|
validate_params!(params)
|
|
26
36
|
request(:post, ENDPOINT, body: params)
|
|
27
37
|
end
|
|
28
38
|
|
|
39
|
+
# Get image-to-video task status by task ID.
|
|
40
|
+
#
|
|
41
|
+
# @param id [String] task ID
|
|
42
|
+
# @return [RunApi::Hailuo::Types::VideoTaskResponse] current task status
|
|
29
43
|
def get(id)
|
|
30
44
|
request(:get, "#{ENDPOINT}/#{id}")
|
|
31
45
|
end
|
|
@@ -33,26 +47,19 @@ module RunApi
|
|
|
33
47
|
private
|
|
34
48
|
|
|
35
49
|
def validate_params!(params)
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
validate_contract!(CONTRACT["image-to-video"], params)
|
|
51
|
+
|
|
38
52
|
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
39
|
-
raise Core::ValidationError, "first_frame_image_url is required" unless param(params, :first_frame_image_url)
|
|
40
53
|
|
|
54
|
+
model = param(params, :model)
|
|
41
55
|
duration_seconds = param(params, :duration_seconds)
|
|
42
56
|
output_resolution = param(params, :output_resolution)
|
|
43
57
|
|
|
44
|
-
if duration_seconds && !Types::DURATIONS.include?(duration_seconds)
|
|
45
|
-
raise Core::ValidationError, "duration_seconds must be one of: #{Types::DURATIONS.join(", ")}"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
58
|
case model
|
|
49
59
|
when "hailuo-02-image-to-video-pro"
|
|
50
60
|
raise Core::ValidationError, "duration_seconds is not supported for #{model}" if duration_seconds
|
|
51
61
|
raise Core::ValidationError, "output_resolution is not supported for #{model}" if output_resolution
|
|
52
|
-
when "hailuo-
|
|
53
|
-
validate_output_resolution!(output_resolution, Types::IMAGE_02_RESOLUTIONS) if output_resolution
|
|
54
|
-
else
|
|
55
|
-
validate_output_resolution!(output_resolution, Types::IMAGE_23_RESOLUTIONS) if output_resolution
|
|
62
|
+
when "hailuo-2.3-image-to-video-pro", "hailuo-2.3-image-to-video-standard"
|
|
56
63
|
raise Core::ValidationError, "last_frame_image_url is not supported for #{model}" if param(params, :last_frame_image_url)
|
|
57
64
|
raise Core::ValidationError, "prompt_optimizer is not supported for #{model}" if param(params, :prompt_optimizer)
|
|
58
65
|
if duration_seconds == 10 && output_resolution.to_s == "1080p"
|
|
@@ -60,12 +67,6 @@ module RunApi
|
|
|
60
67
|
end
|
|
61
68
|
end
|
|
62
69
|
end
|
|
63
|
-
|
|
64
|
-
def validate_output_resolution!(output_resolution, allowed)
|
|
65
|
-
return if allowed.include?(output_resolution.to_s)
|
|
66
|
-
|
|
67
|
-
raise Core::ValidationError, "output_resolution must be one of: #{allowed.join(", ")}"
|
|
68
|
-
end
|
|
69
70
|
end
|
|
70
71
|
end
|
|
71
72
|
end
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Hailuo
|
|
5
5
|
module Resources
|
|
6
|
+
# Hailuo text-to-video resource.
|
|
7
|
+
# Generate video from a text prompt.
|
|
6
8
|
class TextToVideo
|
|
7
9
|
include RunApi::Core::ResourceHelpers
|
|
8
10
|
|
|
@@ -15,17 +17,29 @@ module RunApi
|
|
|
15
17
|
@http = http
|
|
16
18
|
end
|
|
17
19
|
|
|
20
|
+
# Generate a text-to-video task and wait until complete.
|
|
21
|
+
#
|
|
22
|
+
# @param params [Hash] text-to-video parameters
|
|
23
|
+
# @return [RunApi::Hailuo::Types::CompletedVideoTaskResponse] completed task with videos
|
|
18
24
|
def run(**params)
|
|
19
25
|
task = create(**params)
|
|
20
26
|
poll_until_complete { get(task.id) }
|
|
21
27
|
end
|
|
22
28
|
|
|
29
|
+
# Create a text-to-video task.
|
|
30
|
+
#
|
|
31
|
+
# @param params [Hash] text-to-video parameters
|
|
32
|
+
# @return [RunApi::Hailuo::Types::VideoTaskResponse] task creation result with id
|
|
23
33
|
def create(**params)
|
|
24
34
|
params = compact_params(params)
|
|
25
35
|
validate_params!(params)
|
|
26
36
|
request(:post, ENDPOINT, body: params)
|
|
27
37
|
end
|
|
28
38
|
|
|
39
|
+
# Get text-to-video task status by task ID.
|
|
40
|
+
#
|
|
41
|
+
# @param id [String] task ID
|
|
42
|
+
# @return [RunApi::Hailuo::Types::VideoTaskResponse] current task status
|
|
29
43
|
def get(id)
|
|
30
44
|
request(:get, "#{ENDPOINT}/#{id}")
|
|
31
45
|
end
|
|
@@ -33,17 +47,12 @@ module RunApi
|
|
|
33
47
|
private
|
|
34
48
|
|
|
35
49
|
def validate_params!(params)
|
|
36
|
-
|
|
37
|
-
raise Core::ValidationError, "model is required" unless Types::TEXT_TO_VIDEO_MODELS.include?(model)
|
|
38
|
-
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
50
|
+
validate_contract!(CONTRACT["text-to-video"], params)
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
return unless duration_seconds
|
|
52
|
+
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
if model == "hailuo-02-text-to-video-pro"
|
|
54
|
+
model = param(params, :model)
|
|
55
|
+
if model == "hailuo-02-text-to-video-pro" && param(params, :duration_seconds)
|
|
47
56
|
raise Core::ValidationError, "duration_seconds is not supported for #{model}"
|
|
48
57
|
end
|
|
49
58
|
end
|
data/lib/runapi/hailuo/types.rb
CHANGED
|
@@ -2,22 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Hailuo
|
|
5
|
+
# Type definitions and constants for Hailuo video generation.
|
|
5
6
|
module Types
|
|
6
|
-
|
|
7
|
-
IMAGE_TO_VIDEO_MODELS = %w[
|
|
8
|
-
hailuo-02-image-to-video-pro
|
|
9
|
-
hailuo-02-image-to-video-standard
|
|
10
|
-
hailuo-2.3-image-to-video-pro
|
|
11
|
-
hailuo-2.3-image-to-video-standard
|
|
12
|
-
].freeze
|
|
13
|
-
DURATIONS = [6, 10].freeze
|
|
14
|
-
IMAGE_02_RESOLUTIONS = %w[512p 768p].freeze
|
|
15
|
-
IMAGE_23_RESOLUTIONS = %w[768p 1080p].freeze
|
|
16
|
-
|
|
7
|
+
# A generated video file with a download URL.
|
|
17
8
|
class MediaUrl < RunApi::Core::BaseModel
|
|
18
9
|
optional :url, String
|
|
19
10
|
end
|
|
20
11
|
|
|
12
|
+
# Video generation task status and results. Poll until status reaches a terminal state.
|
|
21
13
|
class VideoTaskResponse < RunApi::Core::TaskResponse
|
|
22
14
|
required :id, String
|
|
23
15
|
optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
|
|
@@ -25,6 +17,7 @@ module RunApi
|
|
|
25
17
|
optional :error, String
|
|
26
18
|
end
|
|
27
19
|
|
|
20
|
+
# Narrowed response returned after successful completion, guaranteeing videos is present.
|
|
28
21
|
class CompletedVideoTaskResponse < VideoTaskResponse
|
|
29
22
|
required :videos, [-> { MediaUrl }]
|
|
30
23
|
end
|
data/lib/runapi/hailuo.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runapi-hailuo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
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.
|
|
18
|
+
version: 0.2.7
|
|
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: The
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
version: 0.2.7
|
|
26
|
+
description: The Hailuo Ruby SDK is the language-specific package for Hailuo on RunAPI.
|
|
27
|
+
Use this package for video generation, animation, and video editing workflows when
|
|
28
|
+
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,6 +39,7 @@ files:
|
|
|
39
39
|
- lib/runapi-hailuo.rb
|
|
40
40
|
- lib/runapi/hailuo.rb
|
|
41
41
|
- lib/runapi/hailuo/client.rb
|
|
42
|
+
- lib/runapi/hailuo/contract_gen.rb
|
|
42
43
|
- lib/runapi/hailuo/resources/image_to_video.rb
|
|
43
44
|
- lib/runapi/hailuo/resources/text_to_video.rb
|
|
44
45
|
- lib/runapi/hailuo/types.rb
|
|
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/hailuo
|
|
|
46
47
|
licenses:
|
|
47
48
|
- Apache-2.0
|
|
48
49
|
metadata:
|
|
50
|
+
runapi_slug: hailuo
|
|
49
51
|
homepage_uri: https://runapi.ai/models/hailuo
|
|
50
52
|
documentation_uri: https://github.com/runapi-ai/hailuo-sdk/blob/main/ruby/README.md
|
|
51
53
|
source_code_uri: https://github.com/runapi-ai/hailuo-sdk
|
|
54
|
+
bug_tracker_uri: https://github.com/runapi-ai/hailuo-sdk/issues
|
|
52
55
|
changelog_uri: https://github.com/runapi-ai/hailuo-sdk/blob/main/CHANGELOG.md
|
|
53
56
|
rdoc_options: []
|
|
54
57
|
require_paths:
|
|
@@ -66,5 +69,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
66
69
|
requirements: []
|
|
67
70
|
rubygems_version: 4.0.10
|
|
68
71
|
specification_version: 4
|
|
69
|
-
summary: Hailuo
|
|
72
|
+
summary: Hailuo API Ruby SDK for RunAPI
|
|
70
73
|
test_files: []
|