langchain-videogen 2.5.0__py3-none-any.whl
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/__init__.py +19 -0
- langchain_videogen/client.py +47 -0
- langchain_videogen/operations.py +88 -0
- langchain_videogen/toolkit.py +87 -0
- langchain_videogen/tools.py +1018 -0
- langchain_videogen-2.5.0.dist-info/METADATA +118 -0
- langchain_videogen-2.5.0.dist-info/RECORD +9 -0
- langchain_videogen-2.5.0.dist-info/WHEEL +4 -0
- langchain_videogen-2.5.0.dist-info/licenses/LICENSE +9 -0
|
@@ -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
|
+
)
|