Using prompts
Craft reusable prompts to generate structured data with @repo/ai.
Prompt engineering is the process of crafting prompts to interact with the AI. This guide does not dive deep into prompt engineering; it shows how to use prompts in TurboJet to get data generated by the AI that you can use in your app.
Create a prompt
There is no prompt library in the repo yet. Add helpers under packages/ai/src/prompts.ts and re-export them from packages/ai/src/index.ts so apps import from @repo/ai.
The idea is that you create a prompt with placeholders that can then be filled with data from your app and sent to the AI as a message.
export function generateProductNamesPrompt(topic: string) {
return `List me five funny product names that could be used for ${topic}. Format the output as a JSON array of objects with the key name that contains the generated value. Also remove code highlighting.`;
}Re-export from the package entry:
export { generateProductNamesPrompt } from "./prompts";This function returns a prompt that can generate product names for a given topic.
Use the prompt
Call the function and pass the topic as an argument, then send it with streamText and getChatModel:
import { getChatModel, generateProductNamesPrompt } from "@repo/ai";
import { streamText } from "ai";
const prompt = generateProductNamesPrompt("dog food");
const response = streamText({
model: getChatModel(),
messages: [{ role: "user", content: prompt }],
});For a UI stream instead, pass the same message array into createChatUIMessageResponse.
A possible response from the AI:
[
{ "name": "Bark Bites: Woof-tastic Chews" },
{ "name": "Paw-some Pâté: Tail-Wagging Treats" },
{ "name": "Mutt Munchies: Canine Crunchies" },
{ "name": "Fido's Feast: Bark-quet Delights" },
{ "name": "Pup-ular Chow: Snout-Approved Snacks" }
]Parse the value as JSON and use the data in your application.
This is a basic example — you can create more complex prompts and use the data anywhere in your app.
Check out the Prompt Engineering Guide for more examples and ideas.
Related
- AI overview — models and gateway setup
- AI chatbot — streaming chat API