mirror of
https://github.com/langgenius/dify.git
synced 2026-05-24 02:47:53 +08:00
Co-authored-by: Copilot <copilot@github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""Small CLI for listing or copying Agenton examples."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
EXAMPLE_MODULES = (
|
|
"basics",
|
|
"pydantic_ai_bridge",
|
|
"session_snapshot",
|
|
)
|
|
|
|
|
|
def cli() -> None:
|
|
parser = argparse.ArgumentParser(
|
|
prog="agenton_examples",
|
|
description="List or copy Agenton examples.",
|
|
)
|
|
parser.add_argument("--copy-to", metavar="DEST", help="Copy example files to a new directory")
|
|
args = parser.parse_args()
|
|
|
|
examples_dir = Path(__file__).parent
|
|
if args.copy_to:
|
|
copy_to(examples_dir, Path(args.copy_to))
|
|
return
|
|
|
|
for module_name in EXAMPLE_MODULES:
|
|
print(f"python -m agenton_examples.{module_name}")
|
|
|
|
|
|
def copy_to(examples_dir: Path, destination: Path) -> None:
|
|
if destination.exists():
|
|
print(f'Error: destination path "{destination}" already exists', file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
destination.mkdir(parents=True)
|
|
copied = 0
|
|
for source in examples_dir.glob("*.py"):
|
|
if source.name == "__init__.py":
|
|
continue
|
|
shutil.copy2(source, destination / source.name)
|
|
copied += 1
|
|
print(f'Copied {copied} Agenton example files to "{destination}"')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
cli()
|