livekit-plugins-runway 1.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.
- livekit_plugins_runway-1.5.3/.gitignore +179 -0
- livekit_plugins_runway-1.5.3/PKG-INFO +84 -0
- livekit_plugins_runway-1.5.3/README.md +62 -0
- livekit_plugins_runway-1.5.3/livekit/plugins/runway/__init__.py +36 -0
- livekit_plugins_runway-1.5.3/livekit/plugins/runway/avatar.py +179 -0
- livekit_plugins_runway-1.5.3/livekit/plugins/runway/log.py +3 -0
- livekit_plugins_runway-1.5.3/livekit/plugins/runway/py.typed +0 -0
- livekit_plugins_runway-1.5.3/livekit/plugins/runway/version.py +1 -0
- livekit_plugins_runway-1.5.3/pyproject.toml +42 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
**/.vscode
|
|
2
|
+
**/.DS_Store
|
|
3
|
+
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
share/python-wheels/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.installed.cfg
|
|
29
|
+
*.egg
|
|
30
|
+
MANIFEST
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# poetry
|
|
101
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
102
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
103
|
+
# commonly ignored for libraries.
|
|
104
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
105
|
+
#poetry.lock
|
|
106
|
+
|
|
107
|
+
# pdm
|
|
108
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
109
|
+
#pdm.lock
|
|
110
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
111
|
+
# in version control.
|
|
112
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
113
|
+
.pdm.toml
|
|
114
|
+
|
|
115
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
116
|
+
__pypackages__/
|
|
117
|
+
|
|
118
|
+
# Celery stuff
|
|
119
|
+
celerybeat-schedule
|
|
120
|
+
celerybeat.pid
|
|
121
|
+
|
|
122
|
+
# SageMath parsed files
|
|
123
|
+
*.sage.py
|
|
124
|
+
|
|
125
|
+
# Environments
|
|
126
|
+
.env
|
|
127
|
+
.venv
|
|
128
|
+
env/
|
|
129
|
+
venv/
|
|
130
|
+
ENV/
|
|
131
|
+
env.bak/
|
|
132
|
+
venv.bak/
|
|
133
|
+
|
|
134
|
+
# Spyder project settings
|
|
135
|
+
.spyderproject
|
|
136
|
+
.spyproject
|
|
137
|
+
|
|
138
|
+
# Rope project settings
|
|
139
|
+
.ropeproject
|
|
140
|
+
|
|
141
|
+
# mkdocs documentation
|
|
142
|
+
/site
|
|
143
|
+
|
|
144
|
+
# mypy
|
|
145
|
+
.mypy_cache/
|
|
146
|
+
.dmypy.json
|
|
147
|
+
dmypy.json
|
|
148
|
+
|
|
149
|
+
# trunk
|
|
150
|
+
.trunk/
|
|
151
|
+
|
|
152
|
+
# Pyre type checker
|
|
153
|
+
.pyre/
|
|
154
|
+
|
|
155
|
+
# pytype static type analyzer
|
|
156
|
+
.pytype/
|
|
157
|
+
|
|
158
|
+
# Cython debug symbols
|
|
159
|
+
cython_debug/
|
|
160
|
+
|
|
161
|
+
# PyCharm
|
|
162
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
163
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
164
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
165
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
166
|
+
.idea/
|
|
167
|
+
|
|
168
|
+
node_modules
|
|
169
|
+
|
|
170
|
+
credentials.json
|
|
171
|
+
pyrightconfig.json
|
|
172
|
+
docs/
|
|
173
|
+
|
|
174
|
+
# Database files
|
|
175
|
+
*.db
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
# Examples for development
|
|
179
|
+
examples/dev/*
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: livekit-plugins-runway
|
|
3
|
+
Version: 1.5.3
|
|
4
|
+
Summary: Agent Framework plugin for Runway Characters Avatar
|
|
5
|
+
Project-URL: Documentation, https://docs.livekit.io
|
|
6
|
+
Project-URL: Website, https://livekit.io/
|
|
7
|
+
Project-URL: Source, https://github.com/livekit/agents
|
|
8
|
+
Author-email: LiveKit <support@livekit.io>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Keywords: ai,audio,avatar,livekit,realtime,runway,video,voice
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
17
|
+
Classifier: Topic :: Multimedia :: Video
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10.0
|
|
20
|
+
Requires-Dist: livekit-agents>=1.5.3
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# livekit-plugins-runway
|
|
24
|
+
|
|
25
|
+
[LiveKit Agents](https://docs.livekit.io/agents/) plugin for [Runway Characters](https://dev.runwayml.com/) avatar integration.
|
|
26
|
+
|
|
27
|
+
Your LiveKit agent owns the full conversational AI pipeline (STT, LLM, TTS). Runway provides the visual layer — audio in, avatar video out.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install livekit-plugins-runway
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from livekit.agents import AgentSession, Agent, RoomOutputOptions
|
|
39
|
+
from livekit.plugins import runway
|
|
40
|
+
|
|
41
|
+
async def entrypoint(ctx):
|
|
42
|
+
session = AgentSession()
|
|
43
|
+
|
|
44
|
+
avatar = runway.AvatarSession(
|
|
45
|
+
avatar_id="your-custom-avatar-id",
|
|
46
|
+
# api_key defaults to RUNWAYML_API_SECRET env var
|
|
47
|
+
)
|
|
48
|
+
await avatar.start(session, room=ctx.room)
|
|
49
|
+
|
|
50
|
+
await session.start(
|
|
51
|
+
agent=Agent(instructions="Talk to me!"),
|
|
52
|
+
room=ctx.room,
|
|
53
|
+
room_output_options=RoomOutputOptions(audio_enabled=False),
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Using a preset avatar
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
avatar = runway.AvatarSession(
|
|
61
|
+
preset_id="runway-preset-slug",
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### With a session duration limit
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
avatar = runway.AvatarSession(
|
|
69
|
+
avatar_id="your-custom-avatar-id",
|
|
70
|
+
max_duration=300,
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
| Parameter | Env var | Description |
|
|
77
|
+
|-----------|---------|-------------|
|
|
78
|
+
| `api_key` | `RUNWAYML_API_SECRET` | Runway API key |
|
|
79
|
+
| `api_url` | `RUNWAYML_BASE_URL` | API base URL (default: `https://api.dev.runwayml.com`) |
|
|
80
|
+
| `avatar_id` | — | Custom avatar ID (mutually exclusive with `preset_id`) |
|
|
81
|
+
| `preset_id` | — | Preset avatar slug (mutually exclusive with `avatar_id`) |
|
|
82
|
+
| `max_duration` | — | Maximum session duration in seconds |
|
|
83
|
+
|
|
84
|
+
LiveKit credentials (`LIVEKIT_URL`, `LIVEKIT_API_KEY`, `LIVEKIT_API_SECRET`) are read from environment variables or can be passed to `avatar.start()`.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# livekit-plugins-runway
|
|
2
|
+
|
|
3
|
+
[LiveKit Agents](https://docs.livekit.io/agents/) plugin for [Runway Characters](https://dev.runwayml.com/) avatar integration.
|
|
4
|
+
|
|
5
|
+
Your LiveKit agent owns the full conversational AI pipeline (STT, LLM, TTS). Runway provides the visual layer — audio in, avatar video out.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install livekit-plugins-runway
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from livekit.agents import AgentSession, Agent, RoomOutputOptions
|
|
17
|
+
from livekit.plugins import runway
|
|
18
|
+
|
|
19
|
+
async def entrypoint(ctx):
|
|
20
|
+
session = AgentSession()
|
|
21
|
+
|
|
22
|
+
avatar = runway.AvatarSession(
|
|
23
|
+
avatar_id="your-custom-avatar-id",
|
|
24
|
+
# api_key defaults to RUNWAYML_API_SECRET env var
|
|
25
|
+
)
|
|
26
|
+
await avatar.start(session, room=ctx.room)
|
|
27
|
+
|
|
28
|
+
await session.start(
|
|
29
|
+
agent=Agent(instructions="Talk to me!"),
|
|
30
|
+
room=ctx.room,
|
|
31
|
+
room_output_options=RoomOutputOptions(audio_enabled=False),
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Using a preset avatar
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
avatar = runway.AvatarSession(
|
|
39
|
+
preset_id="runway-preset-slug",
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### With a session duration limit
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
avatar = runway.AvatarSession(
|
|
47
|
+
avatar_id="your-custom-avatar-id",
|
|
48
|
+
max_duration=300,
|
|
49
|
+
)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
| Parameter | Env var | Description |
|
|
55
|
+
|-----------|---------|-------------|
|
|
56
|
+
| `api_key` | `RUNWAYML_API_SECRET` | Runway API key |
|
|
57
|
+
| `api_url` | `RUNWAYML_BASE_URL` | API base URL (default: `https://api.dev.runwayml.com`) |
|
|
58
|
+
| `avatar_id` | — | Custom avatar ID (mutually exclusive with `preset_id`) |
|
|
59
|
+
| `preset_id` | — | Preset avatar slug (mutually exclusive with `avatar_id`) |
|
|
60
|
+
| `max_duration` | — | Maximum session duration in seconds |
|
|
61
|
+
|
|
62
|
+
LiveKit credentials (`LIVEKIT_URL`, `LIVEKIT_API_KEY`, `LIVEKIT_API_SECRET`) are read from environment variables or can be passed to `avatar.start()`.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright 2025 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Runway Characters avatar plugin for LiveKit Agents"""
|
|
16
|
+
|
|
17
|
+
from .avatar import AvatarSession, RunwayException
|
|
18
|
+
from .version import __version__
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"RunwayException",
|
|
22
|
+
"AvatarSession",
|
|
23
|
+
"__version__",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
from livekit.agents import Plugin
|
|
27
|
+
|
|
28
|
+
from .log import logger
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class RunwayPlugin(Plugin):
|
|
32
|
+
def __init__(self) -> None:
|
|
33
|
+
super().__init__(__name__, __version__, __package__, logger)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Plugin.register_plugin(RunwayPlugin())
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
import aiohttp
|
|
7
|
+
|
|
8
|
+
from livekit import api, rtc
|
|
9
|
+
from livekit.agents import (
|
|
10
|
+
DEFAULT_API_CONNECT_OPTIONS,
|
|
11
|
+
NOT_GIVEN,
|
|
12
|
+
AgentSession,
|
|
13
|
+
APIConnectionError,
|
|
14
|
+
APIConnectOptions,
|
|
15
|
+
APIStatusError,
|
|
16
|
+
NotGivenOr,
|
|
17
|
+
get_job_context,
|
|
18
|
+
utils,
|
|
19
|
+
)
|
|
20
|
+
from livekit.agents.voice.avatar import DataStreamAudioOutput
|
|
21
|
+
from livekit.agents.voice.room_io import ATTRIBUTE_PUBLISH_ON_BEHALF
|
|
22
|
+
|
|
23
|
+
from .log import logger
|
|
24
|
+
|
|
25
|
+
DEFAULT_API_URL = "https://api.dev.runwayml.com"
|
|
26
|
+
API_VERSION = "2024-11-06"
|
|
27
|
+
SAMPLE_RATE = 16000
|
|
28
|
+
_AVATAR_AGENT_IDENTITY = "runway-avatar-agent"
|
|
29
|
+
_AVATAR_AGENT_NAME = "runway-avatar-agent"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class RunwayException(Exception):
|
|
33
|
+
"""Exception for Runway errors"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AvatarSession:
|
|
37
|
+
"""A Runway Characters avatar session.
|
|
38
|
+
|
|
39
|
+
Creates a realtime session backed by Runway's avatar inference pipeline.
|
|
40
|
+
The customer's LiveKit agent owns the conversational AI stack (STT, LLM, TTS);
|
|
41
|
+
Runway provides the visual layer — audio in, avatar video out.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
*,
|
|
47
|
+
avatar_id: NotGivenOr[str | None] = NOT_GIVEN,
|
|
48
|
+
preset_id: NotGivenOr[str | None] = NOT_GIVEN,
|
|
49
|
+
max_duration: NotGivenOr[int] = NOT_GIVEN,
|
|
50
|
+
api_url: NotGivenOr[str] = NOT_GIVEN,
|
|
51
|
+
api_key: NotGivenOr[str] = NOT_GIVEN,
|
|
52
|
+
avatar_participant_identity: NotGivenOr[str] = NOT_GIVEN,
|
|
53
|
+
avatar_participant_name: NotGivenOr[str] = NOT_GIVEN,
|
|
54
|
+
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
|
55
|
+
) -> None:
|
|
56
|
+
if not avatar_id and not preset_id:
|
|
57
|
+
raise RunwayException("Either avatar_id or preset_id must be provided")
|
|
58
|
+
if avatar_id and preset_id:
|
|
59
|
+
raise RunwayException("Provide avatar_id or preset_id, not both")
|
|
60
|
+
|
|
61
|
+
if avatar_id:
|
|
62
|
+
self._avatar: dict[str, str] = {"type": "custom", "avatarId": str(avatar_id)}
|
|
63
|
+
else:
|
|
64
|
+
self._avatar = {"type": "runway-preset", "presetId": str(preset_id)}
|
|
65
|
+
self._max_duration = max_duration
|
|
66
|
+
|
|
67
|
+
self._api_url = api_url or os.getenv("RUNWAYML_BASE_URL", DEFAULT_API_URL)
|
|
68
|
+
self._api_key = api_key or os.getenv("RUNWAYML_API_SECRET")
|
|
69
|
+
if self._api_key is None:
|
|
70
|
+
raise RunwayException(
|
|
71
|
+
"api_key must be set either by passing it to AvatarSession or "
|
|
72
|
+
"by setting the RUNWAYML_API_SECRET environment variable"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
self._avatar_participant_identity = avatar_participant_identity or _AVATAR_AGENT_IDENTITY
|
|
76
|
+
self._avatar_participant_name = avatar_participant_name or _AVATAR_AGENT_NAME
|
|
77
|
+
self._http_session: aiohttp.ClientSession | None = None
|
|
78
|
+
self._conn_options = conn_options
|
|
79
|
+
|
|
80
|
+
def _ensure_http_session(self) -> aiohttp.ClientSession:
|
|
81
|
+
if self._http_session is None:
|
|
82
|
+
self._http_session = utils.http_context.http_session()
|
|
83
|
+
return self._http_session
|
|
84
|
+
|
|
85
|
+
async def start(
|
|
86
|
+
self,
|
|
87
|
+
agent_session: AgentSession,
|
|
88
|
+
room: rtc.Room,
|
|
89
|
+
*,
|
|
90
|
+
livekit_url: NotGivenOr[str] = NOT_GIVEN,
|
|
91
|
+
livekit_api_key: NotGivenOr[str] = NOT_GIVEN,
|
|
92
|
+
livekit_api_secret: NotGivenOr[str] = NOT_GIVEN,
|
|
93
|
+
) -> None:
|
|
94
|
+
livekit_url = livekit_url or (os.getenv("LIVEKIT_URL") or NOT_GIVEN)
|
|
95
|
+
livekit_api_key = livekit_api_key or (os.getenv("LIVEKIT_API_KEY") or NOT_GIVEN)
|
|
96
|
+
livekit_api_secret = livekit_api_secret or (os.getenv("LIVEKIT_API_SECRET") or NOT_GIVEN)
|
|
97
|
+
if not livekit_url or not livekit_api_key or not livekit_api_secret:
|
|
98
|
+
raise RunwayException(
|
|
99
|
+
"livekit_url, livekit_api_key, and livekit_api_secret must be set "
|
|
100
|
+
"by arguments or environment variables"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
job_ctx = get_job_context()
|
|
104
|
+
self._local_participant_identity = job_ctx.local_participant_identity
|
|
105
|
+
|
|
106
|
+
livekit_token = (
|
|
107
|
+
api.AccessToken(api_key=livekit_api_key, api_secret=livekit_api_secret)
|
|
108
|
+
.with_kind("agent")
|
|
109
|
+
.with_identity(self._avatar_participant_identity)
|
|
110
|
+
.with_name(self._avatar_participant_name)
|
|
111
|
+
.with_grants(api.VideoGrants(room_join=True, room=room.name))
|
|
112
|
+
.with_attributes({ATTRIBUTE_PUBLISH_ON_BEHALF: self._local_participant_identity})
|
|
113
|
+
.to_jwt()
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
logger.debug("starting Runway avatar session")
|
|
117
|
+
await self._create_session(livekit_url, livekit_token, room.name)
|
|
118
|
+
|
|
119
|
+
agent_session.output.audio = DataStreamAudioOutput(
|
|
120
|
+
room=room,
|
|
121
|
+
destination_identity=self._avatar_participant_identity,
|
|
122
|
+
wait_remote_track=rtc.TrackKind.KIND_VIDEO,
|
|
123
|
+
sample_rate=SAMPLE_RATE,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
async def _create_session(self, livekit_url: str, livekit_token: str, room_name: str) -> None:
|
|
127
|
+
assert self._api_key is not None
|
|
128
|
+
assert isinstance(self._api_url, str)
|
|
129
|
+
|
|
130
|
+
body: dict[str, object] = {
|
|
131
|
+
"model": "gwm1_avatars",
|
|
132
|
+
"avatar": self._avatar,
|
|
133
|
+
"livekit": {
|
|
134
|
+
"url": livekit_url,
|
|
135
|
+
"token": livekit_token,
|
|
136
|
+
"roomName": room_name,
|
|
137
|
+
"agentIdentity": self._local_participant_identity,
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if self._max_duration:
|
|
142
|
+
body["maxDuration"] = self._max_duration
|
|
143
|
+
|
|
144
|
+
for attempt in range(self._conn_options.max_retry):
|
|
145
|
+
try:
|
|
146
|
+
async with self._ensure_http_session().post(
|
|
147
|
+
f"{self._api_url}/v1/realtime_sessions",
|
|
148
|
+
headers={
|
|
149
|
+
"Authorization": f"Bearer {self._api_key}",
|
|
150
|
+
"X-Runway-Version": API_VERSION,
|
|
151
|
+
},
|
|
152
|
+
json=body,
|
|
153
|
+
timeout=aiohttp.ClientTimeout(sock_connect=self._conn_options.timeout),
|
|
154
|
+
) as response:
|
|
155
|
+
if not response.ok:
|
|
156
|
+
text = await response.text()
|
|
157
|
+
raise APIStatusError(
|
|
158
|
+
"Runway API returned an error",
|
|
159
|
+
status_code=response.status,
|
|
160
|
+
body=text,
|
|
161
|
+
)
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
except Exception as error:
|
|
165
|
+
if isinstance(error, APIStatusError):
|
|
166
|
+
raise
|
|
167
|
+
|
|
168
|
+
if isinstance(error, APIConnectionError):
|
|
169
|
+
logger.warning(
|
|
170
|
+
"failed to call Runway avatar API",
|
|
171
|
+
extra={"error": str(error)},
|
|
172
|
+
)
|
|
173
|
+
else:
|
|
174
|
+
logger.exception("failed to call Runway avatar API")
|
|
175
|
+
|
|
176
|
+
if attempt < self._conn_options.max_retry - 1:
|
|
177
|
+
await asyncio.sleep(self._conn_options.retry_interval)
|
|
178
|
+
|
|
179
|
+
raise APIConnectionError("Failed to start Runway Avatar Session after all retries")
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.5.3"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "livekit-plugins-runway"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Agent Framework plugin for Runway Characters Avatar"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.10.0"
|
|
12
|
+
authors = [{ name = "LiveKit", email = "support@livekit.io" }]
|
|
13
|
+
keywords = ["voice", "ai", "realtime", "audio", "video", "avatar", "livekit", "runway"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Topic :: Multimedia :: Sound/Audio",
|
|
18
|
+
"Topic :: Multimedia :: Video",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["livekit-agents>=1.5.3"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Documentation = "https://docs.livekit.io"
|
|
28
|
+
Website = "https://livekit.io/"
|
|
29
|
+
Source = "https://github.com/livekit/agents"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.version]
|
|
32
|
+
path = "livekit/plugins/runway/version.py"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["livekit"]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.sdist]
|
|
38
|
+
include = ["/livekit"]
|
|
39
|
+
|
|
40
|
+
[tool.uv]
|
|
41
|
+
exclude-newer = "7 days"
|
|
42
|
+
exclude-newer-package = { livekit-agents = "0 days" }
|