diff --git a/examples/car-notifier/Dockerfile b/examples/car-notifier/Dockerfile new file mode 100644 index 00000000..52727022 --- /dev/null +++ b/examples/car-notifier/Dockerfile @@ -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"] diff --git a/examples/car-notifier/README.md b/examples/car-notifier/README.md new file mode 100644 index 00000000..2e6e097b --- /dev/null +++ b/examples/car-notifier/README.md @@ -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 `` and ``. 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 +``` diff --git a/examples/car-notifier/car-notifier.gpt b/examples/car-notifier/car-notifier.gpt new file mode 100644 index 00000000..7c030a79 --- /dev/null +++ b/examples/car-notifier/car-notifier.gpt @@ -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: (name: ) + from: (name: ) + reply to: (name: ) + subject: "4Runner Listings" + content: $contents