Schema
Schema for stream object
typescript
import { z } from 'zod';
// define a schema for the notifications
export const notificationSchema = z.object({
notifications: z.array(
z.object({
name: z.string().describe('Name of a fictional person.'),
message: z.string().describe('Message. Do not use emojis or links.'),
}),
),
});
Stream object
Stream object with Vercel's AI SDK
typescript
export async function POST(req: Request) {
const context = await req.json();
const result = streamObject({
model: openai('gpt-4-turbo'),
schema: notificationSchema,
prompt:
"Generate 3 notifications for a messages app in this context:" + context,
});
return result.toTextStreamResponse();
}