pydantic-ai-videogen 2.5.3__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.
- pydantic_ai_videogen-2.5.3/.gitignore +8 -0
- pydantic_ai_videogen-2.5.3/PKG-INFO +112 -0
- pydantic_ai_videogen-2.5.3/README.md +95 -0
- pydantic_ai_videogen-2.5.3/pyproject.toml +46 -0
- pydantic_ai_videogen-2.5.3/src/pydantic_ai_videogen/__init__.py +18 -0
- pydantic_ai_videogen-2.5.3/src/pydantic_ai_videogen/client.py +47 -0
- pydantic_ai_videogen-2.5.3/src/pydantic_ai_videogen/factory.py +47 -0
- pydantic_ai_videogen-2.5.3/src/pydantic_ai_videogen/operations.py +88 -0
- pydantic_ai_videogen-2.5.3/src/pydantic_ai_videogen/tools.py +1016 -0
- pydantic_ai_videogen-2.5.3/tests/test_tools.py +59 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pydantic-ai-videogen
|
|
3
|
+
Version: 2.5.3
|
|
4
|
+
Summary: Official Pydantic AI tools for the VideoGen API. Generate videos, images, voiceovers, sound effects, music, and avatars from any Pydantic AI agent.
|
|
5
|
+
Project-URL: Homepage, https://videogen.io
|
|
6
|
+
Project-URL: Documentation, https://github.com/video-gen/video-workflow-recipes/tree/main/integrations/pydantic-ai-videogen#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/video-gen/video-workflow-recipes
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: agents,ai,ai-video-generation,image-generation,pydantic,pydantic-ai,text-to-speech,text-to-video,tools,videogen
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: pydantic-ai-slim>=0.0.30
|
|
12
|
+
Requires-Dist: pydantic>=2.0.0
|
|
13
|
+
Requires-Dist: videogen>=2.5.3
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# pydantic-ai-videogen
|
|
19
|
+
|
|
20
|
+
Official [Pydantic AI](https://ai.pydantic.dev) tools for the [VideoGen API](https://docs.videogen.io). Give any Pydantic AI agent the ability to turn a script into a finished narrated video, plus generate standalone images, video clips, voiceovers, sound effects, music, and talking-head avatars.
|
|
21
|
+
|
|
22
|
+
Every tool wraps the official [`videogen`](https://pypi.org/project/videogen/) SDK and runs as the team that owns your API key.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install pydantic-ai-videogen
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Setup
|
|
31
|
+
|
|
32
|
+
Get an API key from [app.videogen.io/api](https://app.videogen.io/api) and set it as `VIDEOGEN_API_KEY`:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export VIDEOGEN_API_KEY="your_api_key"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from pydantic_ai import Agent
|
|
42
|
+
from pydantic_ai_videogen import create_videogen_tools
|
|
43
|
+
|
|
44
|
+
agent = Agent(
|
|
45
|
+
"openai:gpt-4o",
|
|
46
|
+
tools=create_videogen_tools(),
|
|
47
|
+
system_prompt="You produce short narrated videos with VideoGen when asked.",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
result = agent.run_sync(
|
|
51
|
+
"Make a short narrated video explaining why staying hydrated matters."
|
|
52
|
+
)
|
|
53
|
+
print(result.output)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
By default each tool blocks until the workflow or tool execution finishes and returns the completed result.
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from videogen import VideoGen
|
|
62
|
+
from pydantic_ai_videogen import create_videogen_tools
|
|
63
|
+
|
|
64
|
+
tools = create_videogen_tools(
|
|
65
|
+
# Provide a pre-configured client, or pass api_key / base_url, or rely on env.
|
|
66
|
+
client=VideoGen(api_key="your_api_key"),
|
|
67
|
+
|
|
68
|
+
# Return the run/execution id immediately instead of waiting.
|
|
69
|
+
wait=False,
|
|
70
|
+
|
|
71
|
+
# Only expose a subset of tools to the model.
|
|
72
|
+
include=["script_to_video", "generate_image", "text_to_speech"],
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
| Option | Default | Description |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `client` | — | A pre-configured `VideoGen` client. |
|
|
79
|
+
| `api_key` | `VIDEOGEN_API_KEY` | API key used to build a client when `client` is omitted. |
|
|
80
|
+
| `base_url` | `VIDEOGEN_BASE_URL` or production | Override the API base URL. |
|
|
81
|
+
| `wait` | `True` | Block until the operation finishes and return the result. |
|
|
82
|
+
| `poll_interval_ms` | SDK default | Poll interval while waiting. |
|
|
83
|
+
| `timeout_ms` | SDK default | Maximum time to wait before giving up. |
|
|
84
|
+
| `include` | all tools | Restrict the returned tool set to these tool names. |
|
|
85
|
+
|
|
86
|
+
## Tools
|
|
87
|
+
|
|
88
|
+
<!-- BEGIN GENERATED PYTHON AGENT TOOLS -->
|
|
89
|
+
- Workflows: `cancel_workflow_run`, `get_workflow_run`, `list_workflow_runs`, `prompt_to_video_clip`, `script_to_video`, `slideshow_to_video`, `storyboard_to_video`, `video_to_video`, `voiceover_to_video`.
|
|
90
|
+
- Media generation: `cancel_tool_execution`, `generate_avatar`, `generate_image`, `generate_motion_graphic`, `generate_music`, `generate_sound_effect`, `generate_video_clip`, `get_tool_execution`, `image_3d_effect`, `list_tool_executions`, `remove_image_background`, `remove_video_background`, `text_to_speech`, `upscale_image`, `upscale_video`, `vectorize_image`.
|
|
91
|
+
- Projects: `export_project`, `get_project`, `list_project_remix_actions`, `list_projects`, `remix_project`.
|
|
92
|
+
- Files: `get_file`, `list_files`, `upload_file`.
|
|
93
|
+
- Resources and account: `get_me`, `list_languages`, `list_tts_voices`.
|
|
94
|
+
|
|
95
|
+
Avatar generation and supported video workflows use reusable actor entities. Pass `actor_entity_id` and set `avatar_quality` to `LOW`, `STANDARD`, `HIGH`, or `MAX`. Narrator changes are passed in `remix_actions` as `CHANGE_NARRATOR` action dictionaries.
|
|
96
|
+
<!-- END GENERATED PYTHON AGENT TOOLS -->
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
- [Use with AI agents](https://docs.videogen.io/use-with-ai-agents)
|
|
101
|
+
- [MCP server](https://docs.videogen.io/libraries/mcp)
|
|
102
|
+
- [API reference](https://docs.videogen.io)
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
107
|
+
|
|
108
|
+
## Account and permissions
|
|
109
|
+
|
|
110
|
+
Generation and editing use your VideoGen account credits. Obtain user approval before invoking credit-consuming tools. Restrict the `include` list when an agent only needs read access. Keep API keys in server-side environment variables and out of shared transcripts.
|
|
111
|
+
|
|
112
|
+
[VideoGen](https://videogen.io/) · [MCP setup](https://videogen.io/videogen-mcp) · [Source](https://github.com/video-gen/video-workflow-recipes/tree/main/integrations/pydantic-ai-videogen)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# pydantic-ai-videogen
|
|
2
|
+
|
|
3
|
+
Official [Pydantic AI](https://ai.pydantic.dev) tools for the [VideoGen API](https://docs.videogen.io). Give any Pydantic AI agent the ability to turn a script into a finished narrated video, plus generate standalone images, video clips, voiceovers, sound effects, music, and talking-head avatars.
|
|
4
|
+
|
|
5
|
+
Every tool wraps the official [`videogen`](https://pypi.org/project/videogen/) SDK and runs as the team that owns your API key.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install pydantic-ai-videogen
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
Get an API key from [app.videogen.io/api](https://app.videogen.io/api) and set it as `VIDEOGEN_API_KEY`:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
export VIDEOGEN_API_KEY="your_api_key"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from pydantic_ai import Agent
|
|
25
|
+
from pydantic_ai_videogen import create_videogen_tools
|
|
26
|
+
|
|
27
|
+
agent = Agent(
|
|
28
|
+
"openai:gpt-4o",
|
|
29
|
+
tools=create_videogen_tools(),
|
|
30
|
+
system_prompt="You produce short narrated videos with VideoGen when asked.",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
result = agent.run_sync(
|
|
34
|
+
"Make a short narrated video explaining why staying hydrated matters."
|
|
35
|
+
)
|
|
36
|
+
print(result.output)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
By default each tool blocks until the workflow or tool execution finishes and returns the completed result.
|
|
40
|
+
|
|
41
|
+
## Options
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from videogen import VideoGen
|
|
45
|
+
from pydantic_ai_videogen import create_videogen_tools
|
|
46
|
+
|
|
47
|
+
tools = create_videogen_tools(
|
|
48
|
+
# Provide a pre-configured client, or pass api_key / base_url, or rely on env.
|
|
49
|
+
client=VideoGen(api_key="your_api_key"),
|
|
50
|
+
|
|
51
|
+
# Return the run/execution id immediately instead of waiting.
|
|
52
|
+
wait=False,
|
|
53
|
+
|
|
54
|
+
# Only expose a subset of tools to the model.
|
|
55
|
+
include=["script_to_video", "generate_image", "text_to_speech"],
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| Option | Default | Description |
|
|
60
|
+
| --- | --- | --- |
|
|
61
|
+
| `client` | — | A pre-configured `VideoGen` client. |
|
|
62
|
+
| `api_key` | `VIDEOGEN_API_KEY` | API key used to build a client when `client` is omitted. |
|
|
63
|
+
| `base_url` | `VIDEOGEN_BASE_URL` or production | Override the API base URL. |
|
|
64
|
+
| `wait` | `True` | Block until the operation finishes and return the result. |
|
|
65
|
+
| `poll_interval_ms` | SDK default | Poll interval while waiting. |
|
|
66
|
+
| `timeout_ms` | SDK default | Maximum time to wait before giving up. |
|
|
67
|
+
| `include` | all tools | Restrict the returned tool set to these tool names. |
|
|
68
|
+
|
|
69
|
+
## Tools
|
|
70
|
+
|
|
71
|
+
<!-- BEGIN GENERATED PYTHON AGENT TOOLS -->
|
|
72
|
+
- Workflows: `cancel_workflow_run`, `get_workflow_run`, `list_workflow_runs`, `prompt_to_video_clip`, `script_to_video`, `slideshow_to_video`, `storyboard_to_video`, `video_to_video`, `voiceover_to_video`.
|
|
73
|
+
- Media generation: `cancel_tool_execution`, `generate_avatar`, `generate_image`, `generate_motion_graphic`, `generate_music`, `generate_sound_effect`, `generate_video_clip`, `get_tool_execution`, `image_3d_effect`, `list_tool_executions`, `remove_image_background`, `remove_video_background`, `text_to_speech`, `upscale_image`, `upscale_video`, `vectorize_image`.
|
|
74
|
+
- Projects: `export_project`, `get_project`, `list_project_remix_actions`, `list_projects`, `remix_project`.
|
|
75
|
+
- Files: `get_file`, `list_files`, `upload_file`.
|
|
76
|
+
- Resources and account: `get_me`, `list_languages`, `list_tts_voices`.
|
|
77
|
+
|
|
78
|
+
Avatar generation and supported video workflows use reusable actor entities. Pass `actor_entity_id` and set `avatar_quality` to `LOW`, `STANDARD`, `HIGH`, or `MAX`. Narrator changes are passed in `remix_actions` as `CHANGE_NARRATOR` action dictionaries.
|
|
79
|
+
<!-- END GENERATED PYTHON AGENT TOOLS -->
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- [Use with AI agents](https://docs.videogen.io/use-with-ai-agents)
|
|
84
|
+
- [MCP server](https://docs.videogen.io/libraries/mcp)
|
|
85
|
+
- [API reference](https://docs.videogen.io)
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
MIT
|
|
90
|
+
|
|
91
|
+
## Account and permissions
|
|
92
|
+
|
|
93
|
+
Generation and editing use your VideoGen account credits. Obtain user approval before invoking credit-consuming tools. Restrict the `include` list when an agent only needs read access. Keep API keys in server-side environment variables and out of shared transcripts.
|
|
94
|
+
|
|
95
|
+
[VideoGen](https://videogen.io/) · [MCP setup](https://videogen.io/videogen-mcp) · [Source](https://github.com/video-gen/video-workflow-recipes/tree/main/integrations/pydantic-ai-videogen)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pydantic-ai-videogen"
|
|
7
|
+
version = "2.5.3"
|
|
8
|
+
description = "Official Pydantic AI tools for the VideoGen API. Generate videos, images, voiceovers, sound effects, music, and avatars from any Pydantic AI agent."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = [
|
|
13
|
+
"videogen",
|
|
14
|
+
"pydantic-ai",
|
|
15
|
+
"pydantic",
|
|
16
|
+
"ai",
|
|
17
|
+
"agents",
|
|
18
|
+
"tools",
|
|
19
|
+
"text-to-video",
|
|
20
|
+
"ai-video-generation",
|
|
21
|
+
"text-to-speech",
|
|
22
|
+
"image-generation",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
dependencies = [
|
|
26
|
+
"videogen>=2.5.3",
|
|
27
|
+
"pydantic-ai-slim>=0.0.30",
|
|
28
|
+
"pydantic>=2.0.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://videogen.io"
|
|
33
|
+
Documentation = "https://github.com/video-gen/video-workflow-recipes/tree/main/integrations/pydantic-ai-videogen#readme"
|
|
34
|
+
Repository = "https://github.com/video-gen/video-workflow-recipes"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/pydantic_ai_videogen"]
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
dev = ["pytest>=8.0.0"]
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
markers = [
|
|
44
|
+
"integration: live tests that call the VideoGen API (require VIDEOGEN_API_KEY)",
|
|
45
|
+
]
|
|
46
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Official Pydantic AI tools for the VideoGen API."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
from .client import resolve_client
|
|
6
|
+
from .factory import create_videogen_tools
|
|
7
|
+
from .operations import Controls
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Controls",
|
|
11
|
+
"create_videogen_tools",
|
|
12
|
+
"resolve_client",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
__version__ = version("pydantic-ai-videogen")
|
|
17
|
+
except PackageNotFoundError:
|
|
18
|
+
__version__ = "0.0.0"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# AUTO-GENERATED from api/integrations/python-agent-templates/client.py. DO NOT EDIT.
|
|
2
|
+
"""Client resolution for the VideoGen Pydantic AI integration."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from videogen import VideoGen
|
|
10
|
+
|
|
11
|
+
_DEFAULT_BASE_URL = "https://api.videogen.io"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def resolve_client(
|
|
15
|
+
client: Optional[VideoGen] = None,
|
|
16
|
+
*,
|
|
17
|
+
api_key: Optional[str] = None,
|
|
18
|
+
base_url: Optional[str] = None,
|
|
19
|
+
) -> VideoGen:
|
|
20
|
+
"""Resolve a VideoGen client from an explicit client, an explicit key, or the environment.
|
|
21
|
+
|
|
22
|
+
Every tool call is authenticated as the team that owns the key.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
client: A pre-configured ``VideoGen`` client. Used as-is when provided.
|
|
26
|
+
api_key: API key. Falls back to the ``VIDEOGEN_API_KEY`` environment variable.
|
|
27
|
+
base_url: API base URL. Falls back to ``VIDEOGEN_BASE_URL``, then production.
|
|
28
|
+
"""
|
|
29
|
+
if client is not None:
|
|
30
|
+
return client
|
|
31
|
+
|
|
32
|
+
resolved_key = api_key or os.environ.get("VIDEOGEN_API_KEY")
|
|
33
|
+
|
|
34
|
+
if resolved_key is None or resolved_key.strip() == "":
|
|
35
|
+
raise ValueError(
|
|
36
|
+
"No VideoGen API key found. Pass `client` or `api_key`, or set the "
|
|
37
|
+
"VIDEOGEN_API_KEY environment variable. Create a key at "
|
|
38
|
+
"https://app.videogen.io/api."
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
resolved_base_url = base_url or os.environ.get("VIDEOGEN_BASE_URL") or _DEFAULT_BASE_URL
|
|
42
|
+
|
|
43
|
+
return VideoGen(
|
|
44
|
+
api_key=resolved_key.strip(),
|
|
45
|
+
base_url=resolved_base_url,
|
|
46
|
+
client_id="pydantic-ai",
|
|
47
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Factory for the VideoGen Pydantic AI integration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Iterable, List, Optional
|
|
6
|
+
|
|
7
|
+
from pydantic_ai import Tool
|
|
8
|
+
|
|
9
|
+
from videogen import VideoGen
|
|
10
|
+
|
|
11
|
+
from .client import resolve_client
|
|
12
|
+
from .operations import Controls
|
|
13
|
+
from .tools import build_videogen_tools
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def create_videogen_tools(
|
|
17
|
+
client: Optional[VideoGen] = None,
|
|
18
|
+
*,
|
|
19
|
+
api_key: Optional[str] = None,
|
|
20
|
+
base_url: Optional[str] = None,
|
|
21
|
+
wait: bool = True,
|
|
22
|
+
poll_interval_ms: Optional[int] = None,
|
|
23
|
+
timeout_ms: Optional[int] = None,
|
|
24
|
+
include: Optional[Iterable[str]] = None,
|
|
25
|
+
) -> List[Tool]:
|
|
26
|
+
"""Build VideoGen tools in Pydantic AI format, ready to pass to any Pydantic AI ``Agent``.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
client: A pre-configured ``VideoGen`` client. When omitted, one is built
|
|
30
|
+
from ``api_key`` / ``base_url`` or the ``VIDEOGEN_API_KEY`` environment variable.
|
|
31
|
+
wait: When True (default), tools block until the workflow run or tool execution
|
|
32
|
+
finishes and return the completed result. Set False to return immediately
|
|
33
|
+
with the run/execution id for the caller to poll.
|
|
34
|
+
poll_interval_ms: Poll interval while waiting. Defaults to the SDK's default.
|
|
35
|
+
timeout_ms: Maximum time to wait before giving up. Defaults to the SDK's default.
|
|
36
|
+
include: Restrict the returned tool set to these tool names. Defaults to all tools.
|
|
37
|
+
"""
|
|
38
|
+
resolved_client = resolve_client(client, api_key=api_key, base_url=base_url)
|
|
39
|
+
controls = Controls(wait=wait, poll_interval_ms=poll_interval_ms, timeout_ms=timeout_ms)
|
|
40
|
+
|
|
41
|
+
tools = build_videogen_tools(resolved_client, controls)
|
|
42
|
+
|
|
43
|
+
if include is None:
|
|
44
|
+
return tools
|
|
45
|
+
|
|
46
|
+
included = set(include)
|
|
47
|
+
return [tool for tool in tools if tool.name in included]
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# AUTO-GENERATED from api/integrations/python-agent-templates/operations.py. DO NOT EDIT.
|
|
2
|
+
"""Shared helpers for starting and polling VideoGen operations."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any, Callable, Dict, Optional
|
|
8
|
+
|
|
9
|
+
from videogen import VideoGen
|
|
10
|
+
from videogen.poll_executed_tool import poll_executed_tool
|
|
11
|
+
from videogen.poll_project_export import poll_project_export
|
|
12
|
+
from videogen.poll_workflow_run import poll_workflow_run
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class Controls:
|
|
17
|
+
"""How the tools handle asynchronous VideoGen operations."""
|
|
18
|
+
|
|
19
|
+
wait: bool = True
|
|
20
|
+
poll_interval_ms: Optional[int] = None
|
|
21
|
+
timeout_ms: Optional[int] = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def to_dict(obj: Any) -> Any:
|
|
25
|
+
"""Convert an SDK response model into a plain, JSON-serializable structure."""
|
|
26
|
+
model_dump = getattr(obj, "model_dump", None)
|
|
27
|
+
if callable(model_dump):
|
|
28
|
+
return model_dump(mode="json")
|
|
29
|
+
return obj
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def drop_none(values: Dict[str, Any]) -> Dict[str, Any]:
|
|
33
|
+
"""Drop ``None``-valued keys so the SDK applies its own defaults."""
|
|
34
|
+
return {key: value for key, value in values.items() if value is not None}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _poll_kwargs(controls: Controls) -> Dict[str, int]:
|
|
38
|
+
kwargs: Dict[str, int] = {}
|
|
39
|
+
if controls.poll_interval_ms is not None:
|
|
40
|
+
kwargs["poll_interval_ms"] = controls.poll_interval_ms
|
|
41
|
+
if controls.timeout_ms is not None:
|
|
42
|
+
kwargs["timeout_ms"] = controls.timeout_ms
|
|
43
|
+
return kwargs
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def run_workflow(
|
|
47
|
+
client: VideoGen,
|
|
48
|
+
controls: Controls,
|
|
49
|
+
start: Callable[[], Any],
|
|
50
|
+
) -> Any:
|
|
51
|
+
"""Start a workflow and, unless ``wait`` is False, poll it to a terminal state."""
|
|
52
|
+
started = start()
|
|
53
|
+
if not controls.wait:
|
|
54
|
+
return to_dict(started)
|
|
55
|
+
|
|
56
|
+
run = poll_workflow_run(client, started["workflowRunId"], **_poll_kwargs(controls))
|
|
57
|
+
return to_dict(run)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def run_tool(
|
|
61
|
+
client: VideoGen,
|
|
62
|
+
controls: Controls,
|
|
63
|
+
start: Callable[[], Any],
|
|
64
|
+
) -> Any:
|
|
65
|
+
"""Start a media tool execution and, unless ``wait`` is False, poll it to a terminal state."""
|
|
66
|
+
started = start()
|
|
67
|
+
if not controls.wait:
|
|
68
|
+
return to_dict(started)
|
|
69
|
+
|
|
70
|
+
execution = poll_executed_tool(client, started["toolExecutionId"], **_poll_kwargs(controls))
|
|
71
|
+
return to_dict(execution)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def run_export(
|
|
75
|
+
client: VideoGen,
|
|
76
|
+
controls: Controls,
|
|
77
|
+
project_id: str,
|
|
78
|
+
start: Callable[[], Any],
|
|
79
|
+
) -> Any:
|
|
80
|
+
"""Start a project export and, unless ``wait`` is False, poll until the download URL is ready."""
|
|
81
|
+
started = start()
|
|
82
|
+
if not controls.wait:
|
|
83
|
+
return to_dict(started)
|
|
84
|
+
|
|
85
|
+
project_export = poll_project_export(
|
|
86
|
+
client, project_id, started["exportId"], **_poll_kwargs(controls)
|
|
87
|
+
)
|
|
88
|
+
return to_dict(project_export)
|