Add context from your database: Free AI Prompt | SheCodes

Free AI prompt · The Code Book

Add context from your database

A ready-to-use prompt from the chapter AI Chat Features. Paste it into Claude, ChatGPT, Lovable, Bolt or any AI coding tool.

The prompt

“In my AI chat, before sending the user's message to the AI, fetch relevant context from my database (e.g., the user's recent orders, their saved notes, or product info matching their query). Pass that context as part of the system prompt so the AI can give personalized answers.”

How to use it

  1. Copy the prompt and paste it into your AI coding tool.
  2. Check the result in the preview, then ask for changes one at a time: "make the buttons bigger", "use my brand colours".
  3. Read the chapter to understand why it works and what to do next.

More prompts like this

All prompts

Add ai chat with vercel ai sdk

“Add an AI chatbot to my app at /chat, powered by Anthropic's Claude. The chat should: (1) show the reply word-by-word as it's written, (2) show a typing indicator while waiting, (3) automatically scroll to the newest message, (4) show a friendly message if something goes wrong. Keep my Claude API key in a safe place so it's never visible to visitors.”

Add chat history

“Add conversation history to my AI chat. Create conversations and messages tables in Supabase. When a user starts a new chat, INSERT a conversation row. After every message exchange, INSERT both the user message and the AI response into the messages table. Add a sidebar showing the user's past conversations (with auto-generated titles based on the first message). Clicking one loads its messages into the chat.”

Add rate limits to my chat

“Add a limit to my AI chat so each visitor can only send 20 messages per hour. Identify them by their account if they're signed in, or by their device otherwise. When someone hits the limit, show a friendly red message in the chat that says: "You've hit your hourly message limit. Try again in X minutes.”

Stream a summary

“Add a "Summarize" button on my long-form content pages (blog posts, transcripts). When clicked, it should stream an AI-generated 3-bullet summary into a sidebar without leaving the page. Use the Vercel AI SDK's streamText function.”

Voice-to-text input

“Add a microphone button to my chat input that records the user's voice and transcribes it (using OpenAI's speech-to-text API or the browser's Web Speech API). When they stop recording, the transcribed text appears in the input box and they can edit it before sending.”

Set up a frontend project

“Set up a new Next.js project with TypeScript, Tailwind CSS, and App Router. Create a clean homepage with a [header/hero/features] layout.”