AI env vars

This commit is contained in:
Leon van Zyl
2025-08-13 15:03:27 +02:00
parent 557bbccb7d
commit 6d376f84dc
5 changed files with 28 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ Before you begin, ensure you have the following installed on your machine:
### 1. Clone or Download the Repository
**Option A: Clone with Git**
```bash
git clone https://github.com/your-username/nextjs-better-auth-postgresql-starter-kit.git
cd nextjs-better-auth-postgresql-starter-kit
@@ -41,6 +42,7 @@ npm install
### 3. Environment Setup
Copy the example environment file:
```bash
cp env.example .env
```
@@ -60,6 +62,7 @@ GOOGLE_CLIENT_SECRET="your-google-client-secret"
# AI Integration (Optional - for chat functionality)
OPENAI_API_KEY="sk-your-openai-api-key-here"
OPENAI_MODEL="gpt-5-mini"
# App URL (for production deployments)
NEXT_PUBLIC_APP_URL="http://localhost:3000"
@@ -68,6 +71,7 @@ NEXT_PUBLIC_APP_URL="http://localhost:3000"
### 4. Database Setup
Push the database schema to your PostgreSQL database:
```bash
npm run db:push
```
@@ -166,11 +170,13 @@ npm run db:reset # Reset database (drop all tables)
### Production Environment Variables
Ensure these are set in your production environment:
- `DATABASE_URL` - Production PostgreSQL connection string
- `BETTER_AUTH_SECRET` - Secure random 32+ character string
- `GOOGLE_CLIENT_ID` - Google OAuth Client ID
- `GOOGLE_CLIENT_SECRET` - Google OAuth Client Secret
- `OPENAI_API_KEY` - OpenAI API key (optional)
- `OPENAI_MODEL` - OpenAI model name (optional, defaults to gpt-5-mini)
- `NEXT_PUBLIC_APP_URL` - Your production domain
## 🎥 Tutorial Video
@@ -179,7 +185,7 @@ Watch my comprehensive tutorial on how to use this boilerplate to build amazing
[📺 YouTube Tutorial - Building with Next.js Better Auth PostgreSQL Starter Kit](#)
*Coming soon - link will be updated with the actual video URL*
_Coming soon - link will be updated with the actual video URL_
## 🤝 Contributing

View File

@@ -97,7 +97,7 @@ export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: openai("gpt-4o"),
model: openai(process.env.OPENAI_MODEL || "gpt-5-mini"),
messages: convertToModelMessages(messages),
});
@@ -209,7 +209,7 @@ export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: openai("gpt-4o"),
model: openai(process.env.OPENAI_MODEL || "gpt-5-mini"),
messages: convertToModelMessages(messages),
tools: {
weather: tool({
@@ -336,7 +336,7 @@ export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: openai("gpt-4o"),
model: openai(process.env.OPENAI_MODEL || "gpt-5-mini"),
messages: convertToModelMessages(messages),
stopWhen: stepCountIs(5),
tools: {
@@ -390,7 +390,7 @@ export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: openai("gpt-4o"),
model: openai(process.env.OPENAI_MODEL || "gpt-5-mini"),
messages: convertToModelMessages(messages),
stopWhen: stepCountIs(5),
tools: {

View File

@@ -10,6 +10,7 @@ GOOGLE_CLIENT_SECRET=
# AI Integration (Optional - for chat functionality)
OPENAI_API_KEY=
OPENAI_MODEL="gpt-5-mini"
# App URL (for production deployments)
NEXT_PUBLIC_APP_URL="http://localhost:3000"

View File

@@ -5,7 +5,7 @@ export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: openai("gpt-5-mini"),
model: openai(process.env.OPENAI_MODEL || "gpt-5-mini"),
messages: convertToModelMessages(messages),
});

View File

@@ -59,6 +59,20 @@ The only things to preserve are:
- shadcn/ui components
- Lucide React icons
## AI Model Configuration
**IMPORTANT**: When implementing any AI functionality, always use the \`OPENAI_MODEL\` environment variable for the model name instead of hardcoding it:
\`\`\`typescript
// ✅ Correct - Use environment variable
const model = process.env.OPENAI_MODEL || "gpt-5-mini";
model: openai(model)
// ❌ Incorrect - Don't hardcode model names
model: openai("gpt-5-mini")
\`\`\`
This allows for easy model switching without code changes and ensures consistency across the application.
## Component Development Guidelines
**Always prioritize shadcn/ui components** when building the application: