Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions livekit-agents/livekit/agents/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,16 +1950,26 @@ async def simulate_job() -> None:

@app.command()
def download_files() -> None:
import warnings

c = AgentsConsole.get_instance()
c.enabled = True

_configure_logger(c, logging.DEBUG)

try:
# import_data = get_import_data(path=path)
# c.print(f"Importing from {import_data.module_data.extra_sys_path}")
# c.print(" ")
c.print(
"[yellow]`download-files` via the agent CLI is deprecated. "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the message in

"Use `python3 your_agent.py download-files` to download the models."
as well?

"Use `python -m livekit.agents.download` instead — it discovers installed "
"plugins without loading your agent code.[/yellow]"
)
warnings.warn(
"`download-files` via the agent CLI is deprecated. "
"Use `python -m livekit.agents.download` instead.",
DeprecationWarning,
stacklevel=2,
)

try:
for plugin in Plugin.registered_plugins:
logger.info(f"Downloading files for {plugin.package}")
plugin.download_files()
Expand Down
56 changes: 56 additions & 0 deletions livekit-agents/livekit/agents/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from __future__ import annotations

import importlib
import logging
import pkgutil
import sys

from .plugin import Plugin

logger = logging.getLogger("livekit.agents.download")


def _discover_and_import_plugins() -> list[str]:
try:
import livekit.plugins as ns
except ImportError:
logger.warning("no livekit.plugins namespace found — nothing to download")
return []

attempted: list[str] = []
for _finder, name, is_pkg in pkgutil.iter_modules(ns.__path__, prefix="livekit.plugins."):
if not is_pkg:
continue
attempted.append(name)
try:
importlib.import_module(name)
except Exception as e:
logger.warning("failed to import %s: %s", name, e)
return attempted


def main() -> int:
logging.basicConfig(level=logging.INFO, format="%(message)s")

attempted = _discover_and_import_plugins()
logger.info(
"discovered %d plugin package(s): %s",
len(attempted),
", ".join(attempted) if attempted else "(none)",
)

exit_code = 0
for plugin in Plugin.registered_plugins:
logger.info("downloading files for %s", plugin.package)
try:
plugin.download_files()
except Exception as e:
logger.error("failed downloading files for %s: %s", plugin.package, e)
exit_code = 1
else:
logger.info("finished downloading files for %s", plugin.package)
return exit_code


if __name__ == "__main__":
sys.exit(main())
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
See https://docs.livekit.io/agents/build/turns/turn-detector/ for more information.
"""

from livekit.agents import Plugin

from .base import EOUPlugin
from .english import _EUORunnerEn
from .multilingual import _EUORunnerMultilingual
from .version import __version__

__all__ = ["english", "multilingual", "__version__"]

Plugin.register_plugin(EOUPlugin(_EUORunnerEn))
Plugin.register_plugin(EOUPlugin(_EUORunnerMultilingual))
Comment thread
davidzhao marked this conversation as resolved.


# Cleanup docs of unexported modules
_module = dir()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from livekit.agents import Plugin
from livekit.agents.inference_runner import _InferenceRunner

from .base import EOUModelBase, EOUPlugin, _EUORunnerBase
from .base import EOUModelBase, _EUORunnerBase
from .models import EOUModelType


Expand Down Expand Up @@ -33,4 +32,3 @@ def _inference_method(self) -> str:


_InferenceRunner.register_runner(_EUORunnerEn)
Plugin.register_plugin(EOUPlugin(_EUORunnerEn))
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import aiohttp

from livekit.agents import LanguageCode, Plugin, get_job_context, llm, utils
from livekit.agents import LanguageCode, get_job_context, llm, utils
from livekit.agents.inference_runner import _InferenceRunner

from .base import MAX_HISTORY_TURNS, EOUModelBase, EOUPlugin, _EUORunnerBase
from .base import MAX_HISTORY_TURNS, EOUModelBase, _EUORunnerBase
from .log import logger
from .models import EOUModelType

Expand Down Expand Up @@ -114,4 +114,3 @@ def _remote_inference_url() -> str | None:

if not _remote_inference_url():
_InferenceRunner.register_runner(_EUORunnerMultilingual)
Plugin.register_plugin(EOUPlugin(_EUORunnerMultilingual))
19 changes: 17 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading