A Next.js application that helps users create personalized learning plans using the Vercel AI SDK. The app supports both OpenAI and Cerebras inference backends.
-
Install dependencies:
npm install
-
Configure your AI provider:
- Create a
.env.localfile with the provider selection and credentials. By default, the app will use OpenAI.
# Select the provider: openai (default) or cerebras AI_PROVIDER=openai # OpenAI credentials (required when AI_PROVIDER=openai) OPENAI_API_KEY=your_openai_api_key # Cerebras credentials (required when AI_PROVIDER=cerebras) CEREBRAS_API_KEY=your_cerebras_api_key # Optional: override the base URL if you are using a private deployment # CEREBRAS_BASE_URL=https://api.cerebras.ai/v1
- Modify
lib/ai/config.tsto adjust the default models for each provider/use case. For example,gpt-oss-120bfor Cerebras chat orgpt-5-minifor OpenAI.
- Create a
-
Set up Supabase (required for persistence): Add these variables to
.env.local:
NEXT_PUBLIC_SUPABASE_URL=https://your-supabase-project-ref.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_public_anon_key_here
SUPABASE_SECRET_KEY=your_secret_key_here
SUPABASE_DB_URL=postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres- The
NEXT_PUBLIC_*keys are safe for the browser. SUPABASE_SECRET_KEY(a.k.a. service role key) andSUPABASE_DB_URLare server-only values; keep them out of the client bundle and version control. Rotate them immediately if they leak.
-
Run database migrations (after setting env vars):
npm run db:generate npm run db:migrate
-
Run the development server:
npm run dev
-
Run the background worker
Course generation now happens fully asynchronously. There is a long-running worker that polls
course_generation_jobs, calls the LLM, and persists results.-
Make sure the required env vars are present (the easiest way is to export them in the shell that runs the worker;
.env.localis not loaded automatically bytsx):export SUPABASE_DB_URL=postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres export OPENAI_API_KEY=your_openai_api_key export AI_PROVIDER=openai # Optional tuning export COURSE_GENERATION_WORKER_CONCURRENCY=3 export COURSE_GENERATION_HEARTBEAT_MS=45000 export COURSE_GENERATION_STALE_TIMEOUT_MS=180000 export COURSE_GENERATION_REQUEUE_INTERVAL_MS=60000
You can add these to your shell profile or use
direnv/dotenvxto load them automatically. -
Start the worker in a separate terminal:
npm run worker:course
This script uses
tsxto runworker/course-generator.tsdirectly. Keep it running alongsidenpm run dev.
-
Create a Render Background Worker service pointing to this repo/branch.
-
Set the same environment variables in the Render dashboard (
SUPABASE_DB_URL,OPENAI_API_KEY,AI_PROVIDER, plus any optional tuning vars). -
Use a start command that installs deps (with dev deps, for
tsx) and launches the worker. For example:npm install npm run worker:course
Alternatively you can build once and run the compiled JS with
node dist/worker/course-generator.jsif you prefer not to ship dev deps.
-
-
Open your browser: Navigate to http://localhost:3000