Spaces:
Sleeping
Sleeping
Camillahannesbo
commited on
Commit
•
59ed150
1
Parent(s):
de07696
changes
Browse files- .gitignore +1 -0
- Dockerfile +21 -0
- app/__init__.py +0 -0
- app/server.py +23 -0
- packages/README.md +0 -0
- packages/pirate-speak/LICENSE +21 -0
- packages/pirate-speak/README.md +67 -0
- packages/pirate-speak/pirate_speak/.env +1 -0
- packages/pirate-speak/pirate_speak/__init__.py +0 -0
- packages/pirate-speak/pirate_speak/chain.py +32 -0
- packages/pirate-speak/poetry.lock +0 -0
- packages/pirate-speak/pyproject.toml +31 -0
- packages/pirate-speak/tests/__init__.py +0 -0
- pyproject.toml +25 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__
|
Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11-slim
|
2 |
+
|
3 |
+
RUN pip install poetry==1.6.1
|
4 |
+
|
5 |
+
RUN poetry config virtualenvs.create false
|
6 |
+
|
7 |
+
WORKDIR /code
|
8 |
+
|
9 |
+
COPY ./pyproject.toml ./README.md ./poetry.lock* ./
|
10 |
+
|
11 |
+
COPY ./package[s] ./packages
|
12 |
+
|
13 |
+
RUN poetry install --no-interaction --no-ansi --no-root
|
14 |
+
|
15 |
+
COPY ./app ./app
|
16 |
+
|
17 |
+
RUN poetry install --no-interaction --no-ansi
|
18 |
+
|
19 |
+
EXPOSE 8080
|
20 |
+
|
21 |
+
CMD exec uvicorn app.server:app --host 0.0.0.0 --port 8080
|
app/__init__.py
ADDED
File without changes
|
app/server.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import RedirectResponse
|
3 |
+
from langserve import add_routes
|
4 |
+
from pirate_speak.chain import chain as pirate_speak_chain
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
|
9 |
+
@app.get("/")
|
10 |
+
async def redirect_root_to_docs():
|
11 |
+
return RedirectResponse("/docs")
|
12 |
+
|
13 |
+
|
14 |
+
# Edit this to add the chain you want to add
|
15 |
+
add_routes(app,
|
16 |
+
pirate_speak_chain,
|
17 |
+
path="/pirate-speak",
|
18 |
+
playground_type='chat')
|
19 |
+
|
20 |
+
if __name__ == "__main__":
|
21 |
+
import uvicorn
|
22 |
+
|
23 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
packages/README.md
ADDED
File without changes
|
packages/pirate-speak/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2023 LangChain, Inc.
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
packages/pirate-speak/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# pirate-speak
|
3 |
+
|
4 |
+
This template converts user input into pirate speak.
|
5 |
+
|
6 |
+
## Environment Setup
|
7 |
+
|
8 |
+
Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.
|
9 |
+
|
10 |
+
## Usage
|
11 |
+
|
12 |
+
To use this package, you should first have the LangChain CLI installed:
|
13 |
+
|
14 |
+
```shell
|
15 |
+
pip install -U langchain-cli
|
16 |
+
```
|
17 |
+
|
18 |
+
To create a new LangChain project and install this as the only package, you can do:
|
19 |
+
|
20 |
+
```shell
|
21 |
+
langchain app new my-app --package pirate-speak
|
22 |
+
```
|
23 |
+
|
24 |
+
If you want to add this to an existing project, you can just run:
|
25 |
+
|
26 |
+
```shell
|
27 |
+
langchain app add pirate-speak
|
28 |
+
```
|
29 |
+
|
30 |
+
And add the following code to your `server.py` file:
|
31 |
+
```python
|
32 |
+
from pirate_speak.chain import chain as pirate_speak_chain
|
33 |
+
|
34 |
+
add_routes(app, pirate_speak_chain, path="/pirate-speak")
|
35 |
+
```
|
36 |
+
|
37 |
+
(Optional) Let's now configure LangSmith.
|
38 |
+
LangSmith will help us trace, monitor and debug LangChain applications.
|
39 |
+
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
|
40 |
+
If you don't have access, you can skip this section
|
41 |
+
|
42 |
+
|
43 |
+
```shell
|
44 |
+
export LANGCHAIN_TRACING_V2=true
|
45 |
+
export LANGCHAIN_API_KEY=<your-api-key>
|
46 |
+
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
|
47 |
+
```
|
48 |
+
|
49 |
+
If you are inside this directory, then you can spin up a LangServe instance directly by:
|
50 |
+
|
51 |
+
```shell
|
52 |
+
langchain serve
|
53 |
+
```
|
54 |
+
|
55 |
+
This will start the FastAPI app with a server is running locally at
|
56 |
+
[http://localhost:8000](http://localhost:8000)
|
57 |
+
|
58 |
+
We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
|
59 |
+
We can access the playground at [http://127.0.0.1:8000/pirate-speak/playground](http://127.0.0.1:8000/pirate-speak/playground)
|
60 |
+
|
61 |
+
We can access the template from code with:
|
62 |
+
|
63 |
+
```python
|
64 |
+
from langserve.client import RemoteRunnable
|
65 |
+
|
66 |
+
runnable = RemoteRunnable("http://localhost:8000/pirate-speak")
|
67 |
+
```
|
packages/pirate-speak/pirate_speak/.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
TOGETHER_API_KEY = 631128cfbf21bdafc2b8c920ea4ee1688416a47e099b63509fdbaae2a1cc8a04
|
packages/pirate-speak/pirate_speak/__init__.py
ADDED
File without changes
|
packages/pirate-speak/pirate_speak/chain.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#from langchain_community.chat_models import ChatOpenAI
|
2 |
+
from langchain_together import Together
|
3 |
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
4 |
+
|
5 |
+
import os
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
load_dotenv()
|
8 |
+
together_api_key = os.getenv("TOGETHER_API_KEY")
|
9 |
+
|
10 |
+
_prompt = ChatPromptTemplate.from_messages(
|
11 |
+
[
|
12 |
+
(
|
13 |
+
"system",
|
14 |
+
"You are a strange but happy pirate answer in pirate speak. No longer than 1-2 sentences. Be brave!",
|
15 |
+
),
|
16 |
+
MessagesPlaceholder("chat_history"),
|
17 |
+
("human", "{text}"),
|
18 |
+
]
|
19 |
+
)
|
20 |
+
_model = Together(
|
21 |
+
#model="mistralai/Mistral-7B-Instruct-v0.2",
|
22 |
+
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
23 |
+
temperature=0.7,
|
24 |
+
top_k=50,
|
25 |
+
top_p=0.7,
|
26 |
+
repetition_penalty=1,
|
27 |
+
together_api_key=together_api_key
|
28 |
+
)
|
29 |
+
|
30 |
+
# if you update this, you MUST also update ../pyproject.toml
|
31 |
+
# with the new `tool.langserve.export_attr`
|
32 |
+
chain = _prompt | _model
|
packages/pirate-speak/poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
packages/pirate-speak/pyproject.toml
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "pirate-speak"
|
3 |
+
version = "0.0.1"
|
4 |
+
description = "Get started with a simple template that speaks like a pirate"
|
5 |
+
authors = []
|
6 |
+
readme = "README.md"
|
7 |
+
|
8 |
+
[tool.poetry.dependencies]
|
9 |
+
python = ">=3.8.1,<4.0"
|
10 |
+
openai = "<2"
|
11 |
+
langchain-community = ">=0.0.7,<0.2"
|
12 |
+
langchain-core = ">=0.1.4,<0.2"
|
13 |
+
|
14 |
+
[tool.poetry.group.dev.dependencies]
|
15 |
+
langchain-cli = ">=0.0.21"
|
16 |
+
fastapi = ">=0.104.0,<1"
|
17 |
+
sse-starlette = "^1.6.5"
|
18 |
+
|
19 |
+
[tool.langserve]
|
20 |
+
export_module = "pirate_speak.chain"
|
21 |
+
export_attr = "chain"
|
22 |
+
|
23 |
+
[tool.templates-hub]
|
24 |
+
use-case = "chatbot"
|
25 |
+
author = "LangChain"
|
26 |
+
integrations = ["OpenAI"]
|
27 |
+
tags = ["getting-started"]
|
28 |
+
|
29 |
+
[build-system]
|
30 |
+
requires = ["poetry-core"]
|
31 |
+
build-backend = "poetry.core.masonry.api"
|
packages/pirate-speak/tests/__init__.py
ADDED
File without changes
|
pyproject.toml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "my-app"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["Your Name <you@example.com>"]
|
6 |
+
readme = "README.md"
|
7 |
+
packages = [
|
8 |
+
{ include = "app" },
|
9 |
+
]
|
10 |
+
|
11 |
+
[tool.poetry.dependencies]
|
12 |
+
python = "^3.11"
|
13 |
+
uvicorn = "^0.23.2"
|
14 |
+
langserve = {extras = ["server"], version = ">=0.0.30"}
|
15 |
+
pydantic = "2.6.0"
|
16 |
+
pirate-speak = {path = "packages/pirate-speak", develop = true}
|
17 |
+
python-dotenv = "1"
|
18 |
+
langchain-together = "0.0.2.post1"
|
19 |
+
|
20 |
+
[tool.poetry.group.dev.dependencies]
|
21 |
+
langchain-cli = ">=0.0.15"
|
22 |
+
|
23 |
+
[build-system]
|
24 |
+
requires = ["poetry-core"]
|
25 |
+
build-backend = "poetry.core.masonry.api"
|