Skip to content

Commit e4b7d18

Browse files
authored
docs: add car-notifier example (#128)
Signed-off-by: Grant Linville <[email protected]>
1 parent 7221be1 commit e4b7d18

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

examples/car-notifier/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine:latest
2+
3+
COPY car-notifier.gpt ./car-notifier.gpt
4+
5+
RUN apk update && apk add curl postgresql16-client --no-cache && curl https://get.gptscript.ai/install.sh | sh && mkdir /.cache && chmod 777 /.cache
6+
7+
CMD ["gptscript", "--cache=false", "car-notifier.gpt"]

examples/car-notifier/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Car Notifier
2+
3+
This is an example tool that fetches information about recently posted Toyota 4Runners
4+
on Phoenix Craigslist and sends an email with information about them.
5+
6+
This tool is meant to be run as a cron job, daily, and requires a PostgreSQL database.
7+
It uses SendGrid to send the email.
8+
9+
## Design
10+
11+
This tool does not rely on any code besides a Dockerfile and a GPTScript. The Dockerfile
12+
is only used to containerize the environment that the GPTScript will run in.
13+
14+
## Run the Example
15+
16+
Prerequisites:
17+
- A PostgreSQL database, and a connection URL to it
18+
- A SendGrid API key
19+
- `psql` CLI client for PostgreSQL
20+
- `curl`
21+
22+
Before running the script (or building the Dockerfile), be sure to edit it and fill in
23+
every occurrence of `<email address>` and `<name>`. Unfortunately, there is no
24+
straightforward way to provide this information through environment variables, due to
25+
issues with escaping quotes in the cURL command that the LLM will run.
26+
27+
```bash
28+
# Set up the environment variables
29+
export PGURL=your-postgres-connection-url
30+
export SENDGRID_API_KEY=your-sendgrid-api-key
31+
32+
# Run the script
33+
gptscript --cache=false car-notifier.gpt
34+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tools: send_email, sys.http.html2text, sys.write, sys.exec?
2+
3+
Visit https://phoenix.craigslist.org/search/cta?postedToday=1&query=4runner&sort=date to get information about the
4+
4Runners listed today.
5+
6+
Check the PostgreSQL database and see if any of these vehicles have already been stored. If they have been, ignore them.
7+
The `psql` command is available. The database connection string is in the environment variable PGURL. The table is
8+
called "vehicles". If the table doesn't exist yet, create it. The only thing that needs to be stored in the table
9+
is the URL for each vehicle. Don't add any other fields.
10+
11+
For each vehicle that was not already in the database, store the information about it into the database, and send
12+
an email with information about those vehicles. If there are no new vehicles, then don't send an email.
13+
14+
---
15+
name: send_email
16+
description: sends an email with the provided contents
17+
args: contents: the contents of the email to send
18+
tools: sys.http.html2text, sys.exec?
19+
20+
IMPORTANT: when setting --header or -H on a cURL command, always use double quotes, never single quotes!
21+
IMPORTANT: when setting --data or -d on a cURL command, always use single quotes, never double quotes! And always escape newlines! (They should look like "\\n")
22+
23+
The SendGrid API key is in the environment variable SENDGRID_API_KEY.
24+
25+
Perform the following actions in this order:
26+
1. View the contents of https://docs.sendgrid.com/for-developers/sending-email/api-getting-started to learn about the SendGrid API.
27+
2. Run a cURL command to send an email using the SendGrid API, with the following information:
28+
to: <email address> (name: <name>)
29+
from: <email address> (name: <name>)
30+
reply to: <email address> (name: <name>)
31+
subject: "4Runner Listings"
32+
content: $contents

0 commit comments

Comments
 (0)