runapi-infinitetalk 0.1.0__tar.gz
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.
- runapi_infinitetalk-0.1.0/.gitignore +29 -0
- runapi_infinitetalk-0.1.0/PKG-INFO +84 -0
- runapi_infinitetalk-0.1.0/README.md +71 -0
- runapi_infinitetalk-0.1.0/pyproject.toml +30 -0
- runapi_infinitetalk-0.1.0/src/runapi/infinitetalk/__init__.py +24 -0
- runapi_infinitetalk-0.1.0/src/runapi/infinitetalk/client.py +30 -0
- runapi_infinitetalk-0.1.0/src/runapi/infinitetalk/py.typed +0 -0
- runapi_infinitetalk-0.1.0/src/runapi/infinitetalk/resources/__init__.py +3 -0
- runapi_infinitetalk-0.1.0/src/runapi/infinitetalk/resources/audio_to_video.py +97 -0
- runapi_infinitetalk-0.1.0/src/runapi/infinitetalk/types.py +30 -0
- runapi_infinitetalk-0.1.0/tests/test_client.py +227 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Build artifacts
|
|
2
|
+
dist/
|
|
3
|
+
build/
|
|
4
|
+
*.egg-info/
|
|
5
|
+
*.egg
|
|
6
|
+
|
|
7
|
+
# Bytecode
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
|
|
15
|
+
# uv
|
|
16
|
+
uv.lock
|
|
17
|
+
|
|
18
|
+
# Test / type caches
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
.mypy_cache/
|
|
21
|
+
.ruff_cache/
|
|
22
|
+
.coverage
|
|
23
|
+
htmlcov/
|
|
24
|
+
|
|
25
|
+
# IDE / OS
|
|
26
|
+
.idea/
|
|
27
|
+
.vscode/
|
|
28
|
+
*.swp
|
|
29
|
+
.DS_Store
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: runapi-infinitetalk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: InfiniteTalk audio-to-video client for RunAPI
|
|
5
|
+
Project-URL: Homepage, https://runapi.ai/models/infinitetalk
|
|
6
|
+
Project-URL: Documentation, https://runapi.ai/docs#sdk-infinitetalk
|
|
7
|
+
Author-email: RunAPI <contact@runapi.ai>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Keywords: ai,audio-to-video,infinitetalk,runapi,sdk
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: runapi-core
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# InfiniteTalk Python SDK for RunAPI
|
|
15
|
+
|
|
16
|
+
The InfiniteTalk Python SDK is the language-specific package for InfiniteTalk on
|
|
17
|
+
RunAPI. Use it for audio-to-video flows when your application needs JSON request
|
|
18
|
+
bodies, task status lookup, and consistent RunAPI errors in Python.
|
|
19
|
+
|
|
20
|
+
For model details, use https://runapi.ai/models/infinitetalk; for API reference,
|
|
21
|
+
use https://runapi.ai/docs#infinitetalk; for SDK docs, use
|
|
22
|
+
https://runapi.ai/docs#sdk-infinitetalk.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install runapi-infinitetalk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from runapi.infinitetalk import InfinitetalkClient
|
|
34
|
+
|
|
35
|
+
client = InfinitetalkClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
|
|
36
|
+
|
|
37
|
+
task = client.audio_to_video.create(
|
|
38
|
+
model="infinitetalk-from-audio",
|
|
39
|
+
source_image_url="https://example.com/face.jpg",
|
|
40
|
+
source_audio_url="https://example.com/voice.mp3",
|
|
41
|
+
prompt="A person speaking to the camera",
|
|
42
|
+
output_resolution="720p",
|
|
43
|
+
)
|
|
44
|
+
status = client.audio_to_video.get(task.id)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Use `create` to submit a task and return quickly, `get` to fetch the latest task
|
|
48
|
+
state, and `run` to create and poll until completion:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
result = client.audio_to_video.run(
|
|
52
|
+
model="infinitetalk-from-audio",
|
|
53
|
+
source_image_url="https://example.com/face.jpg",
|
|
54
|
+
source_audio_url="https://example.com/voice.mp3",
|
|
55
|
+
prompt="A person speaking to the camera",
|
|
56
|
+
)
|
|
57
|
+
print(result.videos[0].url)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
In web request handlers, prefer `create` plus webhook or later `get` polling so a
|
|
61
|
+
worker is not held open.
|
|
62
|
+
|
|
63
|
+
RunAPI-generated file URLs are temporary. Download and store generated videos in
|
|
64
|
+
your own durable storage within 7 days; do not treat returned URLs as long-term
|
|
65
|
+
assets.
|
|
66
|
+
|
|
67
|
+
## Language notes
|
|
68
|
+
|
|
69
|
+
Pass parameters as keyword arguments and catch the `runapi.infinitetalk` error
|
|
70
|
+
classes when building video jobs or scripts. The available resource is
|
|
71
|
+
`audio_to_video`. Keep `RUNAPI_API_KEY` in the environment or your secret
|
|
72
|
+
manager; never commit API keys or callback secrets.
|
|
73
|
+
|
|
74
|
+
## Links
|
|
75
|
+
|
|
76
|
+
- Model page: https://runapi.ai/models/infinitetalk
|
|
77
|
+
- SDK docs: https://runapi.ai/docs#sdk-infinitetalk
|
|
78
|
+
- Product docs: https://runapi.ai/docs#infinitetalk
|
|
79
|
+
- Pricing and rate limits: https://runapi.ai/models/infinitetalk
|
|
80
|
+
- Full catalog: https://runapi.ai/models
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# InfiniteTalk Python SDK for RunAPI
|
|
2
|
+
|
|
3
|
+
The InfiniteTalk Python SDK is the language-specific package for InfiniteTalk on
|
|
4
|
+
RunAPI. Use it for audio-to-video flows when your application needs JSON request
|
|
5
|
+
bodies, task status lookup, and consistent RunAPI errors in Python.
|
|
6
|
+
|
|
7
|
+
For model details, use https://runapi.ai/models/infinitetalk; for API reference,
|
|
8
|
+
use https://runapi.ai/docs#infinitetalk; for SDK docs, use
|
|
9
|
+
https://runapi.ai/docs#sdk-infinitetalk.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install runapi-infinitetalk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from runapi.infinitetalk import InfinitetalkClient
|
|
21
|
+
|
|
22
|
+
client = InfinitetalkClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
|
|
23
|
+
|
|
24
|
+
task = client.audio_to_video.create(
|
|
25
|
+
model="infinitetalk-from-audio",
|
|
26
|
+
source_image_url="https://example.com/face.jpg",
|
|
27
|
+
source_audio_url="https://example.com/voice.mp3",
|
|
28
|
+
prompt="A person speaking to the camera",
|
|
29
|
+
output_resolution="720p",
|
|
30
|
+
)
|
|
31
|
+
status = client.audio_to_video.get(task.id)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use `create` to submit a task and return quickly, `get` to fetch the latest task
|
|
35
|
+
state, and `run` to create and poll until completion:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
result = client.audio_to_video.run(
|
|
39
|
+
model="infinitetalk-from-audio",
|
|
40
|
+
source_image_url="https://example.com/face.jpg",
|
|
41
|
+
source_audio_url="https://example.com/voice.mp3",
|
|
42
|
+
prompt="A person speaking to the camera",
|
|
43
|
+
)
|
|
44
|
+
print(result.videos[0].url)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
In web request handlers, prefer `create` plus webhook or later `get` polling so a
|
|
48
|
+
worker is not held open.
|
|
49
|
+
|
|
50
|
+
RunAPI-generated file URLs are temporary. Download and store generated videos in
|
|
51
|
+
your own durable storage within 7 days; do not treat returned URLs as long-term
|
|
52
|
+
assets.
|
|
53
|
+
|
|
54
|
+
## Language notes
|
|
55
|
+
|
|
56
|
+
Pass parameters as keyword arguments and catch the `runapi.infinitetalk` error
|
|
57
|
+
classes when building video jobs or scripts. The available resource is
|
|
58
|
+
`audio_to_video`. Keep `RUNAPI_API_KEY` in the environment or your secret
|
|
59
|
+
manager; never commit API keys or callback secrets.
|
|
60
|
+
|
|
61
|
+
## Links
|
|
62
|
+
|
|
63
|
+
- Model page: https://runapi.ai/models/infinitetalk
|
|
64
|
+
- SDK docs: https://runapi.ai/docs#sdk-infinitetalk
|
|
65
|
+
- Product docs: https://runapi.ai/docs#infinitetalk
|
|
66
|
+
- Pricing and rate limits: https://runapi.ai/models/infinitetalk
|
|
67
|
+
- Full catalog: https://runapi.ai/models
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "runapi-infinitetalk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "InfiniteTalk audio-to-video client for RunAPI"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
|
|
13
|
+
keywords = ["runapi", "infinitetalk", "audio-to-video", "ai", "sdk"]
|
|
14
|
+
dependencies = ["runapi-core"]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://runapi.ai/models/infinitetalk"
|
|
18
|
+
Documentation = "https://runapi.ai/docs#sdk-infinitetalk"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["src/runapi"]
|
|
22
|
+
|
|
23
|
+
[tool.uv]
|
|
24
|
+
package = true
|
|
25
|
+
|
|
26
|
+
[tool.uv.sources]
|
|
27
|
+
runapi-core = { path = "../runapi-core", editable = true }
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = ["pytest>=8"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""InfiniteTalk client for RunAPI."""
|
|
2
|
+
|
|
3
|
+
from runapi.core import (
|
|
4
|
+
AuthenticationError,
|
|
5
|
+
InsufficientCreditsError,
|
|
6
|
+
NotFoundError,
|
|
7
|
+
RateLimitError,
|
|
8
|
+
TaskFailedError,
|
|
9
|
+
TaskTimeoutError,
|
|
10
|
+
ValidationError,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .client import InfinitetalkClient
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"InfinitetalkClient",
|
|
17
|
+
"AuthenticationError",
|
|
18
|
+
"RateLimitError",
|
|
19
|
+
"InsufficientCreditsError",
|
|
20
|
+
"NotFoundError",
|
|
21
|
+
"ValidationError",
|
|
22
|
+
"TaskFailedError",
|
|
23
|
+
"TaskTimeoutError",
|
|
24
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""InfiniteTalk client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
from runapi.core import ClientOptions, HttpClient, resolve_api_key
|
|
8
|
+
|
|
9
|
+
from .resources.audio_to_video import AudioToVideo
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class InfinitetalkClient:
|
|
13
|
+
"""InfiniteTalk audio-to-video client.
|
|
14
|
+
|
|
15
|
+
Example::
|
|
16
|
+
|
|
17
|
+
client = InfinitetalkClient(api_key="sk-...")
|
|
18
|
+
result = client.audio_to_video.run(
|
|
19
|
+
model="infinitetalk-from-audio",
|
|
20
|
+
source_image_url="https://example.com/face.jpg",
|
|
21
|
+
source_audio_url="https://example.com/voice.mp3",
|
|
22
|
+
prompt="A person speaking to the camera",
|
|
23
|
+
)
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
|
|
27
|
+
resolved_api_key = resolve_api_key(api_key)
|
|
28
|
+
client_options = ClientOptions(api_key=resolved_api_key, **options)
|
|
29
|
+
http = client_options.http_client or HttpClient(client_options)
|
|
30
|
+
self.audio_to_video = AudioToVideo(http)
|
|
File without changes
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""InfiniteTalk audio-to-video resource."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource, ValidationError
|
|
8
|
+
|
|
9
|
+
from ..types import (
|
|
10
|
+
MODELS,
|
|
11
|
+
RESOLUTIONS,
|
|
12
|
+
AudioToVideoResponse,
|
|
13
|
+
CompletedAudioToVideoResponse,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
PROMPT_MAX_LENGTH = 5000
|
|
17
|
+
SEED_RANGE = range(10_000, 1_000_001)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AudioToVideo(Resource):
|
|
21
|
+
"""Generate a talking-head video from a source image and audio track."""
|
|
22
|
+
|
|
23
|
+
ENDPOINT = "/api/v1/infinitetalk/audio_to_video"
|
|
24
|
+
|
|
25
|
+
RESPONSE_CLASS = AudioToVideoResponse
|
|
26
|
+
COMPLETED_RESPONSE_CLASS = CompletedAudioToVideoResponse
|
|
27
|
+
|
|
28
|
+
def run(self, **params: Any) -> Any:
|
|
29
|
+
"""Create a task and poll until it completes."""
|
|
30
|
+
task = self.create(**params)
|
|
31
|
+
return self._poll_until_complete(lambda: self.get(task.id))
|
|
32
|
+
|
|
33
|
+
def create(self, **params: Any) -> Any:
|
|
34
|
+
"""Create an audio-to-video task and return immediately with an ``id``."""
|
|
35
|
+
compacted = self._compact_params(params)
|
|
36
|
+
self._validate_params(compacted)
|
|
37
|
+
return self._request("post", self.ENDPOINT, body=compacted)
|
|
38
|
+
|
|
39
|
+
def get(self, id: str) -> Any:
|
|
40
|
+
"""Fetch the current status of an audio-to-video task."""
|
|
41
|
+
return self._request("get", f"{self.ENDPOINT}/{id}")
|
|
42
|
+
|
|
43
|
+
def _validate_params(self, params: Dict[str, Any]) -> None:
|
|
44
|
+
model = params.get("model")
|
|
45
|
+
if not model:
|
|
46
|
+
raise ValidationError("model is required")
|
|
47
|
+
if model not in MODELS:
|
|
48
|
+
joined = ", ".join(MODELS)
|
|
49
|
+
raise ValidationError(f"Invalid model: {model}. Must be one of: {joined}")
|
|
50
|
+
|
|
51
|
+
self._validate_required(params, "source_image_url")
|
|
52
|
+
self._validate_required(params, "source_audio_url")
|
|
53
|
+
|
|
54
|
+
prompt = params.get("prompt")
|
|
55
|
+
if not (isinstance(prompt, str) and prompt != ""):
|
|
56
|
+
raise ValidationError("prompt is required")
|
|
57
|
+
if len(prompt) > PROMPT_MAX_LENGTH:
|
|
58
|
+
raise ValidationError(f"prompt must be at most {PROMPT_MAX_LENGTH} characters")
|
|
59
|
+
|
|
60
|
+
self._validate_optional(params, "output_resolution", RESOLUTIONS)
|
|
61
|
+
|
|
62
|
+
seed = params.get("seed")
|
|
63
|
+
if seed is None:
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
parsed = self._parse_integer(seed)
|
|
67
|
+
if parsed is not None and parsed in SEED_RANGE:
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
raise ValidationError(
|
|
71
|
+
f"seed must be an integer between {SEED_RANGE.start} and {SEED_RANGE.stop - 1}"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def _validate_required(params: Dict[str, Any], key: str) -> None:
|
|
76
|
+
value = params.get(key)
|
|
77
|
+
present = (value != "") if isinstance(value, str) else (value is not None)
|
|
78
|
+
if not present:
|
|
79
|
+
raise ValidationError(f"{key} is required")
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def _parse_integer(value: Any) -> Any:
|
|
83
|
+
"""Mirror Ruby ``Integer(value, exception: false)``.
|
|
84
|
+
|
|
85
|
+
Accepts ints and integer-looking strings; rejects bools and anything
|
|
86
|
+
non-coercible by returning ``None``.
|
|
87
|
+
"""
|
|
88
|
+
if isinstance(value, bool):
|
|
89
|
+
return None
|
|
90
|
+
if isinstance(value, int):
|
|
91
|
+
return value
|
|
92
|
+
if isinstance(value, str):
|
|
93
|
+
try:
|
|
94
|
+
return int(value.strip(), 10)
|
|
95
|
+
except ValueError:
|
|
96
|
+
return None
|
|
97
|
+
return None
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""InfiniteTalk model lists, enums, and response models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from runapi.core import BaseModel, TaskResponse, optional, required
|
|
6
|
+
|
|
7
|
+
MODELS = ["infinitetalk-from-audio"]
|
|
8
|
+
RESOLUTIONS = ["480p", "720p"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Video(BaseModel):
|
|
12
|
+
url = optional(str)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AudioToVideoResponse(TaskResponse):
|
|
16
|
+
"""Response for an audio-to-video task."""
|
|
17
|
+
|
|
18
|
+
id = required(str)
|
|
19
|
+
status = optional(str, enum=lambda: TaskResponse.Status.ALL)
|
|
20
|
+
videos = optional([lambda: Video])
|
|
21
|
+
error = optional(str)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CompletedAudioToVideoResponse(AudioToVideoResponse):
|
|
25
|
+
"""Returned by ``audio_to_video.run()`` once polling observes completion.
|
|
26
|
+
|
|
27
|
+
``videos`` is required so callers never have to null-check it on success.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
videos = required([lambda: Video])
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from runapi.core import config
|
|
4
|
+
from runapi.core.errors import AuthenticationError, ValidationError
|
|
5
|
+
from runapi.infinitetalk import InfinitetalkClient
|
|
6
|
+
from runapi.infinitetalk.resources.audio_to_video import AudioToVideo
|
|
7
|
+
from runapi.infinitetalk.types import (
|
|
8
|
+
AudioToVideoResponse,
|
|
9
|
+
CompletedAudioToVideoResponse,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FakeHttp:
|
|
14
|
+
"""Records (method, path, body) and replays preset responses by call order."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, *responses):
|
|
17
|
+
self._responses = list(responses)
|
|
18
|
+
self.calls = []
|
|
19
|
+
|
|
20
|
+
def request(self, method, path, body=None, options=None):
|
|
21
|
+
self.calls.append((method, path, body))
|
|
22
|
+
if self._responses:
|
|
23
|
+
return self._responses.pop(0)
|
|
24
|
+
return {"id": "task_1", "status": "pending"}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture(autouse=True)
|
|
28
|
+
def reset_config(monkeypatch):
|
|
29
|
+
monkeypatch.delenv("RUNAPI_API_KEY", raising=False)
|
|
30
|
+
monkeypatch.setattr(config, "api_key", None)
|
|
31
|
+
yield
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
VALID_PARAMS = dict(
|
|
35
|
+
model="infinitetalk-from-audio",
|
|
36
|
+
source_image_url="https://example.com/face.jpg",
|
|
37
|
+
source_audio_url="https://example.com/voice.mp3",
|
|
38
|
+
prompt="A person speaking to the camera",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# --- authentication -------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_accepts_api_key_parameter():
|
|
46
|
+
assert isinstance(
|
|
47
|
+
InfinitetalkClient(api_key="param-key", http_client=FakeHttp()), InfinitetalkClient
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_falls_back_to_global(monkeypatch):
|
|
52
|
+
monkeypatch.setattr(config, "api_key", "global-key")
|
|
53
|
+
assert isinstance(InfinitetalkClient(http_client=FakeHttp()), InfinitetalkClient)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_falls_back_to_env(monkeypatch):
|
|
57
|
+
monkeypatch.setenv("RUNAPI_API_KEY", "env-key")
|
|
58
|
+
assert isinstance(InfinitetalkClient(http_client=FakeHttp()), InfinitetalkClient)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_raises_without_api_key():
|
|
62
|
+
with pytest.raises(AuthenticationError, match="API key is required"):
|
|
63
|
+
InfinitetalkClient()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# --- transport injection / accessors --------------------------------------
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_uses_injected_http_client():
|
|
70
|
+
fake = FakeHttp()
|
|
71
|
+
client = InfinitetalkClient(api_key="k", http_client=fake)
|
|
72
|
+
assert client.audio_to_video._http is fake
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_exposes_resource_accessors():
|
|
76
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
77
|
+
assert isinstance(client.audio_to_video, AudioToVideo)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# --- request shapes -------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_create_posts_compacted_body():
|
|
84
|
+
fake = FakeHttp({"id": "t1", "status": "pending"})
|
|
85
|
+
client = InfinitetalkClient(api_key="k", http_client=fake)
|
|
86
|
+
result = client.audio_to_video.create(
|
|
87
|
+
**VALID_PARAMS,
|
|
88
|
+
output_resolution="720p",
|
|
89
|
+
seed=None,
|
|
90
|
+
)
|
|
91
|
+
assert fake.calls == [
|
|
92
|
+
(
|
|
93
|
+
"post",
|
|
94
|
+
"/api/v1/infinitetalk/audio_to_video",
|
|
95
|
+
{
|
|
96
|
+
"model": "infinitetalk-from-audio",
|
|
97
|
+
"source_image_url": "https://example.com/face.jpg",
|
|
98
|
+
"source_audio_url": "https://example.com/voice.mp3",
|
|
99
|
+
"prompt": "A person speaking to the camera",
|
|
100
|
+
"output_resolution": "720p",
|
|
101
|
+
},
|
|
102
|
+
),
|
|
103
|
+
]
|
|
104
|
+
assert isinstance(result, AudioToVideoResponse)
|
|
105
|
+
assert result.id == "t1"
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_get_fetches_by_id():
|
|
109
|
+
fake = FakeHttp({"id": "t1", "status": "processing"})
|
|
110
|
+
client = InfinitetalkClient(api_key="k", http_client=fake)
|
|
111
|
+
client.audio_to_video.get("t1")
|
|
112
|
+
assert fake.calls == [("get", "/api/v1/infinitetalk/audio_to_video/t1", None)]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_run_polls_and_narrows_completed_type():
|
|
116
|
+
fake = FakeHttp(
|
|
117
|
+
{"id": "t1", "status": "pending"},
|
|
118
|
+
{"id": "t1", "status": "completed", "videos": [{"url": "https://x/y.mp4"}]},
|
|
119
|
+
)
|
|
120
|
+
client = InfinitetalkClient(api_key="k", http_client=fake)
|
|
121
|
+
result = client.audio_to_video.run(**VALID_PARAMS)
|
|
122
|
+
|
|
123
|
+
assert isinstance(result, CompletedAudioToVideoResponse)
|
|
124
|
+
assert result.videos[0].url == "https://x/y.mp4"
|
|
125
|
+
assert [call[0] for call in fake.calls] == ["post", "get"]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# --- validation -----------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_create_requires_model():
|
|
132
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
133
|
+
params = {k: v for k, v in VALID_PARAMS.items() if k != "model"}
|
|
134
|
+
with pytest.raises(ValidationError, match="model is required"):
|
|
135
|
+
client.audio_to_video.create(**params)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_create_rejects_unknown_model():
|
|
139
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
140
|
+
params = {**VALID_PARAMS, "model": "not-a-model"}
|
|
141
|
+
with pytest.raises(ValidationError, match="Invalid model"):
|
|
142
|
+
client.audio_to_video.create(**params)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_create_requires_source_image_url():
|
|
146
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
147
|
+
params = {k: v for k, v in VALID_PARAMS.items() if k != "source_image_url"}
|
|
148
|
+
with pytest.raises(ValidationError, match="source_image_url is required"):
|
|
149
|
+
client.audio_to_video.create(**params)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def test_create_requires_source_audio_url():
|
|
153
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
154
|
+
params = {k: v for k, v in VALID_PARAMS.items() if k != "source_audio_url"}
|
|
155
|
+
with pytest.raises(ValidationError, match="source_audio_url is required"):
|
|
156
|
+
client.audio_to_video.create(**params)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_create_requires_prompt():
|
|
160
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
161
|
+
params = {k: v for k, v in VALID_PARAMS.items() if k != "prompt"}
|
|
162
|
+
with pytest.raises(ValidationError, match="prompt is required"):
|
|
163
|
+
client.audio_to_video.create(**params)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_create_rejects_overlong_prompt():
|
|
167
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
168
|
+
params = {**VALID_PARAMS, "prompt": "x" * 5001}
|
|
169
|
+
with pytest.raises(ValidationError, match="prompt must be at most 5000 characters"):
|
|
170
|
+
client.audio_to_video.create(**params)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def test_create_rejects_invalid_resolution():
|
|
174
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
175
|
+
params = {**VALID_PARAMS, "output_resolution": "1080p"}
|
|
176
|
+
with pytest.raises(ValidationError, match="Invalid output_resolution"):
|
|
177
|
+
client.audio_to_video.create(**params)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def test_create_rejects_seed_below_range():
|
|
181
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
182
|
+
params = {**VALID_PARAMS, "seed": 9999}
|
|
183
|
+
with pytest.raises(
|
|
184
|
+
ValidationError, match="seed must be an integer between 10000 and 1000000"
|
|
185
|
+
):
|
|
186
|
+
client.audio_to_video.create(**params)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def test_create_rejects_seed_above_range():
|
|
190
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
191
|
+
params = {**VALID_PARAMS, "seed": 1_000_001}
|
|
192
|
+
with pytest.raises(
|
|
193
|
+
ValidationError, match="seed must be an integer between 10000 and 1000000"
|
|
194
|
+
):
|
|
195
|
+
client.audio_to_video.create(**params)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_create_rejects_non_integer_seed():
|
|
199
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
200
|
+
params = {**VALID_PARAMS, "seed": "not-a-number"}
|
|
201
|
+
with pytest.raises(
|
|
202
|
+
ValidationError, match="seed must be an integer between 10000 and 1000000"
|
|
203
|
+
):
|
|
204
|
+
client.audio_to_video.create(**params)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def test_create_rejects_bool_seed():
|
|
208
|
+
client = InfinitetalkClient(api_key="k", http_client=FakeHttp())
|
|
209
|
+
params = {**VALID_PARAMS, "seed": True}
|
|
210
|
+
with pytest.raises(
|
|
211
|
+
ValidationError, match="seed must be an integer between 10000 and 1000000"
|
|
212
|
+
):
|
|
213
|
+
client.audio_to_video.create(**params)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_create_accepts_seed_in_range():
|
|
217
|
+
fake = FakeHttp({"id": "t1", "status": "pending"})
|
|
218
|
+
client = InfinitetalkClient(api_key="k", http_client=fake)
|
|
219
|
+
client.audio_to_video.create(**VALID_PARAMS, seed=500_000)
|
|
220
|
+
assert fake.calls[0][2]["seed"] == 500_000
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def test_create_accepts_integer_string_seed():
|
|
224
|
+
fake = FakeHttp({"id": "t1", "status": "pending"})
|
|
225
|
+
client = InfinitetalkClient(api_key="k", http_client=fake)
|
|
226
|
+
client.audio_to_video.create(**VALID_PARAMS, seed="500000")
|
|
227
|
+
assert fake.calls[0][2]["seed"] == "500000"
|