feat: respond in user's language, style fixes and research depth fixes

This commit is contained in:
AnotiaWang
2025-02-12 19:34:21 +08:00
parent 5a973b5d63
commit b0c86ce2e2
8 changed files with 80 additions and 34 deletions

View File

@ -2,7 +2,7 @@ import { streamText } from 'ai'
import { z } from 'zod'
import { zodToJsonSchema } from 'zod-to-json-schema'
import { systemPrompt } from './prompt'
import { languagePrompt, systemPrompt } from './prompt'
import { useAiModel } from '~/composables/useAiProvider'
type PartialFeedback = DeepPartial<z.infer<typeof feedbackTypeSchema>>
@ -13,9 +13,11 @@ export const feedbackTypeSchema = z.object({
export function generateFeedback({
query,
language,
numQuestions = 3,
}: {
query: string
language: string
numQuestions?: number
}) {
const schema = z.object({
@ -27,6 +29,7 @@ export function generateFeedback({
const prompt = [
`Given the following query from the user, ask ${numQuestions} follow up questions to clarify the research direction. Return a maximum of ${numQuestions} questions, but feel free to return less if the original query is clear: <query>${query}</query>`,
`You MUST respond in JSON with the following schema: ${jsonSchema}`,
languagePrompt(language),
].join('\n\n')
const stream = streamText({