fix some stuff (#12292)

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Harrison Chase
2023-10-26 13:30:36 -07:00
committed by GitHub
parent 6ce276e099
commit 9ce38726a2
21 changed files with 17 additions and 3033 deletions

View File

@@ -1,3 +1,4 @@
DEFAULT_GIT_REPO = "https://github.com/langchain-ai/langchain.git"
DEFAULT_GIT_REF = "langserve-templates"
DEFAULT_GIT_SUBDIRECTORY = "templates"
DEFAULT_GIT_REF = "master"

View File

@@ -30,7 +30,7 @@ def new(
destination_dir = Path.cwd() / name if name != "." else Path.cwd()
# copy over template from ../package_template
project_template_dir = Path(__file__).parent.parent.parent / "package_template"
project_template_dir = Path(__file__).parents[1] / "package_template"
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=name == ".")
package_name_split = computed_name.split("/")

View File

@@ -42,7 +42,7 @@ def new(
Create a new LangServe application.
"""
# copy over template from ../project_template
project_template_dir = Path(__file__).parent.parent.parent / "project_template"
project_template_dir = Path(__file__).parents[1] / "project_template"
destination_dir = Path.cwd() / name if name != "." else Path.cwd()
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=name == ".")

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 LangChain, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1 @@
# __package_name_last__

View File

@@ -0,0 +1,18 @@
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI
_prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a helpful assistant who speaks like a pirate",
),
("human", "{text}"),
]
)
_model = ChatOpenAI()
# if you update this, you MUST also update ../pyproject.toml
# with the new `tool.langserve.export_attr`
chain = _prompt | _model

View File

@@ -0,0 +1,32 @@
[tool.poetry]
name = "__package_name__"
version = "0.0.1"
description = ""
authors = []
readme = "README.md"
[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
langchain = ">=0.0.313, <0.1"
openai = "^0.28.1"
fastapi = "^0.104.0"
sse-starlette = "^1.6.5"
[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.1"
langchain-cli = ">=0.0.1rc2"
[tool.langserve]
export_module = "__package_name__.chain"
export_attr = "chain"
[tool.poe.tasks.start]
cmd="uvicorn langchain_cli.dev_scripts:create_demo_server --reload --port $port --host $host"
args = [
{name = "port", help = "port to run on", default = "8000"},
{name = "host", help = "host to run on", default = "127.0.0.1"}
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@@ -0,0 +1,32 @@
# LangServeHub Project Template
## Installation
Install the LangChain CLI if you haven't yet
```bash
pip install --user --upgrade git+https://github.com/pingpong-templates/cli.git
```
And install this package's dependencies
```bash
poetry install
```
## Adding packages
```bash
# if you have problems with `poe`, try `poetry run poe`
# adding packages from https://github.com/pingpong-templates/hub
langchain serve add simple-pirate
# adding custom GitHub repo packages
langchain serve add git+https://github.com/hwchase17/chain-of-verification
# with a custom api mount point (defaults to `/{package_name}`)
poe add simple-translator --api_path=/my/custom/path/translator
```
## Removing packages
Note: you remove packages by their api path
```bash
langchain serve remove pirate
```

View File

@@ -0,0 +1,12 @@
from fastapi import FastAPI
from langserve import add_routes
app = FastAPI()
# Edit this to add the chain you want to add
add_routes(app, NotImplemented)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)

View File

@@ -0,0 +1,31 @@
[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"
tomli-w = "^1.0.0"
uvicorn = "^0.23.2"
fastapi = "^0.103.2"
langserve = ">=0.0.16"
[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.1"
uvicorn = "^0.23.2"
pygithub = "^2.1.1"
[tool.poe.tasks.start]
cmd="uvicorn app.server:app --reload --port $port --host $host"
args = [
{name = "port", help = "port to run on", default = "8000"},
{name = "host", help = "host to run on", default = "127.0.0.1"}
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@@ -67,7 +67,6 @@ def parse_dependency_string(package_string: str) -> DependencySource:
raise NotImplementedError("url dependencies are not supported yet")
else:
# it's a default git repo dependency
gitstring = DEFAULT_GIT_REPO
subdirectory = str(Path(DEFAULT_GIT_SUBDIRECTORY) / package_string)
return DependencySource(
git=gitstring, ref=DEFAULT_GIT_REF, subdirectory=subdirectory