langchain-videogen 2.5.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.
- langchain_videogen-2.5.0/.gitignore +5 -0
- langchain_videogen-2.5.0/LICENSE +9 -0
- langchain_videogen-2.5.0/PKG-INFO +118 -0
- langchain_videogen-2.5.0/README.md +100 -0
- langchain_videogen-2.5.0/pyproject.toml +46 -0
- langchain_videogen-2.5.0/src/langchain_videogen/__init__.py +19 -0
- langchain_videogen-2.5.0/src/langchain_videogen/client.py +47 -0
- langchain_videogen-2.5.0/src/langchain_videogen/operations.py +88 -0
- langchain_videogen-2.5.0/src/langchain_videogen/toolkit.py +87 -0
- langchain_videogen-2.5.0/src/langchain_videogen/tools.py +1018 -0
- langchain_videogen-2.5.0/tests/test_tools.py +59 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VideoGen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-videogen
|
|
3
|
+
Version: 2.5.0
|
|
4
|
+
Summary: Official LangChain tools for the VideoGen API. Generate videos, images, voiceovers, sound effects, music, and avatars from any LangChain or LangGraph agent.
|
|
5
|
+
Project-URL: Homepage, https://videogen.io
|
|
6
|
+
Project-URL: Documentation, https://github.com/video-gen/langchain-videogen#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/video-gen/langchain-videogen
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agents,ai,ai-video-generation,image-generation,langchain,langgraph,text-to-speech,text-to-video,tools,videogen
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
13
|
+
Requires-Dist: pydantic>=2.0.0
|
|
14
|
+
Requires-Dist: videogen>=2.5.0
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# langchain-videogen
|
|
20
|
+
|
|
21
|
+
Official [LangChain](https://python.langchain.com) tools for the [VideoGen API](https://docs.videogen.io). Give any LangChain or LangGraph 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.
|
|
22
|
+
|
|
23
|
+
Every tool wraps the official [`videogen`](https://pypi.org/project/videogen/) SDK and runs as the team that owns your API key.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install langchain-videogen
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Setup
|
|
32
|
+
|
|
33
|
+
Get an API key from [app.videogen.io/api](https://app.videogen.io/api) and set it as `VIDEOGEN_API_KEY`:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
export VIDEOGEN_API_KEY="your_api_key"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from langchain.chat_models import init_chat_model
|
|
43
|
+
from langgraph.prebuilt import create_react_agent
|
|
44
|
+
from langchain_videogen import create_videogen_tools
|
|
45
|
+
|
|
46
|
+
tools = create_videogen_tools()
|
|
47
|
+
|
|
48
|
+
agent = create_react_agent(init_chat_model("openai:gpt-4o"), tools)
|
|
49
|
+
|
|
50
|
+
result = agent.invoke(
|
|
51
|
+
{"messages": [{"role": "user", "content": "Make a short narrated video about why hydration matters."}]}
|
|
52
|
+
)
|
|
53
|
+
print(result["messages"][-1].content)
|
|
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 langchain_videogen import create_videogen_tools, VideoGenToolkit
|
|
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
|
+
# Or use the toolkit:
|
|
76
|
+
toolkit = VideoGenToolkit.from_client()
|
|
77
|
+
tools = toolkit.get_tools()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Option | Default | Description |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| `client` | — | A pre-configured `VideoGen` client. |
|
|
83
|
+
| `api_key` | `VIDEOGEN_API_KEY` | API key used to build a client when `client` is omitted. |
|
|
84
|
+
| `base_url` | `VIDEOGEN_BASE_URL` or production | Override the API base URL. |
|
|
85
|
+
| `wait` | `True` | Block until the operation finishes and return the result. |
|
|
86
|
+
| `poll_interval_ms` | SDK default | Poll interval while waiting. |
|
|
87
|
+
| `timeout_ms` | SDK default | Maximum time to wait before giving up. |
|
|
88
|
+
| `include` | all tools | Restrict the returned tool set to these tool names. |
|
|
89
|
+
|
|
90
|
+
## Tools
|
|
91
|
+
|
|
92
|
+
<!-- BEGIN GENERATED PYTHON AGENT TOOLS -->
|
|
93
|
+
- 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`.
|
|
94
|
+
- 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`.
|
|
95
|
+
- Projects: `export_project`, `get_project`, `list_project_remix_actions`, `list_projects`, `remix_project`.
|
|
96
|
+
- Files: `get_file`, `list_files`, `upload_file`.
|
|
97
|
+
- Resources and account: `get_me`, `list_languages`, `list_tts_voices`.
|
|
98
|
+
|
|
99
|
+
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.
|
|
100
|
+
<!-- END GENERATED PYTHON AGENT TOOLS -->
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
- [Use with AI agents](https://docs.videogen.io/use-with-ai-agents)
|
|
105
|
+
- [MCP server](https://docs.videogen.io/libraries/mcp)
|
|
106
|
+
- [API reference](https://docs.videogen.io)
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
111
|
+
|
|
112
|
+
## Account and tool permissions
|
|
113
|
+
|
|
114
|
+
Generation uses your VideoGen account credits. Obtain user approval before invoking generation, editing or export tools. Start with a restricted `include` list when an agent only needs read access. File upload tools send the selected file to VideoGen; keep API keys in server-side environment variables and never place them in shared agent transcripts.
|
|
115
|
+
|
|
116
|
+
For a credential-free smoke check, build the tools with a synthetic key without invoking them. The package tests mock or avoid external calls; they do not prove paid generation.
|
|
117
|
+
|
|
118
|
+
[VideoGen](https://videogen.io/) · [MCP setup](https://videogen.io/videogen-mcp)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# langchain-videogen
|
|
2
|
+
|
|
3
|
+
Official [LangChain](https://python.langchain.com) tools for the [VideoGen API](https://docs.videogen.io). Give any LangChain or LangGraph 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 langchain-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 langchain.chat_models import init_chat_model
|
|
25
|
+
from langgraph.prebuilt import create_react_agent
|
|
26
|
+
from langchain_videogen import create_videogen_tools
|
|
27
|
+
|
|
28
|
+
tools = create_videogen_tools()
|
|
29
|
+
|
|
30
|
+
agent = create_react_agent(init_chat_model("openai:gpt-4o"), tools)
|
|
31
|
+
|
|
32
|
+
result = agent.invoke(
|
|
33
|
+
{"messages": [{"role": "user", "content": "Make a short narrated video about why hydration matters."}]}
|
|
34
|
+
)
|
|
35
|
+
print(result["messages"][-1].content)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
By default each tool blocks until the workflow or tool execution finishes and returns the completed result.
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from videogen import VideoGen
|
|
44
|
+
from langchain_videogen import create_videogen_tools, VideoGenToolkit
|
|
45
|
+
|
|
46
|
+
tools = create_videogen_tools(
|
|
47
|
+
# Provide a pre-configured client, or pass api_key / base_url, or rely on env.
|
|
48
|
+
client=VideoGen(api_key="your_api_key"),
|
|
49
|
+
|
|
50
|
+
# Return the run/execution id immediately instead of waiting.
|
|
51
|
+
wait=False,
|
|
52
|
+
|
|
53
|
+
# Only expose a subset of tools to the model.
|
|
54
|
+
include=["script_to_video", "generate_image", "text_to_speech"],
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Or use the toolkit:
|
|
58
|
+
toolkit = VideoGenToolkit.from_client()
|
|
59
|
+
tools = toolkit.get_tools()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
| Option | Default | Description |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| `client` | — | A pre-configured `VideoGen` client. |
|
|
65
|
+
| `api_key` | `VIDEOGEN_API_KEY` | API key used to build a client when `client` is omitted. |
|
|
66
|
+
| `base_url` | `VIDEOGEN_BASE_URL` or production | Override the API base URL. |
|
|
67
|
+
| `wait` | `True` | Block until the operation finishes and return the result. |
|
|
68
|
+
| `poll_interval_ms` | SDK default | Poll interval while waiting. |
|
|
69
|
+
| `timeout_ms` | SDK default | Maximum time to wait before giving up. |
|
|
70
|
+
| `include` | all tools | Restrict the returned tool set to these tool names. |
|
|
71
|
+
|
|
72
|
+
## Tools
|
|
73
|
+
|
|
74
|
+
<!-- BEGIN GENERATED PYTHON AGENT TOOLS -->
|
|
75
|
+
- 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`.
|
|
76
|
+
- 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`.
|
|
77
|
+
- Projects: `export_project`, `get_project`, `list_project_remix_actions`, `list_projects`, `remix_project`.
|
|
78
|
+
- Files: `get_file`, `list_files`, `upload_file`.
|
|
79
|
+
- Resources and account: `get_me`, `list_languages`, `list_tts_voices`.
|
|
80
|
+
|
|
81
|
+
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.
|
|
82
|
+
<!-- END GENERATED PYTHON AGENT TOOLS -->
|
|
83
|
+
|
|
84
|
+
## Documentation
|
|
85
|
+
|
|
86
|
+
- [Use with AI agents](https://docs.videogen.io/use-with-ai-agents)
|
|
87
|
+
- [MCP server](https://docs.videogen.io/libraries/mcp)
|
|
88
|
+
- [API reference](https://docs.videogen.io)
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
93
|
+
|
|
94
|
+
## Account and tool permissions
|
|
95
|
+
|
|
96
|
+
Generation uses your VideoGen account credits. Obtain user approval before invoking generation, editing or export tools. Start with a restricted `include` list when an agent only needs read access. File upload tools send the selected file to VideoGen; keep API keys in server-side environment variables and never place them in shared agent transcripts.
|
|
97
|
+
|
|
98
|
+
For a credential-free smoke check, build the tools with a synthetic key without invoking them. The package tests mock or avoid external calls; they do not prove paid generation.
|
|
99
|
+
|
|
100
|
+
[VideoGen](https://videogen.io/) · [MCP setup](https://videogen.io/videogen-mcp)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langchain-videogen"
|
|
7
|
+
version = "2.5.0"
|
|
8
|
+
description = "Official LangChain tools for the VideoGen API. Generate videos, images, voiceovers, sound effects, music, and avatars from any LangChain or LangGraph agent."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = [
|
|
13
|
+
"videogen",
|
|
14
|
+
"langchain",
|
|
15
|
+
"langgraph",
|
|
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.0",
|
|
27
|
+
"langchain-core>=0.3.0",
|
|
28
|
+
"pydantic>=2.0.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://videogen.io"
|
|
33
|
+
Documentation = "https://github.com/video-gen/langchain-videogen#readme"
|
|
34
|
+
Repository = "https://github.com/video-gen/langchain-videogen"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/langchain_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,19 @@
|
|
|
1
|
+
"""Official LangChain tools for the VideoGen API."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
from .client import resolve_client
|
|
6
|
+
from .operations import Controls
|
|
7
|
+
from .toolkit import VideoGenToolkit, create_videogen_tools
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Controls",
|
|
11
|
+
"VideoGenToolkit",
|
|
12
|
+
"create_videogen_tools",
|
|
13
|
+
"resolve_client",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
__version__ = version("langchain-videogen")
|
|
18
|
+
except PackageNotFoundError:
|
|
19
|
+
__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 LangChain 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="langchain",
|
|
47
|
+
)
|
|
@@ -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)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Factory and toolkit for the VideoGen LangChain integration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Iterable, List, Optional
|
|
6
|
+
|
|
7
|
+
from langchain_core.tools import BaseTool, BaseToolkit
|
|
8
|
+
from pydantic import ConfigDict, Field
|
|
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[BaseTool]:
|
|
26
|
+
"""Build VideoGen tools in LangChain format, ready to bind to any LangChain or LangGraph 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]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class VideoGenToolkit(BaseToolkit):
|
|
51
|
+
"""A LangChain toolkit exposing the VideoGen tools.
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
>>> toolkit = VideoGenToolkit.from_client()
|
|
55
|
+
>>> tools = toolkit.get_tools()
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
59
|
+
|
|
60
|
+
videogen_tools: List[BaseTool] = Field(default_factory=list)
|
|
61
|
+
|
|
62
|
+
def get_tools(self) -> List[BaseTool]:
|
|
63
|
+
return self.videogen_tools
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def from_client(
|
|
67
|
+
cls,
|
|
68
|
+
client: Optional[VideoGen] = None,
|
|
69
|
+
*,
|
|
70
|
+
api_key: Optional[str] = None,
|
|
71
|
+
base_url: Optional[str] = None,
|
|
72
|
+
wait: bool = True,
|
|
73
|
+
poll_interval_ms: Optional[int] = None,
|
|
74
|
+
timeout_ms: Optional[int] = None,
|
|
75
|
+
include: Optional[Iterable[str]] = None,
|
|
76
|
+
) -> "VideoGenToolkit":
|
|
77
|
+
return cls(
|
|
78
|
+
videogen_tools=create_videogen_tools(
|
|
79
|
+
client,
|
|
80
|
+
api_key=api_key,
|
|
81
|
+
base_url=base_url,
|
|
82
|
+
wait=wait,
|
|
83
|
+
poll_interval_ms=poll_interval_ms,
|
|
84
|
+
timeout_ms=timeout_ms,
|
|
85
|
+
include=include,
|
|
86
|
+
)
|
|
87
|
+
)
|