langservehub template cli

This commit is contained in:
Erick Friis
2023-10-13 17:51:23 -07:00
parent 616cb855f8
commit afded44bba
2 changed files with 39 additions and 17 deletions

View File

@@ -76,6 +76,9 @@ def new(
use_poetry: Annotated[
Optional[bool], typer.Option(help="Specify whether to use Poetry or not.")
] = None,
template: Annotated[
Optional[str], typer.Argument(help="The template to use for the project.")
] = None,
) -> None:
"""Create a new project with LangChain."""
@@ -83,6 +86,16 @@ def new(
project_name_suggestion = project_directory_path.name.replace("-", "_")
project_name = _select_project_name(project_name_suggestion)
if template == "langservehub":
create(
project_directory,
project_name,
author_name,
author_email,
use_poetry,
template,
)
if not author_name:
author_name = typer.prompt("Author Name", default=get_git_user_name())

View File

@@ -4,7 +4,7 @@ import pathlib
import string
import subprocess
from pathlib import Path
from typing import List, Sequence
from typing import List, Sequence, Optional
import typer
@@ -22,9 +22,10 @@ def _create_project_dir(
project_name_identifier: str,
author_name: str,
author_email: str,
template: Optional[str] = None,
) -> None:
project_directory_path.mkdir(parents=True, exist_ok=True)
template_directories = _get_template_directories(use_poetry)
template_directories = _get_template_directories(use_poetry, template)
_check_conflicting_files(template_directories, project_directory_path)
_copy_template_files(
template_directories,
@@ -36,7 +37,9 @@ def _create_project_dir(
)
def _get_template_directories(use_poetry: bool) -> List[Path]:
def _get_template_directories(
use_poetry: bool, template: Optional[str] = None
) -> List[Path]:
"""Get the directories containing the templates.
Args:
@@ -44,6 +47,9 @@ def _get_template_directories(use_poetry: bool) -> List[Path]:
"""
template_parent_path = Path(__file__).parent / "templates"
if template:
return [template_parent_path / template]
template_directories = [template_parent_path / "repo"]
if use_poetry:
template_directories.append(template_parent_path / "poetry")
@@ -181,6 +187,7 @@ def create(
author_name: str,
author_email: str,
use_poetry: bool,
template: Optional[str] = None,
) -> None:
"""Create a new LangChain project.
@@ -196,20 +203,21 @@ def create(
project_name_identifier = project_name
resolved_path = project_directory_path.resolve()
if not typer.confirm(
f"\n"
f"Creating a new LangChain project 🦜️🔗\n"
f"Name: {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Path: {typer.style(resolved_path, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Project name: {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Author name: {typer.style(author_name, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Author email: {typer.style(author_email, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Use Poetry: {typer.style(str(use_poetry), fg=typer.colors.BRIGHT_CYAN)}\n"
"Continue?",
default=True,
):
typer.echo("Cancelled project creation. See you later! 👋")
raise typer.Exit(code=0)
if not template:
if not typer.confirm(
f"\n"
f"Creating a new LangChain project 🦜️🔗\n"
f"Name: {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Path: {typer.style(resolved_path, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Project name: {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Author name: {typer.style(author_name, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Author email: {typer.style(author_email, fg=typer.colors.BRIGHT_CYAN)}\n"
f"Use Poetry: {typer.style(str(use_poetry), fg=typer.colors.BRIGHT_CYAN)}\n"
"Continue?",
default=True,
):
typer.echo("Cancelled project creation. See you later! 👋")
raise typer.Exit(code=0)
_create_project_dir(
project_directory_path,
@@ -218,6 +226,7 @@ def create(
project_name_identifier,
author_name,
author_email,
template,
)
# TODO(Team): Add installation