···11+import { generateObject } from "ai";
22+import { z } from "zod";
33+import { chatModel } from "./model";
44+55+const chatTitleSchema = z.object({
66+ title: z
77+ .string()
88+ .min(1)
99+ .describe("A concise chat title, 2 to 4 words, without wrapping quotes."),
1010+});
1111+1212+export function generateChatTitle(message: string) {
1313+ return generateObject({
1414+ model: chatModel,
1515+ schema: chatTitleSchema,
1616+ schemaName: "ChatTitle",
1717+ system:
1818+ "You write short chat titles. Return a concise title based on the user's first message.",
1919+ prompt: `Write a concise title, 2 to 4 words, for this first message:\n\n${message}`,
2020+ });
2121+}