Getting Started

AI assistant (Groq) setup

Instructions to configure the Vercel @vercel/ai SDK using the groq model and integrate it with the chat flow.

1. API key & env

This template uses the @ai-sdk/groq package and the streaming helper from ai. Add your API key (used by the runtime) to .env.local. The repo includes .env.example with GROQ_API_KEY.

// .env.local (example)
GROQ_API_KEY=your_groq_api_key

2. Server API route (already implemented)

The project exposes an API route at src/app/api/chat/route.ts which accepts a JSON body with { prompt } and streams the AI response back to the client using streamText.

// src/app/api/chat/route.ts (excerpt)
import { groq } from '@ai-sdk/groq';
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { prompt } = await req.json();

  const result = streamText({
    model: groq('llama-3.1-8b-instant'),
    system: 'You are a concise admin assistant. Answer briefly.',
    messages: [{ role: 'user', content: prompt }],
    temperature: 0.7,
  });

  return result.toTextStreamResponse();
}

Call this route from the UI (POST /api/chat with JSON { prompt }) to receive a streamed text response and render it as a system message if you persist it in Firestore.

3. Room & IDs

The template uses specific room IDs to route AI conversations in the UI. See src/constants/ai.constant.tsfor example IDs used by the demo. You can create a dedicated room and use that roomId when saving AI responses as type: 'system'.

3. Conversation design

Keep requests concise and optionally include a trimmed conversation history when calling the API to maintain context while controlling token usage.