Skip to content

Commit e59291e

Browse files
authored
docs(ai-chat): clarify local setup with .env.example (#3623)
1 parent 15b7cde commit e59291e

2 files changed

Lines changed: 62 additions & 15 deletions

File tree

references/ai-chat/.env.example

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Local dev (Trigger.dev webapp running on http://localhost:3030)
2+
#
3+
# Create a project in the local dashboard (References org) and copy:
4+
# - TRIGGER_PROJECT_REF from the project URL (proj_...)
5+
# - TRIGGER_SECRET_KEY from the project's Dev environment API keys
6+
# - NEXT_PUBLIC_TRIGGER_PROJECT_DASHBOARD_PATH from the dashboard URL
7+
TRIGGER_API_URL="http://localhost:3030"
8+
NEXT_PUBLIC_TRIGGER_API_URL="http://localhost:3030"
9+
NEXT_PUBLIC_TRIGGER_DASHBOARD_URL="http://localhost:3030"
10+
NEXT_PUBLIC_TRIGGER_PROJECT_DASHBOARD_PATH="/orgs/<org-slug>/projects/<project-slug>"
11+
TRIGGER_SECRET_KEY="tr_dev_..."
12+
TRIGGER_PROJECT_REF="proj_..."
13+
14+
# Postgres database for the ai-chat reference app itself (separate from the
15+
# webapp's database). Schema is applied by `npx prisma migrate deploy`.
16+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/ai_chat?schema=public"
17+
18+
# Model providers — needed by the chat task. At least one is required.
19+
OPENAI_API_KEY=""
20+
ANTHROPIC_API_KEY=""
21+
22+
# Optional — code-sandbox tool
23+
E2B_API_KEY=""
24+
25+
# Optional — analytics
26+
POSTHOG_API_KEY=""
27+
POSTHOG_PROJECT_ID=""
28+
29+
# Optional — tuning knobs
30+
COMPACT_AFTER_TOKENS="50000"
31+
WEBFETCH_LATENCY_MS="0"

references/ai-chat/README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,38 @@ Persistence is handled server-side in the Trigger.dev task via three hooks:
4141

4242
## Setup
4343

44+
This reference assumes you already have the local webapp running per the repo's [`CONTRIBUTING.md`](../../CONTRIBUTING.md) (Docker services, `pnpm run db:migrate`, `pnpm run db:seed`, webapp on `:3030`).
45+
46+
Unlike `hello-world`, the ai-chat project is **not** in the webapp seed. You'll need to create it manually:
47+
48+
1. Open http://localhost:3030, log in, switch to the `References` org, and create a new project called `ai-chat`.
49+
2. Grab the project ref (`proj_...`) from the URL and a Dev secret key from the project's API keys page.
50+
3. Set up this app's env and database:
51+
52+
```bash
53+
cd references/ai-chat
54+
cp .env.example .env
55+
# Fill in TRIGGER_PROJECT_REF, TRIGGER_SECRET_KEY,
56+
# NEXT_PUBLIC_TRIGGER_PROJECT_DASHBOARD_PATH, and at least one
57+
# of OPENAI_API_KEY / ANTHROPIC_API_KEY.
58+
npx prisma migrate deploy
59+
```
60+
61+
The `DATABASE_URL` in `.env.example` points at the local Postgres started by `pnpm run docker` and uses a separate `ai_chat` database.
62+
63+
## Running
64+
65+
Three terminals from the repo root:
66+
4467
```bash
45-
# From the repo root
46-
pnpm run docker # Start PostgreSQL, Redis, Electric
47-
pnpm run db:migrate # Run webapp migrations
48-
pnpm run db:seed # Seed the database
49-
50-
# Set up the reference app's database
51-
cd references/ai-chat
52-
cp .env.example .env # Edit DATABASE_URL if needed
53-
npx prisma migrate deploy
54-
55-
# Build and run
56-
pnpm run build --filter trigger.dev --filter @trigger.dev/sdk
57-
pnpm run dev --filter webapp # In one terminal
58-
cd references/ai-chat && pnpm exec trigger dev # In another
59-
cd references/ai-chat && pnpm run dev # In another
68+
# 1. Webapp (if not already running)
69+
pnpm run dev --filter webapp
70+
71+
# 2. Trigger CLI dev (registers the chat tasks with the local webapp)
72+
cd references/ai-chat && pnpm exec trigger dev
73+
74+
# 3. Next.js dev server for the chat UI
75+
cd references/ai-chat && pnpm run dev
6076
```
6177

6278
Open http://localhost:3000 to use the chat app.

0 commit comments

Comments
 (0)