From 6d376f84dc517826cfa4512c60c4609e6e1a95f2 Mon Sep 17 00:00:00 2001 From: Leon van Zyl Date: Wed, 13 Aug 2025 15:03:27 +0200 Subject: [PATCH] AI env vars --- README.md | 10 ++++++++-- docs/technical/ai/streaming.md | 8 ++++---- env.example | 1 + src/app/api/chat/route.ts | 2 +- src/components/starter-prompt-modal.tsx | 14 ++++++++++++++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d047736..43e9f98 100644 --- a/README.md +++ b/README.md @@ -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 @@ -203,4 +209,4 @@ If you encounter any issues: --- -**Happy coding! 🚀** \ No newline at end of file +**Happy coding! 🚀** diff --git a/docs/technical/ai/streaming.md b/docs/technical/ai/streaming.md index c4e6d37..89af7d1 100644 --- a/docs/technical/ai/streaming.md +++ b/docs/technical/ai/streaming.md @@ -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: { diff --git a/env.example b/env.example index afe76d0..0593f95 100644 --- a/env.example +++ b/env.example @@ -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" \ No newline at end of file diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index 8d10c5e..68ee73f 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -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), }); diff --git a/src/components/starter-prompt-modal.tsx b/src/components/starter-prompt-modal.tsx index 44747da..938267c 100644 --- a/src/components/starter-prompt-modal.tsx +++ b/src/components/starter-prompt-modal.tsx @@ -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: