|
1 |
| -# AWS Python LangServe Example |
| 1 | +# AWS YAML LangServe Example |
2 | 2 |
|
3 |
| -## Installation |
| 3 | +This example demonstrates how to use deploy a simple app using Pulumi in YAML. |
4 | 4 |
|
5 |
| -Install the LangChain CLI if you haven't yet |
| 5 | +## Prerequisites |
6 | 6 |
|
7 |
| -```bash |
8 |
| -pip install -U langchain-cli |
9 |
| -``` |
10 |
| - |
11 |
| -## Adding packages |
| 7 | +To run this example, you'll need the following tools installed on your machine: |
12 | 8 |
|
13 |
| -```bash |
14 |
| -# adding packages from |
15 |
| -# https://github.com/langchain-ai/langchain/tree/master/templates |
16 |
| -langchain app add $PROJECT_NAME |
17 |
| - |
18 |
| -# adding custom GitHub repo packages |
19 |
| -langchain app add --repo $OWNER/$REPO |
20 |
| -# or with whole git string (supports other git providers): |
21 |
| -# langchain app add git+https://github.com/hwchase17/chain-of-verification |
| 9 | +1. [Install Pulumi](https://www.pulumi.com/docs/install/) |
| 10 | +2. [Install Python](https://www.python.org/downloads/) |
| 11 | +2. [Configure AWS](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/) |
| 12 | +3. [Install Docker](https://docs.docker.com/get-docker/) |
| 13 | +4. [Install the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) |
| 14 | +5. [Install the LangChain CLI](https://python.langchain.com/docs/langserve#installation) |
22 | 15 |
|
23 |
| -# with a custom api mount point (defaults to `/{package_name}`) |
24 |
| -langchain app add $PROJECT_NAME --api_path=/my/custom/path/rag |
25 |
| -``` |
| 16 | +## Deploying to AWS using Pulumi |
26 | 17 |
|
27 |
| -Note: you remove packages by their api path |
| 18 | +Set the region with the following command: |
28 | 19 |
|
29 | 20 | ```bash
|
30 |
| -langchain app remove my/custom/path/rag |
| 21 | +pulumi config set aws:region <region> |
31 | 22 | ```
|
32 | 23 |
|
33 |
| -## Setup LangSmith (Optional) |
34 |
| -LangSmith will help us trace, monitor and debug LangChain applications. |
35 |
| -LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/). |
36 |
| -If you don't have access, you can skip this section |
37 |
| - |
38 |
| - |
39 |
| -```shell |
40 |
| -export LANGCHAIN_TRACING_V2=true |
41 |
| -export LANGCHAIN_API_KEY=<your-api-key> |
42 |
| -export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default" |
43 |
| -``` |
44 |
| - |
45 |
| -## Launch LangServe |
46 |
| - |
47 |
| -```bash |
48 |
| -langchain serve |
49 |
| -``` |
50 |
| - |
51 |
| -## Deploying to AWS |
52 |
| - |
53 | 24 | Run the following command to deploy your LangServe app to AWS:
|
54 | 25 |
|
55 | 26 | ```bash
|
| 27 | +git clone https://github.com/pulumi/examples.git |
| 28 | +cd examples/aws-py-langserve |
| 29 | +pulumi stack init <your-stack-name> |
| 30 | +pulumi config set open-api-key --secret # Enter your OpenAI API key |
56 | 31 | pulumi up
|
57 | 32 | ```
|
58 | 33 |
|
59 |
| -This will output the URL of your LangServe app. You can use this URL to make requests to your app. |
60 |
| - |
61 |
| -## Running in Docker |
| 34 | +This last command will show you a preview of the resources that will be created. After reviewing the changes, you will be prompted to continue. Once confirmed, Pulumi will deploy your LangServe app to AWS. |
62 | 35 |
|
63 |
| -This project folder includes a Dockerfile that allows you to easily build and host your LangServe app. |
| 36 | +The whole deployoment process will take a couple of minutes. Once it's done, you will see the URL of your LangServe app in the output. |
64 | 37 |
|
65 |
| -### Building the Image |
66 |
| - |
67 |
| -To build the image, you simply: |
| 38 | +```bash |
| 39 | +Outputs: |
| 40 | + url: "http://<dns>.elb.amazonaws.com" |
68 | 41 |
|
69 |
| -```shell |
70 |
| -docker build . -t my-langserve-app |
| 42 | +Resources: |
| 43 | + + 27 created |
71 | 44 | ```
|
72 | 45 |
|
73 |
| -If you tag your image with something other than `my-langserve-app`, |
74 |
| -note it for use in the next step. |
75 |
| - |
76 |
| -### Running the Image Locally |
| 46 | +You can now access the LangServe playground by adding `/openai/playground` to the URL you got from the output. |
77 | 47 |
|
78 |
| -To run the image, you'll need to include any environment variables |
79 |
| -necessary for your application. |
| 48 | +> [!NOTE] |
| 49 | +> It may take a few minutes for the load balancer to be ready to accept requests. If you see a 503 error, wait a few minutes and try again. |
80 | 50 |
|
81 |
| -In the below example, we inject the `OPENAI_API_KEY` environment |
82 |
| -variable with the value set in my local environment |
83 |
| -(`$OPENAI_API_KEY`) |
| 51 | +## Clean up |
84 | 52 |
|
85 |
| -We also expose port 8080 with the `-p 8080:8080` option. |
| 53 | +To clean up the resources created by this example, run the following command: |
86 | 54 |
|
87 |
| -```shell |
88 |
| -docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -p 8080:8080 my-langserve-app |
| 55 | +```bash |
| 56 | +pulumi destroy |
89 | 57 | ```
|
| 58 | + |
| 59 | +You will be prompted to confirm the deletion of the resources. Once confirmed, Pulumi will delete all the resources created by this example. |
0 commit comments