Skip to content

docs: add car-notifier example #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/car-notifier/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:latest

COPY car-notifier.gpt ./car-notifier.gpt

RUN apk update && apk add curl postgresql16-client --no-cache && curl https://get.gptscript.ai/install.sh | sh && mkdir /.cache && chmod 777 /.cache

CMD ["gptscript", "--cache=false", "car-notifier.gpt"]
34 changes: 34 additions & 0 deletions examples/car-notifier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Car Notifier

This is an example tool that fetches information about recently posted Toyota 4Runners
on Phoenix Craigslist and sends an email with information about them.

This tool is meant to be run as a cron job, daily, and requires a PostgreSQL database.
It uses SendGrid to send the email.

## Design

This tool does not rely on any code besides a Dockerfile and a GPTScript. The Dockerfile
is only used to containerize the environment that the GPTScript will run in.

## Run the Example

Prerequisites:
- A PostgreSQL database, and a connection URL to it
- A SendGrid API key
- `psql` CLI client for PostgreSQL
- `curl`

Before running the script (or building the Dockerfile), be sure to edit it and fill in
every occurrence of `<email address>` and `<name>`. Unfortunately, there is no
straightforward way to provide this information through environment variables, due to
issues with escaping quotes in the cURL command that the LLM will run.

```bash
# Set up the environment variables
export PGURL=your-postgres-connection-url
export SENDGRID_API_KEY=your-sendgrid-api-key

# Run the script
gptscript --cache=false car-notifier.gpt
```
32 changes: 32 additions & 0 deletions examples/car-notifier/car-notifier.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
tools: send_email, sys.http.html2text, sys.write, sys.exec?

Visit https://phoenix.craigslist.org/search/cta?postedToday=1&query=4runner&sort=date to get information about the
4Runners listed today.

Check the PostgreSQL database and see if any of these vehicles have already been stored. If they have been, ignore them.
The `psql` command is available. The database connection string is in the environment variable PGURL. The table is
called "vehicles". If the table doesn't exist yet, create it. The only thing that needs to be stored in the table
is the URL for each vehicle. Don't add any other fields.

For each vehicle that was not already in the database, store the information about it into the database, and send
an email with information about those vehicles. If there are no new vehicles, then don't send an email.

---
name: send_email
description: sends an email with the provided contents
args: contents: the contents of the email to send
tools: sys.http.html2text, sys.exec?

IMPORTANT: when setting --header or -H on a cURL command, always use double quotes, never single quotes!
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")

The SendGrid API key is in the environment variable SENDGRID_API_KEY.

Perform the following actions in this order:
1. View the contents of https://docs.sendgrid.com/for-developers/sending-email/api-getting-started to learn about the SendGrid API.
2. Run a cURL command to send an email using the SendGrid API, with the following information:
to: <email address> (name: <name>)
from: <email address> (name: <name>)
reply to: <email address> (name: <name>)
subject: "4Runner Listings"
content: $contents