mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem After #53183 and #52567 have been addressed, we should strengthen the interconnections between the UI library and the rest of the Supabase ecosystem. ## Solution - Adds contextual links for `/library`, Auth / Realtime category pages, and specific Auth / Realtime components. Hits top-level product pages, docs, kb, and blogs. ## Preview links N/A, link changes are relatively atomic so easier to review without many preview links. --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
69 lines
3.7 KiB
Plaintext
69 lines
3.7 KiB
Plaintext
---
|
|
title: AI Chat App
|
|
description: >-
|
|
A Next.js chat app with streaming responses, authentication, and saved
|
|
conversations
|
|
preview: |-
|
|
<BlockOverview name="ai-chat-app">
|
|
<div className="library-component-preview h-80 overflow-hidden border md:h-96">
|
|
<CatalogPreview kind="chat" />
|
|
</div>
|
|
</BlockOverview>
|
|
---
|
|
|
|
The [Supabase Community AI chatbot template](https://github.com/supabase-community/vercel-ai-chatbot) includes a chat interface, streaming responses, Supabase Auth, and conversation history in Postgres. Creating the app installs those features together.
|
|
|
|
## Installation
|
|
|
|
### Create the app
|
|
|
|
Scaffold the template with the [Next.js CLI](https://nextjs.org/docs/app/api-reference/cli/create-next-app):
|
|
|
|
```bash
|
|
npx create-next-app@latest my-chat --example https://github.com/supabase-community/vercel-ai-chatbot --use-pnpm
|
|
cd my-chat
|
|
cp .env.example .env
|
|
```
|
|
|
|
This community template uses Next.js 13, AI SDK 2, and Supabase Auth Helpers, which have been replaced by `@supabase/ssr` (see the [migration guide](https://supabase.com/docs/guides/auth/server-side/migrating-to-ssr-from-auth-helpers)). Review its [dependency versions](https://github.com/supabase-community/vercel-ai-chatbot/blob/main/package.json) and plan upgrades before deployment. For a new authentication foundation using `@supabase/ssr`, start with the [Next.js starter](/library/docs/starters/nextjs-starter).
|
|
|
|
## Start Supabase
|
|
|
|
Install [Docker](https://docs.docker.com/get-started/get-docker/) and the [Supabase CLI](https://supabase.com/docs/guides/local-development/cli/getting-started), then run the local stack from the template directory:
|
|
|
|
```bash
|
|
supabase start
|
|
```
|
|
|
|
The template includes [database migrations](https://supabase.com/docs/guides/local-development/database-migrations) for chat history. Use the project URL and `anon` key printed by the CLI in `.env`:
|
|
|
|
```env
|
|
NEXT_PUBLIC_SUPABASE_URL=your-local-api-url
|
|
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-local-anon-key
|
|
OPENAI_API_KEY=your-model-provider-api-key
|
|
NEXT_PUBLIC_AUTH_GITHUB=false
|
|
```
|
|
|
|
The variable names match the template's [environment example](https://github.com/supabase-community/vercel-ai-chatbot/blob/main/.env.example). Keep `OPENAI_API_KEY` on the server. To add GitHub sign-in, follow the template's [OAuth setup](https://github.com/supabase-community/vercel-ai-chatbot#set-up-github-oauth) and fill in its provider settings. Supabase's [GitHub login guide](https://supabase.com/docs/guides/auth/social-sign-in/auth-github) covers the provider side.
|
|
|
|
## Choose a model
|
|
|
|
The template selects its model in [`app/api/chat/route.ts`](https://github.com/supabase-community/vercel-ai-chatbot/blob/main/app/api/chat/route.ts). Replace the example model with one available to your provider account that supports the template's Chat Completions streaming API. Keep the model selection and API key in the server route.
|
|
|
|
## Run the app
|
|
|
|
```bash
|
|
pnpm dev
|
|
```
|
|
|
|
Open [the app](http://localhost:3000), sign up, and send a message. Use the local email inbox URL printed by the Supabase CLI to confirm your account. Confirm that the response streams and that the conversation appears in your history after refreshing.
|
|
|
|
## Deploy the app
|
|
|
|
Follow the template's [deployment guide](https://github.com/supabase-community/vercel-ai-chatbot#deploy-your-own) to connect a hosted Supabase project, apply its migrations, and set the production Auth Site URL and server environment variables.
|
|
|
|
## Learn more
|
|
|
|
- [AI & Vectors](https://supabase.com/docs/guides/ai) covers embeddings and semantic search if you want to search past conversations.
|
|
- [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security) explains how to scope chat history to each user.
|