Skip to content

Commit 1fb052e

Browse files
authored
Merge pull request #301 from DefangLabs/linda-nodejs
Update nodejs samples
2 parents 74f1583 + badd703 commit 1fb052e

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

README.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,62 @@
22

33
[![1-click-deploy](https://defang.io/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-nodejs-openai-template%26template_owner%3DDefangSamples)
44

5-
## Setup
5+
A simple Node.js and OpenAI app deployed using Defang.
66

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
98

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
1114

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
1319
```
1420

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):
1623

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.
1825
26+
### `OPENAI_KEY`
27+
An API key to access the OpenAI API.
28+
```bash
29+
defang config set OPENAI_KEY
1930
```
31+
32+
## Testing
33+
Below are some useful commands for testing.
34+
35+
```bash
2036
echo "Hello" | curl -H "Content-Type: text/plain" -d @- https://xxxxxxxx/prompt
2137
```
2238

23-
or
39+
or alternatively,
2440

25-
```
41+
```bash
2642
cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
2743
```
2844

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+
2961
---
3062

3163
Title: Node.js & OpenAI

0 commit comments

Comments
 (0)