import z from 'zod'; import { ClassifierInput } from './types'; import { classifierPrompt } from '@/lib/prompts/search/classifier'; import formatChatHistoryAsString from '@/lib/utils/formatHistory'; const schema = z.object({ classification: z.object({ skipSearch: z .boolean() .describe('Indicates whether to skip the search step.'), personalSearch: z .boolean() .describe('Indicates whether to perform a personal search.'), academicSearch: z .boolean() .describe('Indicates whether to perform an academic search.'), discussionSearch: z .boolean() .describe('Indicates whether to perform a discussion search.'), showWeatherWidget: z .boolean() .describe('Indicates whether to show the weather widget.'), showStockWidget: z .boolean() .describe('Indicates whether to show the stock widget.'), }), standaloneFollowUp: z .string() .describe( "A self-contained, context-independent reformulation of the user's question.", ), }); export const classify = async (input: ClassifierInput) => { const output = await input.llm.generateObject({ messages: [ { role: 'system', content: classifierPrompt, }, { role: 'user', content: `\n${formatChatHistoryAsString(input.chatHistory)}\n\n\n${input.query}\n`, }, ], schema, }); return output; };