|
2 | 2 |
|
3 | 3 | [](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-nodejs-openai-template%26template_owner%3DDefangSamples)
|
4 | 4 |
|
5 |
| -## Setup |
| 5 | +A simple Node.js and OpenAI app deployed using Defang. |
6 | 6 |
|
7 |
| -This sample requires an API key to access the OpenAI API. The name of the config value is referenced in the compose.yaml file. |
8 |
| -To provide a value for it, you can use the Defang CLI like this: |
| 7 | +## Prerequisites |
9 | 8 |
|
10 |
| -``` |
| 9 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 10 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 11 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 12 | + |
| 13 | +## Development |
11 | 14 |
|
12 |
| -defang config set --name OPENAI_KEY |
| 15 | +To run the application locally, you can use the following command: |
| 16 | + |
| 17 | +```bash |
| 18 | +docker compose up --build |
13 | 19 | ```
|
14 | 20 |
|
15 |
| -and then enter the value when prompted. |
| 21 | +## Configuration |
| 22 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration): |
16 | 23 |
|
17 |
| -## Testing |
| 24 | +> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you. |
18 | 25 |
|
| 26 | +### `OPENAI_KEY` |
| 27 | +An API key to access the OpenAI API. |
| 28 | +```bash |
| 29 | +defang config set OPENAI_KEY |
19 | 30 | ```
|
| 31 | + |
| 32 | +## Testing |
| 33 | +Below are some useful commands for testing. |
| 34 | + |
| 35 | +```bash |
20 | 36 | echo "Hello" | curl -H "Content-Type: text/plain" -d @- https://xxxxxxxx/prompt
|
21 | 37 | ```
|
22 | 38 |
|
23 |
| -or |
| 39 | +or alternatively, |
24 | 40 |
|
25 |
| -``` |
| 41 | +```bash |
26 | 42 | cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
|
27 | 43 | ```
|
28 | 44 |
|
| 45 | +## Deployment |
| 46 | + |
| 47 | +> [!NOTE] |
| 48 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 49 | +
|
| 50 | +### Defang Playground |
| 51 | + |
| 52 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 53 | +```bash |
| 54 | +defang compose up |
| 55 | +``` |
| 56 | + |
| 57 | +### BYOC (AWS) |
| 58 | + |
| 59 | +If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud): |
| 60 | + |
29 | 61 | ---
|
30 | 62 |
|
31 | 63 | Title: Node.js & OpenAI
|
|
0 commit comments