Compare commits

...

8 Commits

Author SHA1 Message Date
Erick Friis
afded44bba langservehub template cli 2023-10-13 17:51:23 -07:00
Erick Friis
616cb855f8 link to git langserve instead 2023-10-13 17:42:35 -07:00
Erick Friis
2a7557d1e5 packages 2023-10-13 17:39:54 -07:00
Erick Friis
3ca10a99c7 more 2023-10-13 17:28:07 -07:00
Erick Friis
ae92a29973 fix 2023-10-13 17:20:47 -07:00
Erick Friis
5d3d51de5f fix commands 2023-10-13 17:14:35 -07:00
Erick Friis
0586e6950c wip 2023-10-13 17:12:47 -07:00
Erick Friis
ca87b29dfc initial package 2023-10-13 16:32:22 -07:00
9 changed files with 1641 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

View File

@@ -0,0 +1,11 @@
from fastapi import FastAPI
from langserve import add_package_routes
app = FastAPI()
add_package_routes(app, "packages")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
[tool.poetry]
name = "langservehub-template"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
sse-starlette = "^1.6.5"
langserve = {git = "https://github.com/langchain-ai/langserve", rev = "erick/langservehub"}
tomli-w = "^1.0.0"
uvicorn = "^0.23.2"
fastapi = "^0.103.2"
[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.1"
uvicorn = "^0.23.2"
pygithub = "^2.1.1"
[tool.poe.tasks]
start="poetry run uvicorn app.server:app --reload"
[tool.poe.tasks.add]
script="langserve.scripts:download"
args = [
{name = "package", help = "package name", positional = true},
{name = "package_dir", help = "path to packages", default = "packages"},
{name = "repo", help = "An alternative GitHub Repo", default = "langchain-ai/langserve-hub"},
{name = "api_path", help = "The API path to mount", default = ""}
]
[tool.poe.tasks.list]
script="langserve.scripts:list"
args = [
{ name = "path", help = "path to packages", default = "packages"}
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"