llm-router / apps /api /src /services /chat /chat.validator.ts
ClaraSu's picture
Upload folder using huggingface_hub
e481638 verified
Raw History Blame Contribute Delete
718 Bytes
import { z } from 'zod'
import type { RequestHandler } from 'express'
import { validate } from '../../middleware/validate'
const ContentPart = z.object({
type: z.string(),
text: z.string().optional(),
image_url: z.object({ url: z.string() }).optional(),
})
const chatSchema = z.object({
messages: z
.array(
z.object({
role: z.string(),
content: z.union([z.string(), z.array(ContentPart)]),
})
)
.min(1, 'messages must be a non-empty array'),
model: z.string().optional().default('smart-router'),
stream: z.boolean().optional().default(false),
})
export type ChatInput = z.infer<typeof chatSchema>
export const validateChat: RequestHandler = validate(chatSchema)